diff --git a/.gitignore b/.gitignore index 33e6471..382b628 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,7 @@ storeDigitData/ .DS_Store test.py -algorithm/OCR/newNet/images/ -testImages +IMAGES # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/algorithm/Blenometer.py b/Algorithm/Blenometer.py similarity index 96% rename from algorithm/Blenometer.py rename to Algorithm/Blenometer.py index 319840f..4115b60 100644 --- a/algorithm/Blenometer.py +++ b/Algorithm/Blenometer.py @@ -1,9 +1,7 @@ import functools -from algorithm.debug import * -import numpy as np -from algorithm.Common import * -from algorithm.debug import * +from Algorithm.utils.Finder import * +from configuration import * def cmp(contour1, contour2): @@ -71,7 +69,6 @@ def checkBleno(image, info): return res - def readBlenometerStatus(image, info): print("Blenometer Reader called!!!") if image is None: diff --git a/algorithm/OCR/__init__.py b/Algorithm/OCR/__init__.py similarity index 100% rename from algorithm/OCR/__init__.py rename to Algorithm/OCR/__init__.py diff --git a/algorithm/OCR/bin/0.jpg b/Algorithm/OCR/bin/0.jpg similarity index 100% rename from algorithm/OCR/bin/0.jpg rename to Algorithm/OCR/bin/0.jpg diff --git a/algorithm/OCR/bin/1.jpg b/Algorithm/OCR/bin/1.jpg similarity index 100% rename from algorithm/OCR/bin/1.jpg rename to Algorithm/OCR/bin/1.jpg diff --git a/algorithm/OCR/bin/2.jpg b/Algorithm/OCR/bin/2.jpg similarity index 100% rename from algorithm/OCR/bin/2.jpg rename to Algorithm/OCR/bin/2.jpg diff --git a/algorithm/OCR/bin/3.jpg b/Algorithm/OCR/bin/3.jpg similarity index 100% rename from algorithm/OCR/bin/3.jpg rename to Algorithm/OCR/bin/3.jpg diff --git a/algorithm/OCR/bin/4.jpg b/Algorithm/OCR/bin/4.jpg similarity index 100% rename from algorithm/OCR/bin/4.jpg rename to Algorithm/OCR/bin/4.jpg diff --git a/algorithm/OCR/bin/5.jpg b/Algorithm/OCR/bin/5.jpg similarity index 100% rename from algorithm/OCR/bin/5.jpg rename to Algorithm/OCR/bin/5.jpg diff --git a/algorithm/OCR/bin/6.jpg b/Algorithm/OCR/bin/6.jpg similarity index 100% rename from algorithm/OCR/bin/6.jpg rename to Algorithm/OCR/bin/6.jpg diff --git a/algorithm/OCR/bin/7.jpg b/Algorithm/OCR/bin/7.jpg similarity index 100% rename from algorithm/OCR/bin/7.jpg rename to Algorithm/OCR/bin/7.jpg diff --git a/algorithm/OCR/bin/8.jpg b/Algorithm/OCR/bin/8.jpg similarity index 100% rename from algorithm/OCR/bin/8.jpg rename to Algorithm/OCR/bin/8.jpg diff --git a/algorithm/OCR/bin/9.jpg b/Algorithm/OCR/bin/9.jpg similarity index 100% rename from algorithm/OCR/bin/9.jpg rename to Algorithm/OCR/bin/9.jpg diff --git a/algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl b/Algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl similarity index 100% rename from algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl rename to Algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl diff --git a/algorithm/OCR/character/characterNet.py b/Algorithm/OCR/character/characterNet.py similarity index 100% rename from algorithm/OCR/character/characterNet.py rename to Algorithm/OCR/character/characterNet.py diff --git a/algorithm/OCR/newNet/LeNet.py b/Algorithm/OCR/newNet/LeNet.py similarity index 100% rename from algorithm/OCR/newNet/LeNet.py rename to Algorithm/OCR/newNet/LeNet.py diff --git a/algorithm/OCR/newNet/__init__.py b/Algorithm/OCR/newNet/__init__.py similarity index 100% rename from algorithm/OCR/newNet/__init__.py rename to Algorithm/OCR/newNet/__init__.py diff --git a/algorithm/OCR/newNet/dataLoader.py b/Algorithm/OCR/newNet/dataLoader.py similarity index 100% rename from algorithm/OCR/newNet/dataLoader.py rename to Algorithm/OCR/newNet/dataLoader.py diff --git a/algorithm/OCR/newNet/net.pkl b/Algorithm/OCR/newNet/net.pkl similarity index 100% rename from algorithm/OCR/newNet/net.pkl rename to Algorithm/OCR/newNet/net.pkl diff --git a/algorithm/OCR/newNet/train.py b/Algorithm/OCR/newNet/train.py similarity index 96% rename from algorithm/OCR/newNet/train.py rename to Algorithm/OCR/newNet/train.py index b86bfdc..0b79be0 100644 --- a/algorithm/OCR/newNet/train.py +++ b/Algorithm/OCR/newNet/train.py @@ -1,5 +1,5 @@ -from algorithm.OCR.newNet.dataLoader import * -from algorithm.OCR.newNet.LeNet import * +from Algorithm.OCR.newNet.dataLoader import * +from Algorithm.OCR.newNet.LeNet import * import sys sys.path.append("../LeNet") diff --git a/algorithm/OCR/test_ocr.py b/Algorithm/OCR/test_ocr.py similarity index 91% rename from algorithm/OCR/test_ocr.py rename to Algorithm/OCR/test_ocr.py index 7740255..c7dae65 100644 --- a/algorithm/OCR/test_ocr.py +++ b/Algorithm/OCR/test_ocr.py @@ -1,5 +1,5 @@ import cv2 -from algorithm.OCR.utils import * +from Algorithm.OCR.utils import * net = newNet() diff --git a/algorithm/OCR/utils.py b/Algorithm/OCR/utils.py old mode 100755 new mode 100644 similarity index 87% rename from algorithm/OCR/utils.py rename to Algorithm/OCR/utils.py index 83c46cc..ff08282 --- a/algorithm/OCR/utils.py +++ b/Algorithm/OCR/utils.py @@ -1,10 +1,10 @@ import sys + import cv2 -import os import numpy as np import torch -from algorithm.debug import * +from configuration import * sys.path.append(".") @@ -31,11 +31,11 @@ def __init__(self): :return: """ sys.path.append("newNet") - from algorithm.OCR.newNet.LeNet import myNet + from Algorithm.OCR.newNet.LeNet import myNet self.net = myNet() self.net.eval() - self.net.load_state_dict(torch.load("algorithm/OCR/newNet/net.pkl")) + self.net.load_state_dict(torch.load("Algorithm/OCR/newNet/net.pkl")) def recognizeNet(self, image): """ @@ -52,7 +52,7 @@ def recognizeNet(self, image): num = int(np.array(predicted[0]).astype(np.uint32)) if ifShow: - print(num) + print("this number is: ", num) cv2.imshow("single", image) cv2.waitKey(0) diff --git a/algorithm/Remember.py b/Algorithm/Remember.py similarity index 100% rename from algorithm/Remember.py rename to Algorithm/Remember.py diff --git a/algorithm/SF6.py b/Algorithm/SF6.py similarity index 96% rename from algorithm/SF6.py rename to Algorithm/SF6.py index 6f79d17..78d312a 100644 --- a/algorithm/SF6.py +++ b/Algorithm/SF6.py @@ -1,5 +1,6 @@ -from algorithm.Common import * -from algorithm.debug import * +from Algorithm.utils.Finder import * +from Algorithm.utils.AngleFactory import AngleFactory +from configuration import * def SF6Reader(image, info): diff --git a/algorithm/__init__.py b/Algorithm/__init__.py similarity index 100% rename from algorithm/__init__.py rename to Algorithm/__init__.py diff --git a/algorithm/absorb.py b/Algorithm/absorb.py similarity index 98% rename from algorithm/absorb.py rename to Algorithm/absorb.py index 11ef4a7..c72ad85 100644 --- a/algorithm/absorb.py +++ b/Algorithm/absorb.py @@ -1,7 +1,7 @@ import json -import numpy as np + import cv2 -from algorithm.Common import AngleFactory, meterFinderByTemplate +import numpy as np # type transform diff --git a/algorithm/arrest/countArrester.py b/Algorithm/arrest/countArrester.py similarity index 93% rename from algorithm/arrest/countArrester.py rename to Algorithm/arrest/countArrester.py index b9942e5..b0ba6ba 100644 --- a/algorithm/arrest/countArrester.py +++ b/Algorithm/arrest/countArrester.py @@ -3,11 +3,7 @@ @author: maoyingxue """ -import json - -from algorithm.debug import * -from algorithm.Common import * -from algorithm.pressure.normalPressure import normalPressure +from Algorithm.utils.Finder import * def countArrester(image, info): @@ -63,7 +59,7 @@ def countArrester(image, info): cv2.imshow("test", image) cv2.waitKey(0) - #value = calAngleBetweenTwoVector(np.array(startPoint)-centerPoint,pointerPoint-centerPoint) + # value = calAngleBetweenTwoVector(np.array(startPoint)-centerPoint,pointerPoint-centerPoint) if len(pointerPoint) == 0: return "pointer not found!" value = calAngleClockwise(np.array(startPoint), pointerPoint, centerPoint) diff --git a/algorithm/arrest/doubleArrester.py b/Algorithm/arrest/doubleArrester.py similarity index 94% rename from algorithm/arrest/doubleArrester.py rename to Algorithm/arrest/doubleArrester.py index 3d4379d..48cc2f9 100644 --- a/algorithm/arrest/doubleArrester.py +++ b/Algorithm/arrest/doubleArrester.py @@ -1,8 +1,13 @@ -import numpy as np +""" +@author: Xuyuanyuan +""" + import cv2 +import numpy as np -from algorithm.debug import * -from algorithm.Common import scanPointer, meterFinderByTemplate +from Algorithm.utils.Finder import meterFinderByTemplate +from Algorithm.utils.ScanPointer import scanPointer +from configuration import * def doubleArrester(image, info): diff --git a/algorithm/oilTempreture.py b/Algorithm/oilTempreture.py similarity index 95% rename from algorithm/oilTempreture.py rename to Algorithm/oilTempreture.py index 90367e8..4b0633f 100644 --- a/algorithm/oilTempreture.py +++ b/Algorithm/oilTempreture.py @@ -1,5 +1,9 @@ -from algorithm.Common import * -from algorithm.debug import * +import cv2 +import numpy as np + +from Algorithm.utils.Finder import meterFinderBySIFT +from Algorithm.utils.AngleFactory import AngleFactory +from configuration import * red_range = [np.array([156, 120, 80]), np.array([179, 240, 220])] white_range = [np.array([0, 0, 200]), np.array([180, 30, 255])] diff --git a/Algorithm/onoff/frozen_east_text_detection.pb b/Algorithm/onoff/frozen_east_text_detection.pb new file mode 100644 index 0000000..5702180 Binary files /dev/null and b/Algorithm/onoff/frozen_east_text_detection.pb differ diff --git a/algorithm/onoff/onoffBatteryScreen.py b/Algorithm/onoff/onoffBatteryScreen.py similarity index 96% rename from algorithm/onoff/onoffBatteryScreen.py rename to Algorithm/onoff/onoffBatteryScreen.py index 921328b..22bcf98 100644 --- a/algorithm/onoff/onoffBatteryScreen.py +++ b/Algorithm/onoff/onoffBatteryScreen.py @@ -1,9 +1,9 @@ -from algorithm.Common import meterFinderBySIFT -from algorithm.debug import * - import cv2 import numpy as np +from Algorithm.utils.Finder import meterFinderBySIFT +from configuration import * + def onoffBatteryHardCode(image, info): """ diff --git a/algorithm/onoff/onoffIndoor.py b/Algorithm/onoff/onoffIndoor.py similarity index 80% rename from algorithm/onoff/onoffIndoor.py rename to Algorithm/onoff/onoffIndoor.py index 2ce43d1..8bd3c6a 100644 --- a/algorithm/onoff/onoffIndoor.py +++ b/Algorithm/onoff/onoffIndoor.py @@ -1,10 +1,9 @@ -import math -import numpy as np -import cv2 -from algorithm.debug import * -from algorithm.Common import AngleFactory, meterFinderByTemplate -from algorithm.Common import * import json +import cv2 +import numpy as np + +from Algorithm.utils.Finder import meterLocationFinderBySIFT + def HSV(img): """ @@ -19,6 +18,7 @@ def HSV(img): return H, S, V, h, s, v + def getBinary(img): """ 对图像进行轮廓检测,获取图像的二值图 @@ -27,6 +27,7 @@ def getBinary(img): edges = cv2.Canny(gray, 100, 200, apertureSize=3) return edges + def searchUpBlack(raw, img, x, y): """ :param raw: 原图 @@ -57,6 +58,7 @@ def searchUpBlack(raw, img, x, y): # cv2.imwrite("ww.jpg",raw) return y, a, y, b + def searchRightRed(raw, img, x, y): """ :param raw: 原图 @@ -87,19 +89,20 @@ def searchRightRed(raw, img, x, y): return y, a, y, b + # 裁剪目标区域值 def cutTarget(img, x1, y1, x2, y2, status): - - if status=="left": + if status == "left": len = y1 - y2 start_x = x1 - len start_y = y1 - len - elif status=="right": + elif status == "right": len = y1 - y2 - len = len+15 + len = len + 15 start_x = x1 start_y = y1 - len - return img[start_y:start_y + len, start_x:start_x + int(1.4*len)] + return img[start_y:start_y + len, start_x:start_x + int(1.4 * len)] + # 在H空间里统计某一种颜色出现的比率 def countTarPer(h_vec, which): @@ -115,19 +118,20 @@ def countTarPer(h_vec, which): return n, float(n / N) -#type transform -def getMatInt(Mat): +# type transform +def getMatInt(Mat): d = Mat.shape for i in range(d[2]): for n in range(d[0]): for m in range(d[1]): - Mat[n,m,i] = int(Mat[n,m,i]) + Mat[n, m, i] = int(Mat[n, m, i]) # print(Mat[n,m,i]) Mat = Mat.astype(np.uint8) return Mat -def gamma(image,thre): + +def gamma(image, thre): """ :param image: numpy type :param thre: float @@ -140,42 +144,43 @@ def gamma(image,thre): out = getMatInt(out * 255) return out -def calDis(img,t): + +def calDis(img, t): t = int(t) # print(t) - s1=0 - s2=0 - h,w = img.shape - - for i in range(w): - if img[t][i]==255: - if s1==0: - s1=i - elif s2==0: - s2=i - return abs(s2-s1) + s1 = 0 + s2 = 0 + h, w = img.shape + + for i in range(w): + if img[t][i] == 255: + if s1 == 0: + s1 = i + elif s2 == 0: + s2 = i + return abs(s2 - s1) + def judgeStatus(img): - h,w = img.shape - mid = h/2 + h, w = img.shape + mid = h / 2 - #画三条线 + # 画三条线 t1 = mid - t2 = mid+3 - t3=t2+6 - #计算距离 - n=0 + t2 = mid + 3 + t3 = t2 + 6 + # 计算距离 + n = 0 ts = [t1, t2, t3] for t in ts: - if calDis(img,t)<4: - n=n+1 + if calDis(img, t) < 4: + n = n + 1 # print(n) return n - def onoffIndoor(image, info): """ :param image:whole image @@ -184,12 +189,12 @@ def onoffIndoor(image, info): """ binary = getBinary(image) X, Y, _, _ = meterLocationFinderBySIFT(image, info['template']) - if info['name']=="onoffIndoor1_1": + if info['name'] == "onoffIndoor1_1": x1, y1, x2, y2 = searchUpBlack(image, binary, Y, X) - img = cutTarget(image, x1, y1, x2, y2,"left") + img = cutTarget(image, x1, y1, x2, y2, "left") H, _, _, h, _, _ = HSV(img) - n,per = countTarPer(h, "black") - status="p" + n, per = countTarPer(h, "black") + status = "p" if per > 0.5: status = "close" res = { @@ -198,10 +203,10 @@ def onoffIndoor(image, info): 'per': per } - elif info['name']=="onoffIndoor3_1": + elif info['name'] == "onoffIndoor3_1": x1, y1, x2, y2 = searchRightRed(image, binary, Y, X) img = cutTarget(image, x1, y1, x2, y2, "right") - #获取目标区域 + # 获取目标区域 img = gamma(img, 0.2) # cv2.imwrite("res.jpg", img) img = getBinary(img) @@ -213,7 +218,6 @@ def onoffIndoor(image, info): 'status': status } - res = json.dumps(res) return res diff --git a/algorithm/onoff/onoffOutdoor.py b/Algorithm/onoff/onoffOutdoor.py similarity index 100% rename from algorithm/onoff/onoffOutdoor.py rename to Algorithm/onoff/onoffOutdoor.py diff --git a/Algorithm/onoff/readyStatus.py b/Algorithm/onoff/readyStatus.py new file mode 100644 index 0000000..15ce333 --- /dev/null +++ b/Algorithm/onoff/readyStatus.py @@ -0,0 +1,146 @@ +import time + +import cv2 +import numpy as np + +from Algorithm.utils.Finder import meterFinderByTemplate + + +def isDark(img): + gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + r, c = gray_img.shape[:2] + # dark num + dark_sum = 0 + # dark ration + dark_prop = 0 + # pixels n7m of gray image + piexs_sum = r * c + for row in gray_img: + for colum in row: + if colum < 120: + dark_sum += 1 + dark_prop = dark_sum / (piexs_sum) + # print("dark_sum:" + str(dark_sum)) + # print("piexs_sum:" + str(piexs_sum)) + # print("dark_prop=dark_sum/piexs_sum:" + str(dark_prop)) + if dark_prop >= 0.70: + return True + else: + return False + + # def hist(pic_path): + # img = cv2.imread(pic_path, 0) + # hist = cv2.calcHist([img], [0], None, [256], [0, 256]) + # plt.subplot(121) + # plt.imshow(img, 'gray') + # plt.xticks([]) + # plt.yticks([]) + # plt.title("Original") + # plt.subplot(122) + # plt.hist(img.ravel(), 256, [0, 256]) + # plt.show() + # + + +def readyStatus(img, info): + template = info['template'] + image = meterFinderByTemplate(img, info['template']) + # if image is dark enough, do gamma correction for enhancing dark details + if isDark(image): + max = np.max(image) + image = np.power(image / float(max), 1/3) * max + image = image.astype(np.uint8) + # cv2.imshow('Gamma', image) + # cv2.waitKey(0) + t_shape = template.shape[:2] + # image = meterFinderBySIFT(img, info) + orig = image.copy() + # minimum probability required to inspect a region + min_confidence = 0.5 + # load the input image and grab the image dimensions + (H, W) = image.shape[:2] + # path to input EAST text detector + model_name = 'frozen_east_text_detection.pb' + # set the new width and height and then determine the ratio in change + # for both the width and height + # image width should be multiple of 32, so do height + newW = (t_shape[0]) // 32 * 32 + newH = (t_shape[1]) // 32 * 32 + rW = W / float(newW) + rH = H / float(newH) + # resize the image and grab the new image dimensions + image = cv2.resize(image, (newW, newH)) + (H, W) = image.shape[:2] + # define the two output layer names for the EAST detector model that + # we are interested -- the first is the output probabilities and the + # second can be used to derive the bounding box coordinates of text + layerNames = [ + "feature_fusion/Conv_7/Sigmoid", + "feature_fusion/concat_3"] + # load the pre-trained EAST text detector + # print("[INFO] loading EAST text detector...") + net = cv2.dnn.readNet(model_name) + # construct a blob from the image and then perform a forward pass of + # the model to obtain the two output layer sets + blob = cv2.dnn.blobFromImage(image, 1.0, (W, H), + (123.68, 116.78, 103.94), swapRB=True, crop=False) + start = time.time() + net.setInput(blob) + (scores, geometry) = net.forward(layerNames) + end = time.time() + # show timing information on text prediction + # print("[INFO] text detection took {:.6f} seconds".format(end - start)) + # grab the number of rows and columns from the scores volume, then + # initialize our set of bounding box rectangles and corresponding + # confidence scores + (numRows, numCols) = scores.shape[2:4] + rects = [] + confidences = [] + # loop over the number of rows + for y in range(0, numRows): + # extract the scores (probabilities), followed by the geometrical + # data used to derive potential bounding box coordinates that + # surround text + scoresData = scores[0, 0, y] + xData0 = geometry[0, 0, y] + xData1 = geometry[0, 1, y] + xData2 = geometry[0, 2, y] + xData3 = geometry[0, 3, y] + anglesData = geometry[0, 4, y] + + # loop over the number of columns + for x in range(0, numCols): + # if our score does not have sufficient probability, ignore it + if scoresData[x] < min_confidence: + continue + + # compute the offset factor as our resulting feature maps will + # be 4x smaller than the input image + (offsetX, offsetY) = (x * 4.0, y * 4.0) + + # extract the rotation angle for the prediction and then + # compute the sin and cosine + angle = anglesData[x] + cos = np.cos(angle) + sin = np.sin(angle) + + # use the geometry volume to derive the width and height of + # the bounding box + h = xData0[x] + xData2[x] + w = xData1[x] + xData3[x] + + # compute both the starting and ending (x, y)-coordinates for + # the text prediction bounding box + endX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x])) + endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x])) + startX = int(endX - w) + startY = int(endY - h) + + # add the bounding box coordinates and probability score to + # our respective lists + rects.append((startX, startY, endX, endY)) + confidences.append(scoresData[x]) + if len(rects) > 0: + return True + else: + return False \ No newline at end of file diff --git a/Algorithm/onoff/springStatus.py b/Algorithm/onoff/springStatus.py new file mode 100644 index 0000000..6cff1cc --- /dev/null +++ b/Algorithm/onoff/springStatus.py @@ -0,0 +1,26 @@ +from Algorithm.utils.Finder import meterFinderByTemplate + + +# 识别弹簧状态 +def springStatus(ROI, info): + template = info['template'] + img = meterFinderByTemplate(ROI, template) + high, width = img.shape[:2] + i = 0 + y = 2 * high // 5 # y坐标大约是2/5的高度 + while width - 6 - i > 0: # 比较相邻像素的三个通道的差值 从右往左比较 + a1, a2 = img[y][width - 5 - i][0].astype(int), img[y][width - 5 - i - 1][0].astype( + int) # 这里的5是为了防止扣取的模板不精确(防止边框抠出来的情况) + b1, b2 = img[y][width - 5 - i][1].astype(int), img[y][width - 5 - i - 1][1].astype(int) + c1, c2 = img[y][width - 5 - i][2].astype(int), img[y][width - 5 - i - 1][2].astype(int) + if abs(a1 - a2) < 20 and abs(b1 - b2) < 20 and abs(c1 - c2) < 20: # 如果相邻像素值近似,继续循环 + i += 1 + else: # 不想死,输出当前点的x值 + x = width - 5 - i - 1 + break + # cv2.circle(img, (x, y), 2, (0, 0, 255), -1) + # cv2.imshow("ewe", img) + if x > 2 * width // 3: + return {'value': '100%'} + else: + return {'value': '50%'} diff --git a/algorithm/pressure/colorPressure.py b/Algorithm/pressure/colorPressure.py similarity index 94% rename from algorithm/pressure/colorPressure.py rename to Algorithm/pressure/colorPressure.py index 78f6bee..9f727d6 100644 --- a/algorithm/pressure/colorPressure.py +++ b/Algorithm/pressure/colorPressure.py @@ -1,6 +1,8 @@ -from algorithm.Common import * -import numpy as np import cv2 +import numpy as np + +from Algorithm.utils.Finder import meterFinderByTemplate +from Algorithm.utils.ScanPointer import EuclideanDistance def colorPressure(image, info): diff --git a/algorithm/pressure/digitPressure.py b/Algorithm/pressure/digitPressure.py similarity index 96% rename from algorithm/pressure/digitPressure.py rename to Algorithm/pressure/digitPressure.py index 2be8620..0334d11 100644 --- a/algorithm/pressure/digitPressure.py +++ b/Algorithm/pressure/digitPressure.py @@ -1,12 +1,12 @@ -import sys -import cv2 import os -import numpy as np import random -from algorithm.Common import meterFinderBySIFT -from algorithm.debug import * -from algorithm.OCR.utils import newNet +import cv2 +import numpy as np + +from Algorithm.OCR.utils import newNet +from Algorithm.utils.Finder import meterFinderBySIFT +from configuration import * def digitPressure(image, info): @@ -93,7 +93,7 @@ def digitPressure(image, info): temp += c elif j != 0: temp += str(random.randint(0, 9)) - myRes[i] = temp + myRes[i] = float(temp) if ifShow: cv2.circle(template, (start[0], start[1]), 5, (0, 0, 255), -1) diff --git a/Algorithm/pressure/normalPressure.py b/Algorithm/pressure/normalPressure.py new file mode 100644 index 0000000..c7979b6 --- /dev/null +++ b/Algorithm/pressure/normalPressure.py @@ -0,0 +1,15 @@ +from Algorithm.utils.Finder import meterFinderBySIFT +from Algorithm.utils.ScanPointer import scanPointer + + +def normalPressure(image, info): + """ + :param image: ROI image + :param info: information for this meter + :return: value + """ + meter = meterFinderBySIFT(image, info) + result = scanPointer(meter, info) + result = int(result * 1000) / 1000 + return [result] + diff --git a/Algorithm/utils/AngleFactory.py b/Algorithm/utils/AngleFactory.py new file mode 100644 index 0000000..1304394 --- /dev/null +++ b/Algorithm/utils/AngleFactory.py @@ -0,0 +1,106 @@ +import numpy as np + + +class AngleFactory: + """method for angle calculation""" + + @staticmethod + def __calAngleBetweenTwoVector(vectorA, vectorB): + """ + get angle formed by two vector + :param vectorA: vector A + :param vectorB: vector B + :return: angle + """ + lenA = np.sqrt(vectorA.dot(vectorA)) + lenB = np.sqrt(vectorB.dot(vectorB)) + cosAngle = vectorA.dot(vectorB) / (lenA * lenB) + angle = np.arccos(cosAngle) + return angle + + @classmethod + def calAngleClockwise(cls, startPoint, endPoint, centerPoint): + """ + get clockwise angle formed by three point + :param startPoint: start point + :param endPoint: end point + :param centerPoint: center point + :return: clockwise angle + """ + vectorA = startPoint - centerPoint + vectorB = endPoint - centerPoint + angle = cls.__calAngleBetweenTwoVector(vectorA, vectorB) + + # if counter-clockwise + if np.cross(vectorA, vectorB) < 0: + angle = 2 * np.pi - angle + + return angle + + @classmethod + def calPointerValueByOuterPoint(cls, startPoint, endPoint, centerPoint, pointerPoint, startValue, totalValue): + """ + get value of pointer meter + :param startPoint: start point + :param endPoint: end point + :param centerPoint: center point + :param pointerPoint: pointer's outer point + :param startValue: start value + :param totalValue: total value + :return: value + """ + # print(startPoint, endPoint, centerPoint, pointerPoint, startValue, totalValue) + angleRange = cls.calAngleClockwise(startPoint, endPoint, centerPoint) + angle = cls.calAngleClockwise(startPoint, pointerPoint, centerPoint) + value = angle / angleRange * (totalValue - startValue) + startValue + if value > totalValue or value < startValue: + return startValue if angle > np.pi + angleRange / 2 else totalValue + return value + + @classmethod + def calPointerValueByPointerVector(cls, startPoint, endPoint, centerPoint, PointerVector, startValue, totalValue): + """ + get value of pointer meter + 注意传入相对圆心的向量 + :param startPoint: start point + :param endPoint: end point + :param centerPoint: center point + :param PointerVector: pointer's vector + :param startValue: start value + :param totalValue: total value + :return: value + """ + angleRange = cls.calAngleClockwise(startPoint, endPoint, centerPoint) + + vectorA = startPoint - centerPoint + vectorB = PointerVector + + angle = cls.__calAngleBetweenTwoVector(vectorA, vectorB) + + # if counter-clockwise + if np.cross(vectorA, vectorB) < 0: + angle = 2 * np.pi - angle + + value = angle / angleRange * totalValue + startValue + if value > totalValue or value < startValue: + return startValue if angle > np.pi + angleRange / 2 else totalValue + return value + + def findPointerFromHSVSpace(src, center, radius, radians_low, radians_high, patch_degree=1.0, ptr_resolution=5, + low_ptr_color=np.array([0, 0, 221]), up_ptr_color=np.array([180, 30, 255])): + + """ + 从固定颜色的区域找指针,未完成 + :param low_ptr_color: 指针的hsv颜色空间的下界 + :param up_ptr_color: 指针的hsv颜色空间的上界 + :param radians_low:圆的搜索范围(弧度制表示) + :param radians_high:圆的搜索范围(弧度制表示) + :param src: 二值图 + :param center: 刻度盘的圆心 + :param radius: 圆的半径 + :param patch_degree:搜索梯度,默认每次一度 + :param ptr_resolution: 指针的粗细程度 + :return: 指针遮罩、直线与圆相交的点 + """ + + pass diff --git a/Algorithm/utils/Finder.py b/Algorithm/utils/Finder.py new file mode 100644 index 0000000..20fe5cd --- /dev/null +++ b/Algorithm/utils/Finder.py @@ -0,0 +1,248 @@ +import cv2 +import numpy as np +import math +from sklearn.metrics.pairwise import pairwise_distances + + +def meterFinderByTemplate(image, template): + """ + locate meter's bbox + :param image: image + :param template: template + :return: bbox image + """ + methods = [cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED, cv2.TM_CCORR, + cv2.TM_CCORR_NORMED, cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED] + + w, h, _ = template.shape + + # for test + # cv2.imshow("test", img) + # img = (img * 0.5).astype(np.uint8) # test + # cv2.imshow("test2", img) + # cv2.waitKey(0) + + i = 5 + res = cv2.matchTemplate(image, template, methods[i]) + minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res) + if methods[i] in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]: + topLeft = minLoc + else: + topLeft = maxLoc + bottomRight = (topLeft[0] + h, topLeft[1] + w) + + return image[topLeft[1]:bottomRight[1], topLeft[0]:bottomRight[0]] + + +def meterLocationFinderBySIFT(image, template): + """ + locate meter's bbox + :param image: image + :param template: template + :return: bbox, left top & right bottom + """ + templateBlurred = cv2.GaussianBlur(template, (3, 3), 0) + imageBlurred = cv2.GaussianBlur(image, (3, 3), 0) + + sift = cv2.xfeatures2d.SIFT_create() + + # shape of descriptor n * 128, n is the num of key points. + # a row of descriptor is the feature of related key point. + templateKeyPoint, templateDescriptor = sift.detectAndCompute(templateBlurred, None) + imageKeyPoint, imageDescriptor = sift.detectAndCompute(imageBlurred, None) + + # for debug + # templateBlurred = cv2.drawKeypoints(templateBlurred, templateKeyPoint, templateBlurred) + # imageBlurred = cv2.drawKeypoints(imageBlurred, imageKeyPoint, imageBlurred) + # cv2.imshow("template", templateBlurred) + # cv2.imshow("image", imageBlurred) + + # match + bf = cv2.BFMatcher() + # k = 2, so each match has 2 points. 2 points are sorted by distance. + matches = bf.knnMatch(templateDescriptor, imageDescriptor, k=2) + + # The first one is better than the second one + good = [[m] for m, n in matches if m.distance < 0.7 * n.distance] + + # distance matrix + templatePointMatrix = np.array([list(templateKeyPoint[p[0].queryIdx].pt) for p in good]) + imagePointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good]) + templatePointDistanceMatrix = pairwise_distances(templatePointMatrix, metric="euclidean") + imagePointDistanceMatrix = pairwise_distances(imagePointMatrix, metric="euclidean") + + # del bad match + distances = [] + maxAbnormalNum = 15 + for i in range(len(good)): + diff = abs(templatePointDistanceMatrix[i] - imagePointDistanceMatrix[i]) + # distance between distance features + diff.sort() + distances.append(np.sqrt(np.sum(np.square(diff[:-maxAbnormalNum])))) + + averageDistance = np.average(distances) + good2 = [good[i] for i in range(len(good)) if distances[i] < 2 * averageDistance] + + # for debug + # matchImage = cv2.drawMatchesKnn(template, templateKeyPoint, image, imageKeyPoint, good2, None, flags=2) + # cv2.imshow("matchImage", matchImage) + # cv2.waitKey(0) + + matchPointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good2]) + + # for p1, p2 in matchPointMatrix: + # cv2.circle(image, (int(p1), int(p2)), 0, (255, 0, 0), thickness=50) + # print(p1, p2) + # cv2.imshow("matchImage", image) + + minX = int(np.min(matchPointMatrix[:, 0])) + maxX = int(np.max(matchPointMatrix[:, 0])) + minY = int(np.min(matchPointMatrix[:, 1])) + maxY = int(np.max(matchPointMatrix[:, 1])) + return minX, minY, maxX, maxY + + +def meterFinderBySIFT(image, info): + """ + locate meter's bbox + :param image: image + :param info: info + :return: bbox image + """ + template = info["template"] + + # cv2.imshow("template", template) + # cv2.imshow("image", image) + # cv2.waitKey(0) + + startPoint = (info["startPoint"]["x"], info["startPoint"]["y"]) + centerPoint = (info["centerPoint"]["x"], info["centerPoint"]["y"]) + endPoint = (info["endPoint"]["x"], info["endPoint"]["y"]) + # startPointUp = (info["startPointUp"]["x"], info["startPointUp"]["y"]) + # endPointUp = (info["endPointUp"]["x"], info["endPointUp"]["y"]) + # centerPointUp = (info["centerPointUp"]["x"], info["centerPointUp"]["y"]) + + templateBlurred = cv2.GaussianBlur(template, (3, 3), 0) + imageBlurred = cv2.GaussianBlur(image, (3, 3), 0) + + sift = cv2.xfeatures2d.SIFT_create() + + # shape of descriptor n * 128, n is the num of key points. + # a row of descriptor is the feature of related key point. + templateKeyPoint, templateDescriptor = sift.detectAndCompute(templateBlurred, None) + imageKeyPoint, imageDescriptor = sift.detectAndCompute(imageBlurred, None) + + # for debug + # templateBlurred = cv2.drawKeypoints(templateBlurred, templateKeyPoint, templateBlurred) + # imageBlurred = cv2.drawKeypoints(imageBlurred, imageKeyPoint, imageBlurred) + # # cv2.imshow("template", templateBlurred) + # cv2.imshow("image", imageBlurred) + # cv2.waitKey(0) + + # match + bf = cv2.BFMatcher() + # k = 2, so each match has 2 points. 2 points are sorted by distance. + matches = bf.knnMatch(templateDescriptor, imageDescriptor, k=2) + + # The first one is better than the second one + good = [[m] for m, n in matches if m.distance < 0.8 * n.distance] + # distance matrix + templatePointMatrix = np.array([list(templateKeyPoint[p[0].queryIdx].pt) for p in good]) + imagePointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good]) + templatePointDistanceMatrix = pairwise_distances(templatePointMatrix, metric="euclidean") + imagePointDistanceMatrix = pairwise_distances(imagePointMatrix, metric="euclidean") + + # del bad match + distances = [] + maxAbnormalNum = 15 + for i in range(len(good)): + diff = abs(templatePointDistanceMatrix[i] - imagePointDistanceMatrix[i]) + # distance between distance features + diff.sort() + distances.append(np.sqrt(np.sum(np.square(diff[:-maxAbnormalNum])))) + + averageDistance = np.average(distances) + good2 = [good[i] for i in range(len(good)) if distances[i] < 2 * averageDistance] + + # for debug + # matchImage = cv2.drawMatchesKnn(template, templateKeyPoint, image, imageKeyPoint, good2, None, flags=2) + # cv2.imshow("matchImage", matchImage) + # cv2.waitKey(0) + + # not match + if len(good2) < 3: + print("not found!") + return template + + # 寻找转换矩阵 M + src_pts = np.float32([templateKeyPoint[m[0].queryIdx].pt for m in good2]).reshape(-1, 1, 2) + dst_pts = np.float32([imageKeyPoint[m[0].trainIdx].pt for m in good2]).reshape(-1, 1, 2) + M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) + matchesMask = mask.ravel().tolist() + h, w, _ = template.shape + + # 找出匹配到的图形的四个点和标定信息里的所有点 + pts = np.float32( + [[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0], [startPoint[0], startPoint[1]], [endPoint[0], endPoint[1]], + [centerPoint[0], centerPoint[1]], + # [startPointUp[0], startPointUp[1]], + # [endPointUp[0], endPointUp[1]], + # [centerPointUp[0], centerPointUp[1]] + ]).reshape(-1, 1, 2) + dst = cv2.perspectiveTransform(pts, M) + + # 校正图像 + angle = 0.0 + vector = (dst[3][0][0] - dst[0][0][0], dst[3][0][1] - dst[0][0][1]) + cos = (vector[0] * (200.0)) / (200.0 * math.sqrt(vector[0] ** 2 + vector[1] ** 2)) + if (vector[1] > 0): + angle = math.acos(cos) * 180.0 / math.pi + else: + angle = -math.acos(cos) * 180.0 / math.pi + # print(angle) + + change = cv2.getRotationMatrix2D((dst[0][0][0], dst[0][0][1]), angle, 1) + src_correct = cv2.warpAffine(image, change, (image.shape[1], image.shape[0])) + array = np.array([[0, 0, 1]]) + newchange = np.vstack((change, array)) + # 获得校正后的所需要的点 + newpoints = [] + for i in range(len(pts)): + point = newchange.dot(np.array([dst[i][0][0], dst[i][0][1], 1])) + point = list(point) + point.pop() + newpoints.append(point) + src_correct = src_correct[int(round(newpoints[0][1])):int(round(newpoints[1][1])), + int(round(newpoints[0][0])):int(round(newpoints[3][0]))] + + width = src_correct.shape[1] + height = src_correct.shape[0] + if width == 0 or height == 0: + return template + + startPoint = (int(round(newpoints[4][0]) - newpoints[0][0]), int(round(newpoints[4][1]) - newpoints[0][1])) + endPoint = (int(round(newpoints[5][0]) - newpoints[0][0]), int(round(newpoints[5][1]) - newpoints[0][1])) + centerPoint = (int(round(newpoints[6][0]) - newpoints[0][0]), int(round(newpoints[6][1]) - newpoints[0][1])) + + def isOverflow(point, width, height): + if point[0] < 0 or point[1] < 0 or point[0] > width - 1 or point[1] > height - 1: + return True + return False + + if isOverflow(startPoint, width, height) or isOverflow(endPoint, width, height) or isOverflow(centerPoint, width, + height): + print("overflow!") + return template + + # startPointUp = (int(round(newpoints[7][0]) - newpoints[0][0]), int(round(newpoints[7][1]) - newpoints[0][1])) + # endPointUp = (int(round(newpoints[8][0]) - newpoints[0][0]), int(round(newpoints[8][1]) - newpoints[0][1])) + # centerPointUp = (int(round(newpoints[9][0]) - newpoints[0][0]), int(round(newpoints[9][1]) - newpoints[0][1])) + info["startPoint"]["x"] = startPoint[0] + info["startPoint"]["y"] = startPoint[1] + info["centerPoint"]["x"] = centerPoint[0] + info["centerPoint"]["y"] = centerPoint[1] + info["endPoint"]["x"] = endPoint[0] + info["endPoint"]["y"] = endPoint[1] + + return src_correct + diff --git a/Algorithm/utils/ScanPointer.py b/Algorithm/utils/ScanPointer.py new file mode 100644 index 0000000..7f1d7e4 --- /dev/null +++ b/Algorithm/utils/ScanPointer.py @@ -0,0 +1,118 @@ +import cv2 +import numpy as np + +from configuration import * +from Algorithm.utils.AngleFactory import AngleFactory + + +def getPoints(center, radious, angle): + res = [] + farthestPointX = int(center[0] + radious * np.cos(angle / 180 * np.pi)) + farthestPointY = int(center[1] + radious * np.sin(angle / 180 * np.pi)) + + for ro in range(radious // 3, radious): + for theta in range(angle - 2, angle + 2): + angleTemp = theta / 180 * np.pi + x, y = int(ro * np.cos(angleTemp)) + center[0], int(ro * np.sin(angleTemp)) + center[1] + res.append([x, y]) + return res, [farthestPointX, farthestPointY] + + +def EuclideanDistance(pt1, pt2): + return np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2) + + +def scanPointer(meter, info): + """ + find pointer of meter + :param meter: meter matched template + :param pts: a list including three numpy array, eg: [startPointer, endPointer, centerPointer] + :param startVal: an integer of meter start value + :param endVal: an integer of meter ending value + :return: pointer reading number + """ + center = np.array([info["centerPoint"]["x"], info["centerPoint"]["y"]]) + start = np.array([info["startPoint"]["x"], info["startPoint"]["y"]]) + end = np.array([info["endPoint"]["x"], info["endPoint"]["y"]]) + startVal = info["startValue"] + endVal = info["totalValue"] + if meter.shape[0] > 500: + fixHeight = 300 + fixWidth = int(meter.shape[1] / meter.shape[0] * fixHeight) + resizeCoffX = fixWidth / meter.shape[1] + meter = cv2.resize(meter, (fixWidth, fixHeight)) + + start = (start * resizeCoffX).astype(np.int32) + end = (end * resizeCoffX).astype(np.int32) + center = (center * resizeCoffX).astype(np.int32) + + radious = int(EuclideanDistance(start, center)) + + src = cv2.GaussianBlur(meter, (3, 3), sigmaX=0, sigmaY=0, borderType=cv2.BORDER_DEFAULT) + + gray = cv2.cvtColor(src=src, code=cv2.COLOR_RGB2GRAY) + + thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 17, 11) + + mask = np.zeros((src.shape[0], src.shape[1]), np.uint8) + cv2.circle(mask, (center[0], center[1]), radious, (255, 255, 255), -1) + thresh = cv2.bitwise_and(thresh, mask) + cv2.circle(thresh, (center[0], center[1]), int(radious / 3), (0, 0, 0), -1) + + thresh = cv2.ximgproc.thinning(thresh, thinningType=cv2.ximgproc.THINNING_ZHANGSUEN) + + startAngle = int( + AngleFactory.calAngleClockwise(startPoint=np.array([center[0] + 100, center[1]]), centerPoint=center, + endPoint=start) * 180 / np.pi) + endAngle = int(AngleFactory.calAngleClockwise(startPoint=np.array([center[0] + 100, center[1]]), centerPoint=center, + endPoint=end) * 180 / np.pi) + # print(startAngle, endAngle) + if endAngle <= startAngle: + endAngle += 360 + maxSum = 0 + outerPoint = start + for angle in range(startAngle - 10, endAngle + 10): + pts, outPt = getPoints(center, radious, angle) + thisSum = 0 + showImg = cv2.cvtColor(thresh.copy(), cv2.COLOR_GRAY2BGR) + + for pt in pts: + cv2.circle(showImg, (pt[0], pt[1]), 2, (0, 0, 255), -1) + if thresh[pt[1], pt[0]] != 0: + thisSum += 1 + + # cv2.circle(showImg, (outPt[0], outPt[1]), 2, (255, 0, 0), -1) + # cv2.imshow("img", showImg) + # cv2.waitKey(1) + if thisSum > maxSum: + maxSum = thisSum + outerPoint = outPt + + if start[0] == outerPoint[0] and start[1] == outerPoint[1]: + degree = startVal + elif end[0] == outerPoint[0] and end[1] == outerPoint[1]: + degree = endVal + else: + if start[0] == end[0] and start[1] == end[1]: + end[0] -= 1 + end[1] -= 3 + degree = AngleFactory.calPointerValueByOuterPoint(start, end, center, outerPoint, startVal, endVal) + + # small value to zero + if degree - startVal < 0.05 * (endVal - startVal): + degree = startVal + + if ifShow: + print("degree {:.2f} startPoint {}, endPoint{}, outPoint {}".format(degree, start, center, outerPoint)) + cv2.circle(meter, (outerPoint[0], outerPoint[1]), 10, (0, 0, 255), -1) + cv2.line(meter, (center[0], center[1]), (outerPoint[0], outerPoint[1]), (0, 0, 255), 5) + cv2.line(meter, (center[0], center[1]), (start[0], start[1]), (255, 0, 0), 3) + cv2.line(meter, (center[0], center[1]), (end[0], end[1]), (255, 0, 0), 3) + + thresh = np.expand_dims(thresh, axis=2) + thresh = np.concatenate((thresh, thresh, thresh), 2) + meter = np.hstack((meter, thresh)) + + cv2.imshow("test", meter) + cv2.waitKey(0) + return int(degree*100)/100 diff --git a/Algorithm/utils/__init__.py b/Algorithm/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/algorithm/videoDigit.py b/Algorithm/videoDigit.py similarity index 92% rename from algorithm/videoDigit.py rename to Algorithm/videoDigit.py index 3fcdcce..bc37ad5 100644 --- a/algorithm/videoDigit.py +++ b/Algorithm/videoDigit.py @@ -1,13 +1,12 @@ +from collections import defaultdict + import cv2 -import sys -import os import numpy as np import torch -from collections import defaultdict -from algorithm.pressure.digitPressure import digitPressure -from algorithm.Common import meterFinderBySIFT -from algorithm.OCR.character.characterNet import characterNet +from Algorithm.OCR.character.characterNet import characterNet +from Algorithm.pressure.digitPressure import digitPressure +from Algorithm.utils.Finder import meterFinderBySIFT def videoDigit(video, info): @@ -17,13 +16,14 @@ def videoDigit(video, info): :return: """ net = characterNet() - net.load_state_dict(torch.load("algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl")) + net.load_state_dict(torch.load("Algorithm/OCR/character/NewNet_minLoss_model_0.965.pkl")) pictures = getPictures(video) # 获得视频的帧,有少量重复帧 def emptyLsit(): return [] imagesDict = defaultdict(emptyLsit) + for i, frame in enumerate(pictures): res = digitPressure(frame, info) index = checkFrame(net, frame, info) diff --git a/FlaskService.py b/FlaskService.py index 9c141d2..2921bd3 100644 --- a/FlaskService.py +++ b/FlaskService.py @@ -6,6 +6,7 @@ from Interface import meterReader from flask import Flask, request from locator import * +from configuration import * app = Flask(__name__) @@ -13,7 +14,7 @@ def getMeterNum(imageID): """get meter num in an image""" num = 0 - rootdir = 'template/' + rootdir = templatePath list = os.listdir(rootdir) for i in range(0, len(list)): path = os.path.join(rootdir, list[i]) @@ -28,7 +29,7 @@ def getMeterNum(imageID): def getMeterIDs(imageID): """get id of meters in an image""" meterIDs = [] - templateDir = 'template/' + templateDir = templatePath list = os.listdir(templateDir) for i in range(0, len(list)): path = os.path.join(templateDir, list[i]) @@ -46,7 +47,8 @@ def meterReaderAPI(): data = request.get_data().decode("utf-8") data = json.loads(data) imageID = data["imageID"] - + path = data["path"] + # print(imageID) meterIDs = getMeterIDs(imageID) # imageByte = data["image"].encode("ascii") @@ -54,20 +56,19 @@ def meterReaderAPI(): # imageArray = np.asarray(bytearray(imageByte), dtype="uint8") # image = cv2.imdecode(imageArray, cv2.IMREAD_COLOR) - path = data["path"] - recognitionData = None + # recognitionData = None + # if path[-4:] != ".jpg": recognitionData = cv2.VideoCapture(path) else: recognitionData = cv2.imread(path) # print(path, np.shape(recognitionData)) except: - return json.dumps({"error":"json format error!"}) + return json.dumps({"error": "json format error!"}) else: result = meterReader(recognitionData, meterIDs) sendData = json.dumps(result).encode("utf-8") - return sendData @@ -84,14 +85,14 @@ def storeAPI(): imageByte = base64.b64decode(imageByte) imageArray = np.asarray(bytearray(imageByte), dtype="uint8") image = cv2.imdecode(imageArray, cv2.IMREAD_COLOR) - cv2.imwrite("template/" + meterID + ".jpg", image) + cv2.imwrite(templatePath + "/" + meterID + ".jpg", image) config = data["config"] # print(config) except: return json.dumps({"error": "json format error!"}) else: - file = open("config/" + meterID + ".json", "w") + file = open(configPath + "/" + meterID + ".json", "w") file.write(json.dumps(config)) file.close() @@ -105,8 +106,6 @@ def locateAPI(): data = json.loads(data) pointID = data["pointID"] path = data["path"] - - image = None if path[-4:] == ".jpg": diff --git a/Interface.py b/Interface.py index 81605c8..a4055e1 100644 --- a/Interface.py +++ b/Interface.py @@ -2,24 +2,26 @@ import os import cv2 -from algorithm.absorb import absorb -from algorithm.Blenometer import checkBleno -from algorithm.SF6 import SF6Reader -from algorithm.oilTempreture import oilTempreture -from algorithm.highlightDigitMeter import highlightDigit -from algorithm.videoDigit import videoDigit +from Algorithm.absorb import absorb +from Algorithm.Blenometer import checkBleno +from Algorithm.SF6 import SF6Reader +from Algorithm.oilTempreture import oilTempreture +from Algorithm.videoDigit import videoDigit +from Algorithm.arrest.countArrester import countArrester +from Algorithm.arrest.doubleArrester import doubleArrester -from algorithm.arrest.countArrester import countArrester -from algorithm.arrest.doubleArrester import doubleArrester +from Algorithm.pressure.digitPressure import digitPressure +from Algorithm.pressure.normalPressure import normalPressure +from Algorithm.pressure.colorPressure import colorPressure -from algorithm.pressure.digitPressure import digitPressure -from algorithm.pressure.normalPressure import normalPressure -from algorithm.pressure.colorPressure import colorPressure +from Algorithm.onoff.onoffIndoor import onoffIndoor +from Algorithm.onoff.onoffOutdoor import onoffOutdoor +from Algorithm.onoff.onoffBatteryScreen import onoffBattery +from Algorithm.onoff.readyStatus import readyStatus +from Algorithm.onoff.springStatus import springStatus -from algorithm.onoff.onoffIndoor import onoffIndoor -from algorithm.onoff.onoffOutdoor import onoffOutdoor -from algorithm.onoff.onoffBatteryScreen import onoffBattery +from configuration import * def meterReaderCallBack(image, info): @@ -63,7 +65,7 @@ def getInfo(ID): "totalValue": 2 } """ - file = open("config/" + ID + ".json") + file = open(configPath + "/" + ID + ".json") info = json.load(file) # string to pointer if info["type"] == "absorb": @@ -88,19 +90,20 @@ def getInfo(ID): info["type"] = onoffIndoor elif info["type"] == "onoffOutdoor": info["type"] = onoffOutdoor - elif info["type"] == "highlightDigit": - info["type"] = highlightDigit elif info["type"] == "onoffBattery": info["type"] = onoffBattery elif info["type"] == "videoDigit": info["type"] = videoDigit + elif info["type"] == "ready": + info["type"] = readyStatus + elif info["type"] == "spring": + info["type"] = springStatus else: info["type"] = None - info["template"] = cv2.imread("template/" + ID + ".jpg") - + info["template"] = cv2.imread(templatePath + "/" + ID + ".jpg") if info["digitType"] != "False": - info.update(json.load(open(os.path.join("ocr_config", info["digitType"]+".json")))) + info.update(json.load(open(os.path.join("ocr_config", info["digitType"] + ".json")))) return info @@ -111,8 +114,9 @@ def meterReader(recognitionData, meterIDs): :param meterIDs: list of meter ID :return: """ - results = {} - for ID in meterIDs: + # results = {} + results = [] + for i, ID in enumerate(meterIDs): # get info from file info = getInfo(ID) if info["digitType"] == "VIDEO": @@ -125,12 +129,11 @@ def meterReader(recognitionData, meterIDs): h = info["ROI"]["h"] # call back # cv2.rectangle(recognitionData, (x, y), (x+w, y + h), (255, 0, 0), 3) - # cv2.imshow("d", recognitionData) + # cv2.imshow("testInput", recognitionData) # cv2.waitKey(0) if x != 0 or y != 0 or w != 0 or h != 0: ROI = recognitionData[y:y + h, x:x + w] - results[ID] = meterReaderCallBack(ROI, info) + results.append(meterReaderCallBack(ROI, info)) else: - results[ID] = meterReaderCallBack(recognitionData, info) - - return results + results.append(meterReaderCallBack(recognitionData, info)) + return results \ No newline at end of file diff --git a/TestServiceSample.py b/TestServiceSample.py index 4037cb0..ac0526b 100644 --- a/TestServiceSample.py +++ b/TestServiceSample.py @@ -5,49 +5,69 @@ import time import cv2 import multiprocessing +from configuration import * from Interface import meterReader + def startServer(): os.system("python FlaskService.py") def startClient(results): - images = os.listdir("image") + images = os.listdir("info/20190410/IMAGES/Pic_2") for im in images: - path = "image/" + im + path = "info/20190410/IMAGES/Pic_2/" + im data = json.dumps({ "path": path, - "pointID": im.split('.')[0]+"_1" + "imageID": im.split('.')[0] + "_1" }) print(path, im) - r = requests.post("http://127.0.0.1:5000/locate", data=data.encode("utf-8")) + print(data) + r = requests.post("http://127.0.0.1:5000/", data=data.encode("utf-8")) + print(r.text) receive = json.loads(r.text) print(im, receive) results.append(True) +def testReadyStatus(): + imgPath = "info/20190416/image" + configPath = "info/20190416/config" + images = os.listdir(imgPath) + config = os.listdir(configPath) + for im in images: + filename, extention = os.path.splitext(im.lower()) + if extention == '.jpg' or extention == '.png': + image = cv2.imread(imgPath + "/" + im) + for i in range(1, 6): + cfg = filename + "_" + str(i) + if cfg + ".json" in config: + receive2 = meterReader(image, [cfg]) + print(cfg, receive2) + + def codecov(): - images = os.listdir("image") - config = os.listdir("config") + imgPath = "info/20190410/IMAGES/Pic" + images = os.listdir(imgPath) + config = os.listdir(configPath) for im in images: - image = cv2.imread("image/"+im) + image = cv2.imread(imgPath + "/" + im) print(im) + pos = im.split(".")[0].split("-") for i in range(1, 6): - cfg = im.split(".jpg")[0]+"_"+str(i) - if cfg+".json" in config: + cfg = pos[0] + "-" + pos[1] + "_" + str(i) + if cfg + ".json" in config: receive2 = meterReader(image, [cfg]) print(cfg, receive2) - print("codecov done") -def testVideo(): - video_path = ("video_") - config = os.listdir("config") +def testVideo(): + video_path = "info/20190128/IMAGES/video_" for file in os.listdir(video_path): if file.startswith(".DS"): continue @@ -58,6 +78,8 @@ def testVideo(): if __name__ == "__main__": + # Service Test + # serverProcess = multiprocessing.Process(target=startServer) # results = multiprocessing.Manager().list() # clientProcess = multiprocessing.Process(target=startClient, args=(results,)) @@ -67,25 +89,8 @@ def testVideo(): # clientProcess.join() # serverProcess.terminate() - codecov() - testVideo() - # - # for i in range(20): - # serverProcess = multiprocessing.Process(target=startServer) - # results = multiprocessing.Manager().list() - # clientProcess = multiprocessing.Process(target=startClient, args=(results,)) - # serverProcess.start() - # time.sleep(30) - # clientProcess.start() - # clientProcess.join() - # serverProcess.terminate() - # - # codecov() - - # for result in results: - # print(result) - # if not result: - # exit(100) - - + # Single Test + # testReadyStatus() + codecov() + # testVideo() diff --git a/algorithm/Common.py b/algorithm/Common.py deleted file mode 100644 index c842c42..0000000 --- a/algorithm/Common.py +++ /dev/null @@ -1,607 +0,0 @@ -import cv2 -import numpy as np -import math -from sklearn.metrics.pairwise import pairwise_distances - -from algorithm.debug import * - - -def meterFinderByTemplate(image, template): - """ - locate meter's bbox - :param image: image - :param template: template - :return: bbox image - """ - methods = [cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED, cv2.TM_CCORR, - cv2.TM_CCORR_NORMED, cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED] - - w, h, _ = template.shape - - # for test - # cv2.imshow("test", img) - # img = (img * 0.5).astype(np.uint8) # test - # cv2.imshow("test2", img) - # cv2.waitKey(0) - - i = 5 - res = cv2.matchTemplate(image, template, methods[i]) - minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res) - if methods[i] in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]: - topLeft = minLoc - else: - topLeft = maxLoc - bottomRight = (topLeft[0] + h, topLeft[1] + w) - - return image[topLeft[1]:bottomRight[1], topLeft[0]:bottomRight[0]] - - -def meterLocationFinderBySIFT(image, template): - """ - locate meter's bbox - :param image: image - :param template: template - :return: bbox - """ - templateBlurred = cv2.GaussianBlur(template, (3, 3), 0) - imageBlurred = cv2.GaussianBlur(image, (3, 3), 0) - - sift = cv2.xfeatures2d.SIFT_create() - - # shape of descriptor n * 128, n is the num of key points. - # a row of descriptor is the feature of related key point. - templateKeyPoint, templateDescriptor = sift.detectAndCompute(templateBlurred, None) - imageKeyPoint, imageDescriptor = sift.detectAndCompute(imageBlurred, None) - - # for debug - # templateBlurred = cv2.drawKeypoints(templateBlurred, templateKeyPoint, templateBlurred) - # imageBlurred = cv2.drawKeypoints(imageBlurred, imageKeyPoint, imageBlurred) - # cv2.imshow("template", templateBlurred) - # cv2.imshow("image", imageBlurred) - - # match - bf = cv2.BFMatcher() - # k = 2, so each match has 2 points. 2 points are sorted by distance. - matches = bf.knnMatch(templateDescriptor, imageDescriptor, k=2) - - # The first one is better than the second one - good = [[m] for m, n in matches if m.distance < 0.7 * n.distance] - - # distance matrix - templatePointMatrix = np.array([list(templateKeyPoint[p[0].queryIdx].pt) for p in good]) - imagePointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good]) - templatePointDistanceMatrix = pairwise_distances(templatePointMatrix, metric="euclidean") - imagePointDistanceMatrix = pairwise_distances(imagePointMatrix, metric="euclidean") - - # del bad match - distances = [] - maxAbnormalNum = 15 - for i in range(len(good)): - diff = abs(templatePointDistanceMatrix[i] - imagePointDistanceMatrix[i]) - # distance between distance features - diff.sort() - distances.append(np.sqrt(np.sum(np.square(diff[:-maxAbnormalNum])))) - - averageDistance = np.average(distances) - good2 = [good[i] for i in range(len(good)) if distances[i] < 2 * averageDistance] - - # for debug - # matchImage = cv2.drawMatchesKnn(template, templateKeyPoint, image, imageKeyPoint, good2, None, flags=2) - # cv2.imshow("matchImage", matchImage) - # cv2.waitKey(0) - - matchPointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good2]) - - # for p1, p2 in matchPointMatrix: - # cv2.circle(image, (int(p1), int(p2)), 0, (255, 0, 0), thickness=50) - # print(p1, p2) - # cv2.imshow("matchImage", image) - - minX = int(np.min(matchPointMatrix[:, 0])) - maxX = int(np.max(matchPointMatrix[:, 0])) - minY = int(np.min(matchPointMatrix[:, 1])) - maxY = int(np.max(matchPointMatrix[:, 1])) - return minX, minY, maxX, maxY - - -def meterFinderBySIFT(image, info): - """ - locate meter's bbox - :param image: image - :param info: info - :return: bbox image - """ - template = info["template"] - - # cv2.imshow("template", template) - # cv2.imshow("image", image) - # cv2.waitKey(0) - - startPoint = (info["startPoint"]["x"], info["startPoint"]["y"]) - centerPoint = (info["centerPoint"]["x"], info["centerPoint"]["y"]) - endPoint = (info["endPoint"]["x"], info["endPoint"]["y"]) - # startPointUp = (info["startPointUp"]["x"], info["startPointUp"]["y"]) - # endPointUp = (info["endPointUp"]["x"], info["endPointUp"]["y"]) - # centerPointUp = (info["centerPointUp"]["x"], info["centerPointUp"]["y"]) - - templateBlurred = cv2.GaussianBlur(template, (3, 3), 0) - imageBlurred = cv2.GaussianBlur(image, (3, 3), 0) - - sift = cv2.xfeatures2d.SIFT_create() - - # shape of descriptor n * 128, n is the num of key points. - # a row of descriptor is the feature of related key point. - templateKeyPoint, templateDescriptor = sift.detectAndCompute(templateBlurred, None) - imageKeyPoint, imageDescriptor = sift.detectAndCompute(imageBlurred, None) - - # for debug - # templateBlurred = cv2.drawKeypoints(templateBlurred, templateKeyPoint, templateBlurred) - # imageBlurred = cv2.drawKeypoints(imageBlurred, imageKeyPoint, imageBlurred) - # cv2.imshow("template", templateBlurred) - # cv2.imshow("image", imageBlurred) - - # match - bf = cv2.BFMatcher() - # k = 2, so each match has 2 points. 2 points are sorted by distance. - matches = bf.knnMatch(templateDescriptor, imageDescriptor, k=2) - - # The first one is better than the second one - good = [[m] for m, n in matches if m.distance < 0.8 * n.distance] - - # distance matrix - templatePointMatrix = np.array([list(templateKeyPoint[p[0].queryIdx].pt) for p in good]) - imagePointMatrix = np.array([list(imageKeyPoint[p[0].trainIdx].pt) for p in good]) - templatePointDistanceMatrix = pairwise_distances(templatePointMatrix, metric="euclidean") - imagePointDistanceMatrix = pairwise_distances(imagePointMatrix, metric="euclidean") - - # del bad match - distances = [] - maxAbnormalNum = 15 - for i in range(len(good)): - diff = abs(templatePointDistanceMatrix[i] - imagePointDistanceMatrix[i]) - # distance between distance features - diff.sort() - distances.append(np.sqrt(np.sum(np.square(diff[:-maxAbnormalNum])))) - - averageDistance = np.average(distances) - good2 = [good[i] for i in range(len(good)) if distances[i] < 2 * averageDistance] - - # for debug - # matchImage = cv2.drawMatchesKnn(template, templateKeyPoint, image, imageKeyPoint, good2, None, flags=2) - # cv2.imshow("matchImage", matchImage) - # cv2.waitKey(0) - - # not match - if len(good2) < 3: - print("not found!") - return template - - # 寻找转换矩阵 M - src_pts = np.float32([templateKeyPoint[m[0].queryIdx].pt for m in good2]).reshape(-1, 1, 2) - dst_pts = np.float32([imageKeyPoint[m[0].trainIdx].pt for m in good2]).reshape(-1, 1, 2) - M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) - matchesMask = mask.ravel().tolist() - h, w, _ = template.shape - - # 找出匹配到的图形的四个点和标定信息里的所有点 - pts = np.float32( - [[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0], [startPoint[0], startPoint[1]], [endPoint[0], endPoint[1]], - [centerPoint[0], centerPoint[1]], - # [startPointUp[0], startPointUp[1]], - # [endPointUp[0], endPointUp[1]], - # [centerPointUp[0], centerPointUp[1]] - ]).reshape(-1, 1, 2) - dst = cv2.perspectiveTransform(pts, M) - - # 校正图像 - angle = 0.0 - vector = (dst[3][0][0] - dst[0][0][0], dst[3][0][1] - dst[0][0][1]) - cos = (vector[0] * (200.0)) / (200.0 * math.sqrt(vector[0] ** 2 + vector[1] ** 2)) - if (vector[1] > 0): - angle = math.acos(cos) * 180.0 / math.pi - else: - angle = -math.acos(cos) * 180.0 / math.pi - # print(angle) - - change = cv2.getRotationMatrix2D((dst[0][0][0], dst[0][0][1]), angle, 1) - src_correct = cv2.warpAffine(image, change, (image.shape[1], image.shape[0])) - array = np.array([[0, 0, 1]]) - newchange = np.vstack((change, array)) - # 获得校正后的所需要的点 - newpoints = [] - for i in range(len(pts)): - point = newchange.dot(np.array([dst[i][0][0], dst[i][0][1], 1])) - point = list(point) - point.pop() - newpoints.append(point) - src_correct = src_correct[int(round(newpoints[0][1])):int(round(newpoints[1][1])), - int(round(newpoints[0][0])):int(round(newpoints[3][0]))] - - width = src_correct.shape[1] - height = src_correct.shape[0] - if width == 0 or height == 0: - return template - - startPoint = (int(round(newpoints[4][0]) - newpoints[0][0]), int(round(newpoints[4][1]) - newpoints[0][1])) - endPoint = (int(round(newpoints[5][0]) - newpoints[0][0]), int(round(newpoints[5][1]) - newpoints[0][1])) - centerPoint = (int(round(newpoints[6][0]) - newpoints[0][0]), int(round(newpoints[6][1]) - newpoints[0][1])) - - def isOverflow(point, width, height): - if point[0] < 0 or point[1] < 0 or point[0] > width - 1or point[1] > height - 1: - return True - return False - - if isOverflow(startPoint, width, height) or isOverflow(endPoint, width, height) or isOverflow(centerPoint, width, height): - print("overflow!") - return template - - # startPointUp = (int(round(newpoints[7][0]) - newpoints[0][0]), int(round(newpoints[7][1]) - newpoints[0][1])) - # endPointUp = (int(round(newpoints[8][0]) - newpoints[0][0]), int(round(newpoints[8][1]) - newpoints[0][1])) - # centerPointUp = (int(round(newpoints[9][0]) - newpoints[0][0]), int(round(newpoints[9][1]) - newpoints[0][1])) - info["startPoint"]["x"] = startPoint[0] - info["startPoint"]["y"] = startPoint[1] - info["centerPoint"]["x"] = centerPoint[0] - info["centerPoint"]["y"] = centerPoint[1] - info["endPoint"]["x"] = endPoint[0] - info["endPoint"]["y"] = endPoint[1] - - return src_correct - - -class AngleFactory: - """method for angle calculation""" - - @staticmethod - def __calAngleBetweenTwoVector(vectorA, vectorB): - """ - get angle formed by two vector - :param vectorA: vector A - :param vectorB: vector B - :return: angle - """ - lenA = np.sqrt(vectorA.dot(vectorA)) - lenB = np.sqrt(vectorB.dot(vectorB)) - cosAngle = vectorA.dot(vectorB) / (lenA * lenB) - angle = np.arccos(cosAngle) - return angle - - @classmethod - def calAngleClockwise(cls, startPoint, endPoint, centerPoint): - """ - get clockwise angle formed by three point - :param startPoint: start point - :param endPoint: end point - :param centerPoint: center point - :return: clockwise angle - """ - vectorA = startPoint - centerPoint - vectorB = endPoint - centerPoint - angle = cls.__calAngleBetweenTwoVector(vectorA, vectorB) - - # if counter-clockwise - if np.cross(vectorA, vectorB) < 0: - angle = 2 * np.pi - angle - - return angle - - @classmethod - def calPointerValueByOuterPoint(cls, startPoint, endPoint, centerPoint, pointerPoint, startValue, totalValue): - """ - get value of pointer meter - :param startPoint: start point - :param endPoint: end point - :param centerPoint: center point - :param pointerPoint: pointer's outer point - :param startValue: start value - :param totalValue: total value - :return: value - """ - angleRange = cls.calAngleClockwise(startPoint, endPoint, centerPoint) - angle = cls.calAngleClockwise(startPoint, pointerPoint, centerPoint) - value = angle / angleRange * totalValue + startValue - if value > totalValue or value < startValue: - return startValue if angle > np.pi + angleRange / 2 else totalValue - return value - - @classmethod - def calPointerValueByPointerVector(cls, startPoint, endPoint, centerPoint, PointerVector, startValue, totalValue): - """ - get value of pointer meter - 注意传入相对圆心的向量 - :param startPoint: start point - :param endPoint: end point - :param centerPoint: center point - :param PointerVector: pointer's vector - :param startValue: start value - :param totalValue: total value - :return: value - """ - angleRange = cls.calAngleClockwise(startPoint, endPoint, centerPoint) - - vectorA = startPoint - centerPoint - vectorB = PointerVector - - angle = cls.__calAngleBetweenTwoVector(vectorA, vectorB) - - # if counter-clockwise - if np.cross(vectorA, vectorB) < 0: - angle = 2 * np.pi - angle - - value = angle / angleRange * totalValue + startValue - if value > totalValue or value < startValue: - return startValue if angle > np.pi + angleRange / 2 else totalValue - return value - - def findPointerFromHSVSpace(src, center, radius, radians_low, radians_high, patch_degree=1.0, ptr_resolution=5, - low_ptr_color=np.array([0, 0, 221]), up_ptr_color=np.array([180, 30, 255])): - - """ - 从固定颜色的区域找指针,未完成 - :param low_ptr_color: 指针的hsv颜色空间的下界 - :param up_ptr_color: 指针的hsv颜色空间的上界 - :param radians_low:圆的搜索范围(弧度制表示) - :param radians_high:圆的搜索范围(弧度制表示) - :param src: 二值图 - :param center: 刻度盘的圆心 - :param radius: 圆的半径 - :param patch_degree:搜索梯度,默认每次一度 - :param ptr_resolution: 指针的粗细程度 - :return: 指针遮罩、直线与圆相交的点 - """ - - pass - - -def scanPointer(meter, info): - """ - find pointer of meter - :param meter: meter matched template - :param pts: a list including three numpy array, eg: [startPointer, endPointer, centerPointer] - :param startVal: an integer of meter start value - :param endVal: an integer of meter ending value - :return: pointer reading number - """ - center = np.array([info["centerPoint"]["x"], info["centerPoint"]["y"]]) - start = np.array([info["startPoint"]["x"], info["startPoint"]["y"]]) - end = np.array([info["endPoint"]["x"], info["endPoint"]["y"]]) - startVal = info["startValue"] - endVal = info["totalValue"] - if meter.shape[0] > 500: - fixHeight = 300 - fixWidth = int(meter.shape[1] / meter.shape[0] * fixHeight) - resizeCoffX = fixWidth / meter.shape[1] - meter = cv2.resize(meter, (fixWidth, fixHeight)) - - start = (start * resizeCoffX).astype(np.int32) - end = (end * resizeCoffX).astype(np.int32) - center = (center * resizeCoffX).astype(np.int32) - - radious = int(EuclideanDistance(start, center)) - - src = cv2.GaussianBlur(meter, (3, 3), sigmaX=0, sigmaY=0, borderType=cv2.BORDER_DEFAULT) - - gray = cv2.cvtColor(src=src, code=cv2.COLOR_RGB2GRAY) - - thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 17, 11) - - mask = np.zeros((src.shape[0], src.shape[1]), np.uint8) - cv2.circle(mask, (center[0], center[1]), radious, (255, 255, 255), -1) - thresh = cv2.bitwise_and(thresh, mask) - cv2.circle(thresh, (center[0], center[1]), int(radious / 3), (0, 0, 0), -1) - - thresh = cv2.erode(thresh, np.ones((3, 3), np.uint8), 3) - thresh = cv2.dilate(thresh, np.ones((5, 5), np.uint8)) - - thresh = cv2.ximgproc.thinning(thresh, thinningType=cv2.ximgproc.THINNING_ZHANGSUEN) - - startAngle = int( - AngleFactory.calAngleClockwise(startPoint=np.array([center[0] + 100, center[1]]), centerPoint=center, - endPoint=start) * 180 / np.pi) - endAngle = int(AngleFactory.calAngleClockwise(startPoint=np.array([center[0] + 100, center[1]]), centerPoint=center, - endPoint=end) * 180 / np.pi) - # print(startAngle, endAngle) - if endAngle <= startAngle: - endAngle += 360 - maxSum = 0 - outerPoint = start - for angle in range(startAngle - 10, endAngle + 10): - pts, outPt = getPoints(center, radious, angle) - thisSum = 0 - showImg = cv2.cvtColor(thresh.copy(), cv2.COLOR_GRAY2BGR) - - for pt in pts: - cv2.circle(showImg, (pt[0], pt[1]), 2, (0, 0, 255), -1) - if thresh[pt[1], pt[0]] != 0: - thisSum += 1 - - # cv2.circle(showImg, (outPt[0], outPt[1]), 2, (255, 0, 0), -1) - # cv2.imshow("img", showImg) - # cv2.waitKey(1) - if thisSum > maxSum: - maxSum = thisSum - outerPoint = outPt - - if start[0] == outerPoint[0] and start[1] == outerPoint[1]: - degree = startVal - elif end[0] == outerPoint[0] and end[1] == outerPoint[1]: - degree = endVal - else: - if start.all() == end.all(): - end[0] -= 1 - end[1] -= 3 - degree = AngleFactory.calPointerValueByOuterPoint(start, end, center, outerPoint, startVal, endVal) - - # small value to zero - if degree < 0.05 * endVal: - degree = startVal - - if ifShow: - # print(degree, start, center, outerPoint) - cv2.circle(meter, (outerPoint[0], outerPoint[1]), 10, (0, 0, 255), -1) - cv2.line(meter, (center[0], center[1]), (outerPoint[0], outerPoint[1]), (0, 0, 255), 5) - cv2.line(meter, (center[0], center[1]), (start[0], start[1]), (255, 0, 0), 3) - cv2.line(meter, (center[0], center[1]), (end[0], end[1]), (255, 0, 0), 3) - - thresh = np.expand_dims(thresh, axis=2) - thresh = np.concatenate((thresh, thresh, thresh), 2) - meter = np.hstack((meter, thresh)) - - cv2.imshow("test", meter) - cv2.waitKey(0) - return degree - - -def EuclideanDistance(pt1, pt2): - return np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2) - - -def getPoints(center, radious, angle): - res = [] - farthestPointX = int(center[0] + radious * np.cos(angle / 180 * np.pi)) - farthestPointY = int(center[1] + radious * np.sin(angle / 180 * np.pi)) - - for ro in range(radious // 3, radious): - for theta in range(angle - 2, angle + 2): - angleTemp = theta / 180 * np.pi - x, y = int(ro * np.cos(angleTemp)) + center[0], int(ro * np.sin(angleTemp)) + center[1] - res.append([x, y]) - - # width = 2 - # - # - # for x in range(min(farthestPointX, center[0]), max(farthestPointX, center[0])): - # for y in range(min(farthestPointY, center[1]), max(farthestPointY, center[1])): - # if k * x + b - 2 <= y <= k * x + b + 2: - # res.append([x, y]) - - return res, [farthestPointX, farthestPointY] - - -def findPointerFromBinarySpace(src, center, radius, radians_low, radians_high, patch_degree=1.0, ptr_resolution=5): - """ - 接收一张预处理过的二值图(默认较完整保留了指针信息),从通过圆心水平线右边的点开始,连接圆心顺时针建立直线遮罩,取出遮罩范围下的区域, - 计算对应区域灰度和,灰度和最大的区域即为指针所在的位置。直线遮罩的粗细程度、搜索的梯度决定了算法侦测指针的细粒度。该算法适合搜索指针形状 - 为直线的仪表盘,原理与@pointerMaskBySector类似。 - :param radians_low:圆的搜索范围(弧度制表示) - :param radians_high:圆的搜索范围(弧度制表示) - :param src: 二值图 - :param center: 刻度盘的圆心 - :param radius: 圆的半径 - :param patch_degree:搜索梯度,默认每次一度 - :param ptr_resolution: 指针的粗细程度 - :return: 指针遮罩、直线与圆相交的点 - """ - _shape = src.shape - img = src.copy() - # 弧度转化为角度值 - low = math.degrees(radians_low) - high = math.degrees(radians_high) - # _img1 = cv2.erode(_img1, kernel3, iterations=1) - # _img1 = cv2.dilate(_img1, kernel3, iterations=1) - # 157=pi/2*100 - mask_info = [] - max_area = 0 - best_theta = 0 - iteration = np.abs(int((high - low) / patch_degree)) - for i in range(iteration): - # 建立一个大小跟输入一致的全黑图像 - # pointer_mask = np.zeros([_shape[0], _shape[1]], np.uint8) - # theta = float(i) * 0.01 - # 每次旋转patch_degree度,取圆上一点 - theta = float(i * patch_degree / 180 * np.pi) - pointer_mask, point = drawLineMask(_shape, theta, center, ptr_resolution, radius) - # cv2.circle(black_img, (x1, y1), 2, 255, 3) - # cv2.circle(black_img, (item[0], item[1]), 2, 255, 3) - # cv2.line(pointer_mask, (center[0], center[1]), point, 255, ptr_resolution) - # 去除遮罩对应的小区域 - and_img = cv2.bitwise_and(pointer_mask, img) - not_zero_intensity = cv2.countNonZero(and_img) - mask_info.append((not_zero_intensity, theta)) - # if not_zero_intensity > mask_intensity: - # mask_intensity = not_zero_intensity - # mask_theta = theta - # imwrite(dir_path+'/2_line1.jpg', black_img) - # 按灰度和从大到小排列 - mask_info = sorted(mask_info, key=lambda m: m[0], reverse=True) - # thresh = mask_info[0][0] / 30 - # over_index = 1 - # sum = thresh - # for info in mask_info[1:]: - # if mask_info[0][0] - info[0] > thresh: - # break - # over_index += 1 - best_theta = mask_info[0][1] - # 得到灰度和最大的那个直线遮罩,和直线与圆相交的点 - pointer_mask, point = drawLineMask(_shape, best_theta, center, ptr_resolution, radius) - # - # black_img1 = np.zeros([_shape[0], _shape[1]], np.uint8) - # r = item[2]-20 if item[2]==_heart[1][2] else _heart[1][2]+ _heart[0][1]-_heart[1][1]-20 - # y1 = int(item[1] - math.sin(mask_theta) * (r)) - # x1 = int(item[0] + math.cos(mask_theta) * (r)) - # cv2.line(black_img1, (item[0], item[1]), (x1, y1), 255, 7) - # src = cv2.subtract(src, line_mask) - # img = cv2.subtract(img, line_mask) - best_theta = 180 - best_theta * 180 / np.pi - if best_theta < 0: - best_theta = 360 - best_theta - return pointer_mask, best_theta, point - - -def drawLineMask(_shape, theta, center, ptr_resolution, radius): - """ - 画一个长为radius,白色的直线,产生一个背景全黑的白色直线遮罩 - :param _shape: - :param theta: - :param center: - :param ptr_resolution: - :param radius: - :return: - """ - pointer_mask = np.zeros([_shape[0], _shape[1]], np.uint8) - y1 = int(center[1] - np.sin(theta) * radius) - x1 = int(center[0] + np.cos(theta) * radius) - cv2.line(pointer_mask, (center[0], center[1]), (x1, y1), 255, ptr_resolution) - return pointer_mask, (x1, y1) - - -def detectHoughLine(meter, cannyThresholds, houghParam): - ''' - detect pointer of meter - :param meter: - :param cannyThresholds: [threshold1, threshold2], parameters of function Canny - :param houghParam: - :return: - ''' - img = cv2.GaussianBlur(meter, (3, 3), 0) # cv2.imshow("GaussianBlur ", img) - edges = cv2.Canny(img, cannyThresholds[0], cannyThresholds[1], apertureSize=3) - # cv2.imshow("canny", edges) - lines = cv2.HoughLines(edges, 1, np.pi / 180, houghParam) # 这里对最后一个参数使用了经验型的值 - if lines is None: - return None - height, width, _ = img.shape - pointer = [] - rho, theta = lines[0][0] - a = np.cos(theta) - b = np.sin(theta) - x0 = a * rho - y0 = b * rho - # print("x0, y0:", x0, y0) - # print("width, height ", width, height) - xcenter = int(width / 2) - ycenter = int(height / 2) - if xcenter < x0 or (xcenter == x0 and ycenter > y0): - x1 = xcenter - x2 = x0 - y1 = ycenter - y2 = y0 - else: - x1 = x0 - x2 = xcenter - y1 = y0 - y2 = ycenter - cv2.line(meter, (x1, y1), (x2, y2), (0, 0, 255), 2) - # cv2.imshow("HoughLine", meter) - cv2.waitKey(0) - pointer.append([x2 - x1, y2 - y1]) - pointer = np.array(pointer[0]) - return pointer diff --git a/algorithm/debug.py b/algorithm/debug.py deleted file mode 100644 index 72ba9b0..0000000 --- a/algorithm/debug.py +++ /dev/null @@ -1,3 +0,0 @@ -ifShow = False - - diff --git a/algorithm/highlightDigitMeter.py b/algorithm/highlightDigitMeter.py deleted file mode 100644 index 597efa6..0000000 --- a/algorithm/highlightDigitMeter.py +++ /dev/null @@ -1,132 +0,0 @@ -import numpy as np -import cv2 -import math -from algorithm.OCR.utils import * - - -def highlightDigit(image, info): - """ - 识别含有红色高亮数字区域的模块 - :param image: 输入图片 - :param info: 标记信息 - :return: - """ - # 模型初始化 - tfNet_ = tfNet() - - # 图像预处理 - gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - # cv2.imshow("gray", gray) - ret, thresh = cv2.threshold(gray, gray.max() - 25, gray.max(), cv2.THRESH_BINARY) - - # 对高亮区域进行列投影,并且找到高亮区域块,将其分离 - rows = np.sum(thresh, axis=1) - mark = 0 - total = 0 - row_points = [] - - for i, row in enumerate(rows): - if mark == 0 and row > 1000: - start = i - mark = 1 - total = total + row - elif mark == 1: - total = total + row - if row < 1000: - end = i - mark = 0 - row_points.append(start) - row_points.append(end) - row_points.append(total) - total = 0 - row_points = np.array(row_points, dtype="int").reshape((-1, 3)) - args = np.argsort(-row_points[:, 2]) - args = args[:info["nRows"]] - args = args[np.argsort(args)] - row_points = row_points[args] - - blobs = [] - - # 根据找到的高亮块,进行逐块的数字识别 - for i, row_point in enumerate(row_points): - thresh1 = thresh[row_point[0]:row_point[1]] - cols = np.sum(thresh1, axis=0) - mark = 0 - total = 0 - col_points = [] - for j, col in enumerate(cols): - if mark == 0 and col > 1000: - start = j - mark = 1 - total = total + col - elif mark == 1: - total = total + col - if col < 1000: - end = j - mark = 0 - col_points.append(start) - col_points.append(end) - col_points.append(total) - total = 0 - col_points = np.array(col_points, dtype="int").reshape((-1, 3)) - # print(col_points) - for j, col_point in enumerate(col_points): - img = thresh[row_point[0] - 2:row_point[1] + 2, col_point[0] - 2:col_point[1] + 2] - if img.shape[0] > img.shape[1]: - new_img = np.zeros([img.shape[0], img.shape[0]]) - subs = img.shape[0] - img.shape[1] - subs = subs // 2 - new_img[:, subs:subs + img.shape[1]] = img - new_img = cv2.resize(new_img, (28, 28)) - # cv2.imshow("test", img) - # cv2.waitKey(0) - new_img = new_img.reshape(-1, 784) - new_img = np.minimum(new_img, 1) - predict = tfNet_.recognizeNet2(new_img) - # print(predict) - col_points[j][2] = predict - col_points = col_points.tolist() - new_col_points = [col_point for col_point in col_points if col_point[2] != 10] - blobs.append(new_col_points) - blobs = np.array(blobs) - values = [] - for i, blob in enumerate(blobs): - vals = [] - nCols = info["row" + str(i + 1)]["nCols"] - # print(blob) - if nCols > 1: - distances = [] - for j in range(1, blob.shape[0]): - dis = blob[j][0] - blob[j - 1][1] - distances.append(dis) - distances = np.array(distances) - indexs = np.argsort(-distances) - index = indexs[:nCols - 1] - index = index[np.argsort(index)] - index = index + 1 - index = np.insert(index, 0, 0) - index = np.append(index, len(blob)) - # print(index) - for j in range(len(index) - 1): - nDecimals = info["row" + str(i + 1)]["col" + str(j + 1)]["nDecimals"] - t_b = blob[index[j]:index[j + 1]] - tmp = "" - for k in range(t_b.shape[0] - 1, -1, -1): - tmp = tmp + str(blob[blob.shape[0] - k - 1][2]) - if k == nDecimals: - tmp = tmp + "." - # val = float(tmp) - # val = round(val, nDecimals) - vals.append(tmp) - else: - tmp = "" - nDecimals = info["row" + str(i + 1)]["col1"]["nDecimals"] - for j in range(blob.shape[0] - 1, -1, -1): - tmp = tmp + str(blob[blob.shape[0] - j - 1][2]) - if j == nDecimals: - tmp = tmp + "." - # val = float(tmp) - # val = round(val, nDecimals) - vals.append(tmp) - values.append(vals) - return values diff --git a/algorithm/pressure/normalPressure.py b/algorithm/pressure/normalPressure.py deleted file mode 100644 index 3d1bae5..0000000 --- a/algorithm/pressure/normalPressure.py +++ /dev/null @@ -1,70 +0,0 @@ -import json - -import cv2 -import numpy as np - -from algorithm.Common import * - -plot_index = 0 - -def normalPressure(image, info): - """ - :param image: ROI image - :param info: information for this meter - :return: value - """ - meter = meterFinderBySIFT(image, info) - result = scanPointer(meter, info) - result = int(result*1000) / 1000 - return result - -def inc(): - global plot_index - plot_index += 1 - return plot_index - -def calAvgRadius(center, end_ptr, radius, start_ptr): - radius_1 = np.sqrt(np.power(start_ptr[0] - center[0], 2) + np.power(start_ptr[1] - center[1], 2)) - radius_2 = np.sqrt(np.power(end_ptr[0] - center[0], 2) + np.power(end_ptr[1] - center[1], 2)) - radius = np.int64((radius_1 + radius_2) / 2) - return radius - -def cvtPtrDic2D(dic_ptr): - """ - point.x,point.y转numpy数组 - :param dic_ptr: - :return: - """ - if dic_ptr['x'] and dic_ptr['y'] is not None: - dic_ptr = np.array([dic_ptr['x'], dic_ptr['y']]) - else: - return np.array([0, 0]) - return dic_ptr - -def cv2PtrTuple2D(tuple): - """ - tuple 转numpy 数组 - :param tuple: - :return: - """ - if tuple[0] and tuple[1] is not None: - tuple = np.array([tuple[0], tuple[1]]) - else: - return np.array([0, 0]) - return tuple - -def cleanNoisedRegions(src, info, shape): - """ - 根据标定信息清楚一些有干扰性的区域 - :param src: - :param info: - :param shape: - :return: - """ - if 'noisedRegion' in info and info['noisedRegion'] is not None: - region_roi = info['noisedRegion'] - for roi in region_roi: - mask = cv2.bitwise_not(np.zeros(shape=(shape[0], shape[1]), dtype=np.uint8)) - mask[roi[1]:roi[1] + roi[3], roi[0]:roi[0] + roi[2]] = 0 - src = cv2.bitwise_and(src, mask) - return src diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000..6cd8f00 --- /dev/null +++ b/configuration.py @@ -0,0 +1,8 @@ +ifShow = True + + +configPath = "info/20190410/config" +templatePath = "info/20190410/template" +# +# configPath = "info/20190128/config" +# templatePath = "info/20190128/template" diff --git a/image/1-1.jpg b/image/1-1.jpg deleted file mode 100644 index 0867f72..0000000 Binary files a/image/1-1.jpg and /dev/null differ diff --git a/image/1-2.jpg b/image/1-2.jpg deleted file mode 100644 index 6b8a676..0000000 Binary files a/image/1-2.jpg and /dev/null differ diff --git a/image/10-1.jpg b/image/10-1.jpg deleted file mode 100644 index da84274..0000000 Binary files a/image/10-1.jpg and /dev/null differ diff --git a/image/11-1.jpg b/image/11-1.jpg deleted file mode 100644 index c979c0f..0000000 Binary files a/image/11-1.jpg and /dev/null differ diff --git a/image/12-1.jpg b/image/12-1.jpg deleted file mode 100644 index f28a29a..0000000 Binary files a/image/12-1.jpg and /dev/null differ diff --git a/image/13-1.jpg b/image/13-1.jpg deleted file mode 100644 index 9f95ca2..0000000 Binary files a/image/13-1.jpg and /dev/null differ diff --git a/image/14-1.jpg b/image/14-1.jpg deleted file mode 100644 index aa2d85a..0000000 Binary files a/image/14-1.jpg and /dev/null differ diff --git a/image/15-1.jpg b/image/15-1.jpg deleted file mode 100644 index 73a6dd7..0000000 Binary files a/image/15-1.jpg and /dev/null differ diff --git a/image/15-2.jpg b/image/15-2.jpg deleted file mode 100644 index 64c928f..0000000 Binary files a/image/15-2.jpg and /dev/null differ diff --git a/image/16-1.jpg b/image/16-1.jpg deleted file mode 100644 index b045ca3..0000000 Binary files a/image/16-1.jpg and /dev/null differ diff --git a/image/16-2.jpg b/image/16-2.jpg deleted file mode 100644 index 4ac354a..0000000 Binary files a/image/16-2.jpg and /dev/null differ diff --git a/image/17-1.jpg b/image/17-1.jpg deleted file mode 100644 index 3153b77..0000000 Binary files a/image/17-1.jpg and /dev/null differ diff --git a/image/17-2.jpg b/image/17-2.jpg deleted file mode 100644 index 15dac40..0000000 Binary files a/image/17-2.jpg and /dev/null differ diff --git a/image/17-3.jpg b/image/17-3.jpg deleted file mode 100644 index 7dc7f0a..0000000 Binary files a/image/17-3.jpg and /dev/null differ diff --git a/image/18-1.jpg b/image/18-1.jpg deleted file mode 100644 index 5bc2726..0000000 Binary files a/image/18-1.jpg and /dev/null differ diff --git a/image/18-2.jpg b/image/18-2.jpg deleted file mode 100644 index dacc7d1..0000000 Binary files a/image/18-2.jpg and /dev/null differ diff --git a/image/18-3.jpg b/image/18-3.jpg deleted file mode 100644 index 3f309ac..0000000 Binary files a/image/18-3.jpg and /dev/null differ diff --git a/image/18-4.jpg b/image/18-4.jpg deleted file mode 100644 index 3633642..0000000 Binary files a/image/18-4.jpg and /dev/null differ diff --git a/image/19-1.jpg b/image/19-1.jpg deleted file mode 100644 index a7868fb..0000000 Binary files a/image/19-1.jpg and /dev/null differ diff --git a/image/2-1.jpg b/image/2-1.jpg deleted file mode 100644 index 6e10292..0000000 Binary files a/image/2-1.jpg and /dev/null differ diff --git a/image/20-1.jpg b/image/20-1.jpg deleted file mode 100644 index a1de0d6..0000000 Binary files a/image/20-1.jpg and /dev/null differ diff --git a/image/21-1.jpg b/image/21-1.jpg deleted file mode 100644 index 7efd9ec..0000000 Binary files a/image/21-1.jpg and /dev/null differ diff --git a/image/22-1.jpg b/image/22-1.jpg deleted file mode 100644 index 985f577..0000000 Binary files a/image/22-1.jpg and /dev/null differ diff --git a/image/23-1.jpg b/image/23-1.jpg deleted file mode 100644 index e88bca2..0000000 Binary files a/image/23-1.jpg and /dev/null differ diff --git a/image/23-2.jpg b/image/23-2.jpg deleted file mode 100644 index a02f1c0..0000000 Binary files a/image/23-2.jpg and /dev/null differ diff --git a/image/24-1.jpg b/image/24-1.jpg deleted file mode 100644 index 7a942b3..0000000 Binary files a/image/24-1.jpg and /dev/null differ diff --git a/image/25-1.jpg b/image/25-1.jpg deleted file mode 100644 index 3358ce7..0000000 Binary files a/image/25-1.jpg and /dev/null differ diff --git a/image/26-1.jpg b/image/26-1.jpg deleted file mode 100644 index df167f2..0000000 Binary files a/image/26-1.jpg and /dev/null differ diff --git a/image/4-1.jpg b/image/4-1.jpg deleted file mode 100644 index eeb9d37..0000000 Binary files a/image/4-1.jpg and /dev/null differ diff --git a/image/9-1.jpg b/image/9-1.jpg deleted file mode 100644 index c0a195c..0000000 Binary files a/image/9-1.jpg and /dev/null differ diff --git a/config/1-1_1.json b/info/20190128/config/1-1_1.json similarity index 100% rename from config/1-1_1.json rename to info/20190128/config/1-1_1.json diff --git a/config/1-1_2.json b/info/20190128/config/1-1_2.json similarity index 100% rename from config/1-1_2.json rename to info/20190128/config/1-1_2.json diff --git a/config/1-2_1.json b/info/20190128/config/1-2_1.json similarity index 100% rename from config/1-2_1.json rename to info/20190128/config/1-2_1.json diff --git a/config/1-2_2.json b/info/20190128/config/1-2_2.json similarity index 100% rename from config/1-2_2.json rename to info/20190128/config/1-2_2.json diff --git a/config/10-1_1.json b/info/20190128/config/10-1_1.json similarity index 100% rename from config/10-1_1.json rename to info/20190128/config/10-1_1.json diff --git a/config/11-1_1.json b/info/20190128/config/11-1_1.json similarity index 100% rename from config/11-1_1.json rename to info/20190128/config/11-1_1.json diff --git a/config/12-1_1.json b/info/20190128/config/12-1_1.json similarity index 100% rename from config/12-1_1.json rename to info/20190128/config/12-1_1.json diff --git a/config/13-1_1.json b/info/20190128/config/13-1_1.json similarity index 100% rename from config/13-1_1.json rename to info/20190128/config/13-1_1.json diff --git a/config/13-1_2.json b/info/20190128/config/13-1_2.json similarity index 100% rename from config/13-1_2.json rename to info/20190128/config/13-1_2.json diff --git a/config/14-1_1.json b/info/20190128/config/14-1_1.json similarity index 100% rename from config/14-1_1.json rename to info/20190128/config/14-1_1.json diff --git a/config/15-1_1.json b/info/20190128/config/15-1_1.json similarity index 100% rename from config/15-1_1.json rename to info/20190128/config/15-1_1.json diff --git a/config/15-2_1.json b/info/20190128/config/15-2_1.json similarity index 100% rename from config/15-2_1.json rename to info/20190128/config/15-2_1.json diff --git a/config/16-1_1.json b/info/20190128/config/16-1_1.json similarity index 100% rename from config/16-1_1.json rename to info/20190128/config/16-1_1.json diff --git a/config/16-2_1.json b/info/20190128/config/16-2_1.json similarity index 100% rename from config/16-2_1.json rename to info/20190128/config/16-2_1.json diff --git a/config/17-1_1.json b/info/20190128/config/17-1_1.json similarity index 100% rename from config/17-1_1.json rename to info/20190128/config/17-1_1.json diff --git a/config/17-2_1.json b/info/20190128/config/17-2_1.json similarity index 100% rename from config/17-2_1.json rename to info/20190128/config/17-2_1.json diff --git a/config/17-3_1.json b/info/20190128/config/17-3_1.json similarity index 100% rename from config/17-3_1.json rename to info/20190128/config/17-3_1.json diff --git a/config/18-1_1.json b/info/20190128/config/18-1_1.json similarity index 100% rename from config/18-1_1.json rename to info/20190128/config/18-1_1.json diff --git a/config/18-2_1.json b/info/20190128/config/18-2_1.json similarity index 100% rename from config/18-2_1.json rename to info/20190128/config/18-2_1.json diff --git a/config/18-3_1.json b/info/20190128/config/18-3_1.json similarity index 100% rename from config/18-3_1.json rename to info/20190128/config/18-3_1.json diff --git a/config/18-4_1.json b/info/20190128/config/18-4_1.json similarity index 100% rename from config/18-4_1.json rename to info/20190128/config/18-4_1.json diff --git a/config/19-1_1.json b/info/20190128/config/19-1_1.json similarity index 100% rename from config/19-1_1.json rename to info/20190128/config/19-1_1.json diff --git a/config/2-1_1.json b/info/20190128/config/2-1_1.json similarity index 100% rename from config/2-1_1.json rename to info/20190128/config/2-1_1.json diff --git a/config/20-1_1.json b/info/20190128/config/20-1_1.json similarity index 100% rename from config/20-1_1.json rename to info/20190128/config/20-1_1.json diff --git a/config/21-1_1.json b/info/20190128/config/21-1_1.json similarity index 100% rename from config/21-1_1.json rename to info/20190128/config/21-1_1.json diff --git a/config/22-1_1.json b/info/20190128/config/22-1_1.json similarity index 100% rename from config/22-1_1.json rename to info/20190128/config/22-1_1.json diff --git a/config/22-1_2.json b/info/20190128/config/22-1_2.json similarity index 100% rename from config/22-1_2.json rename to info/20190128/config/22-1_2.json diff --git a/config/23-1_1.json b/info/20190128/config/23-1_1.json similarity index 100% rename from config/23-1_1.json rename to info/20190128/config/23-1_1.json diff --git a/config/23-2_1.json b/info/20190128/config/23-2_1.json similarity index 100% rename from config/23-2_1.json rename to info/20190128/config/23-2_1.json diff --git a/config/24-1_1.json b/info/20190128/config/24-1_1.json similarity index 100% rename from config/24-1_1.json rename to info/20190128/config/24-1_1.json diff --git a/config/25-1_1.json b/info/20190128/config/25-1_1.json similarity index 100% rename from config/25-1_1.json rename to info/20190128/config/25-1_1.json diff --git a/config/26-1_1.json b/info/20190128/config/26-1_1.json similarity index 100% rename from config/26-1_1.json rename to info/20190128/config/26-1_1.json diff --git a/config/27-1_1.json b/info/20190128/config/27-1_1.json similarity index 100% rename from config/27-1_1.json rename to info/20190128/config/27-1_1.json diff --git a/config/28-1_1.json b/info/20190128/config/28-1_1.json similarity index 100% rename from config/28-1_1.json rename to info/20190128/config/28-1_1.json diff --git a/config/4-1_1.json b/info/20190128/config/4-1_1.json similarity index 100% rename from config/4-1_1.json rename to info/20190128/config/4-1_1.json diff --git a/config/5-1_1.json b/info/20190128/config/5-1_1.json similarity index 100% rename from config/5-1_1.json rename to info/20190128/config/5-1_1.json diff --git a/config/7-1_1.json b/info/20190128/config/7-1_1.json similarity index 100% rename from config/7-1_1.json rename to info/20190128/config/7-1_1.json diff --git a/config/8-1_1.json b/info/20190128/config/8-1_1.json similarity index 100% rename from config/8-1_1.json rename to info/20190128/config/8-1_1.json diff --git a/config/9-1_1.json b/info/20190128/config/9-1_1.json similarity index 100% rename from config/9-1_1.json rename to info/20190128/config/9-1_1.json diff --git a/config/ConfigTemplate.json b/info/20190128/config/ConfigTemplate.json old mode 100755 new mode 100644 similarity index 94% rename from config/ConfigTemplate.json rename to info/20190128/config/ConfigTemplate.json index 5e7a349..a940795 --- a/config/ConfigTemplate.json +++ b/info/20190128/config/ConfigTemplate.json @@ -1,38 +1,38 @@ -{ - "name": "null", - "type": "Remember", - "ROI": { - "x": 0, - "y": 0, - "w": 0, - "h": 0 - }, - "startPoint": { - "x": 0, - "y": 0 - }, - "endPoint": { - "x": 0, - "y": 0 - }, - "centerPoint": { - "x": 0, - "y": 0 - }, - "startPointUp": { - "x": 0, - "y": 0 - }, - "endPointUp": { - "x": 0, - "y": 0 - }, - "centerPointUp": { - "x": 0, - "y": 0 - }, - "startValue": 0.0, +{ + "name": "null", + "type": "Remember", + "ROI": { + "x": 0, + "y": 0, + "w": 0, + "h": 0 + }, + "startPoint": { + "x": 0, + "y": 0 + }, + "endPoint": { + "x": 0, + "y": 0 + }, + "centerPoint": { + "x": 0, + "y": 0 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, "totalValue": 0.0, - "digitType": "False", - "result": 0.0 + "digitType": "False", + "result": 0.0 } \ No newline at end of file diff --git a/template/1-1_1.jpg b/info/20190128/template/1-1_1.jpg similarity index 100% rename from template/1-1_1.jpg rename to info/20190128/template/1-1_1.jpg diff --git a/template/1-1_2.jpg b/info/20190128/template/1-1_2.jpg similarity index 100% rename from template/1-1_2.jpg rename to info/20190128/template/1-1_2.jpg diff --git a/template/1-2_1.jpg b/info/20190128/template/1-2_1.jpg similarity index 100% rename from template/1-2_1.jpg rename to info/20190128/template/1-2_1.jpg diff --git a/template/1-2_2.jpg b/info/20190128/template/1-2_2.jpg similarity index 100% rename from template/1-2_2.jpg rename to info/20190128/template/1-2_2.jpg diff --git a/template/10-1_1.jpg b/info/20190128/template/10-1_1.jpg similarity index 100% rename from template/10-1_1.jpg rename to info/20190128/template/10-1_1.jpg diff --git a/template/11-1_1.jpg b/info/20190128/template/11-1_1.jpg similarity index 100% rename from template/11-1_1.jpg rename to info/20190128/template/11-1_1.jpg diff --git a/template/12-1_1.jpg b/info/20190128/template/12-1_1.jpg similarity index 100% rename from template/12-1_1.jpg rename to info/20190128/template/12-1_1.jpg diff --git a/template/13-1_1.jpg b/info/20190128/template/13-1_1.jpg similarity index 100% rename from template/13-1_1.jpg rename to info/20190128/template/13-1_1.jpg diff --git a/template/13-1_2.jpg b/info/20190128/template/13-1_2.jpg similarity index 100% rename from template/13-1_2.jpg rename to info/20190128/template/13-1_2.jpg diff --git a/template/14-1_1.jpg b/info/20190128/template/14-1_1.jpg similarity index 100% rename from template/14-1_1.jpg rename to info/20190128/template/14-1_1.jpg diff --git a/template/15-1_1.jpg b/info/20190128/template/15-1_1.jpg similarity index 100% rename from template/15-1_1.jpg rename to info/20190128/template/15-1_1.jpg diff --git a/template/15-2_1.jpg b/info/20190128/template/15-2_1.jpg similarity index 100% rename from template/15-2_1.jpg rename to info/20190128/template/15-2_1.jpg diff --git a/template/16-1_1.jpg b/info/20190128/template/16-1_1.jpg similarity index 100% rename from template/16-1_1.jpg rename to info/20190128/template/16-1_1.jpg diff --git a/template/16-2_1.jpg b/info/20190128/template/16-2_1.jpg similarity index 100% rename from template/16-2_1.jpg rename to info/20190128/template/16-2_1.jpg diff --git a/template/17-1_1.jpg b/info/20190128/template/17-1_1.jpg similarity index 100% rename from template/17-1_1.jpg rename to info/20190128/template/17-1_1.jpg diff --git a/template/17-2_1.jpg b/info/20190128/template/17-2_1.jpg similarity index 100% rename from template/17-2_1.jpg rename to info/20190128/template/17-2_1.jpg diff --git a/template/17-3_1.jpg b/info/20190128/template/17-3_1.jpg similarity index 100% rename from template/17-3_1.jpg rename to info/20190128/template/17-3_1.jpg diff --git a/template/18-1_1.jpg b/info/20190128/template/18-1_1.jpg similarity index 100% rename from template/18-1_1.jpg rename to info/20190128/template/18-1_1.jpg diff --git a/template/18-2_1.jpg b/info/20190128/template/18-2_1.jpg similarity index 100% rename from template/18-2_1.jpg rename to info/20190128/template/18-2_1.jpg diff --git a/template/18-3_1.jpg b/info/20190128/template/18-3_1.jpg similarity index 100% rename from template/18-3_1.jpg rename to info/20190128/template/18-3_1.jpg diff --git a/template/18-4_1.jpg b/info/20190128/template/18-4_1.jpg similarity index 100% rename from template/18-4_1.jpg rename to info/20190128/template/18-4_1.jpg diff --git a/template/19-1_1.jpg b/info/20190128/template/19-1_1.jpg similarity index 100% rename from template/19-1_1.jpg rename to info/20190128/template/19-1_1.jpg diff --git a/template/2-1_1.jpg b/info/20190128/template/2-1_1.jpg similarity index 100% rename from template/2-1_1.jpg rename to info/20190128/template/2-1_1.jpg diff --git a/template/20-1_1.jpg b/info/20190128/template/20-1_1.jpg similarity index 100% rename from template/20-1_1.jpg rename to info/20190128/template/20-1_1.jpg diff --git a/template/21-1_1.jpg b/info/20190128/template/21-1_1.jpg similarity index 100% rename from template/21-1_1.jpg rename to info/20190128/template/21-1_1.jpg diff --git a/template/22-1_1.jpg b/info/20190128/template/22-1_1.jpg similarity index 100% rename from template/22-1_1.jpg rename to info/20190128/template/22-1_1.jpg diff --git a/template/22-1_2.jpg b/info/20190128/template/22-1_2.jpg similarity index 100% rename from template/22-1_2.jpg rename to info/20190128/template/22-1_2.jpg diff --git a/template/23-1_1.jpg b/info/20190128/template/23-1_1.jpg similarity index 100% rename from template/23-1_1.jpg rename to info/20190128/template/23-1_1.jpg diff --git a/template/23-2_1.jpg b/info/20190128/template/23-2_1.jpg similarity index 100% rename from template/23-2_1.jpg rename to info/20190128/template/23-2_1.jpg diff --git a/template/24-1_1.jpg b/info/20190128/template/24-1_1.jpg similarity index 100% rename from template/24-1_1.jpg rename to info/20190128/template/24-1_1.jpg diff --git a/template/25-1_1.jpg b/info/20190128/template/25-1_1.jpg similarity index 100% rename from template/25-1_1.jpg rename to info/20190128/template/25-1_1.jpg diff --git a/template/26-1_1.jpg b/info/20190128/template/26-1_1.jpg similarity index 100% rename from template/26-1_1.jpg rename to info/20190128/template/26-1_1.jpg diff --git a/template/27-1_1.jpg b/info/20190128/template/27-1_1.jpg similarity index 100% rename from template/27-1_1.jpg rename to info/20190128/template/27-1_1.jpg diff --git a/template/28-1_1.jpg b/info/20190128/template/28-1_1.jpg similarity index 100% rename from template/28-1_1.jpg rename to info/20190128/template/28-1_1.jpg diff --git a/template/4-1_1.jpg b/info/20190128/template/4-1_1.jpg similarity index 100% rename from template/4-1_1.jpg rename to info/20190128/template/4-1_1.jpg diff --git a/template/5-1_1.jpg b/info/20190128/template/5-1_1.jpg similarity index 100% rename from template/5-1_1.jpg rename to info/20190128/template/5-1_1.jpg diff --git a/template/7-1_1.jpg b/info/20190128/template/7-1_1.jpg similarity index 100% rename from template/7-1_1.jpg rename to info/20190128/template/7-1_1.jpg diff --git a/template/8-1_1.jpg b/info/20190128/template/8-1_1.jpg similarity index 100% rename from template/8-1_1.jpg rename to info/20190128/template/8-1_1.jpg diff --git a/template/9-1_1.jpg b/info/20190128/template/9-1_1.jpg similarity index 100% rename from template/9-1_1.jpg rename to info/20190128/template/9-1_1.jpg diff --git a/info/20190410/config/1-1_1.json b/info/20190410/config/1-1_1.json new file mode 100644 index 0000000..60310d6 --- /dev/null +++ b/info/20190410/config/1-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 65, + "y": 50, + "w": 1125, + "h": 600 + }, + "startPoint": { + "x": 53, + "y": 174 + }, + "endPoint": { + "x": 159, + "y": 173 + }, + "centerPoint": { + "x": 105, + "y": 121 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 100.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/2-1_1.json b/info/20190410/config/2-1_1.json new file mode 100644 index 0000000..9b63635 --- /dev/null +++ b/info/20190410/config/2-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 75, + "y": 50, + "w": 1175, + "h": 640 + }, + "startPoint": { + "x": 113, + "y": 229 + }, + "endPoint": { + "x": 216, + "y": 231 + }, + "centerPoint": { + "x": 161, + "y": 278 + }, + "startPointUp": { + "x": 170, + "y": 95 + }, + "endPointUp": { + "x": 164, + "y": 95 + }, + "centerPointUp": { + "x": 165, + "y": 133 + }, + "startValue": 0.0, + "totalValue": 0.9, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/3-1_1.json b/info/20190410/config/3-1_1.json new file mode 100644 index 0000000..6fd1ff2 --- /dev/null +++ b/info/20190410/config/3-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 50, + "y": 45, + "w": 1205, + "h": 655 + }, + "startPoint": { + "x": 85, + "y": 235 + }, + "endPoint": { + "x": 235, + "y": 197 + }, + "centerPoint": { + "x": 139, + "y": 146 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 1.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/3-2_1.json b/info/20190410/config/3-2_1.json new file mode 100644 index 0000000..cb674c6 --- /dev/null +++ b/info/20190410/config/3-2_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "digitPressure", + "ROI": { + "x": 40, + "y": 50, + "w": 1170, + "h": 640 + }, + "startPoint": { + "x": 37, + "y": 39 + }, + "endPoint": { + "x": 148, + "y": 194 + }, + "centerPoint": { + "x": 146, + "y": 38 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 0.0, + "digitType": "TEST", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/4-1_1.json b/info/20190410/config/4-1_1.json new file mode 100644 index 0000000..f40ad83 --- /dev/null +++ b/info/20190410/config/4-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 40, + "y": 55, + "w": 1225, + "h": 620 + }, + "startPoint": { + "x": 88, + "y": 163 + }, + "endPoint": { + "x": 166, + "y": 167 + }, + "centerPoint": { + "x": 130, + "y": 130 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": -10.0, + "totalValue": 0.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/5-1_1.json b/info/20190410/config/5-1_1.json new file mode 100644 index 0000000..f5dde2e --- /dev/null +++ b/info/20190410/config/5-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 55, + "y": 55, + "w": 1180, + "h": 630 + }, + "startPoint": { + "x": 44, + "y": 176 + }, + "endPoint": { + "x": 155, + "y": 58 + }, + "centerPoint": { + "x": 153, + "y": 169 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 200.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/6-1_1.json b/info/20190410/config/6-1_1.json new file mode 100644 index 0000000..57dde66 --- /dev/null +++ b/info/20190410/config/6-1_1.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "normalPressure", + "ROI": { + "x": 95, + "y": 15, + "w": 1150, + "h": 665 + }, + "startPoint": { + "x": 206, + "y": 235 + }, + "endPoint": { + "x": 471, + "y": 205 + }, + "centerPoint": { + "x": 358, + "y": 340 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 2.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/ConfigTemplate.json b/info/20190410/config/ConfigTemplate.json new file mode 100644 index 0000000..a940795 --- /dev/null +++ b/info/20190410/config/ConfigTemplate.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "Remember", + "ROI": { + "x": 0, + "y": 0, + "w": 0, + "h": 0 + }, + "startPoint": { + "x": 0, + "y": 0 + }, + "endPoint": { + "x": 0, + "y": 0 + }, + "centerPoint": { + "x": 0, + "y": 0 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 0.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff1_1.json b/info/20190410/config/onoff1_1.json new file mode 100644 index 0000000..d0ebcc3 --- /dev/null +++ b/info/20190410/config/onoff1_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 428, + "y": 741, + "w": 152, + "h": 153 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff2_1.json b/info/20190410/config/onoff2_1.json new file mode 100644 index 0000000..6a85a0d --- /dev/null +++ b/info/20190410/config/onoff2_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 171, + "y": 47, + "w": 90, + "h": 90 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff3_1.json b/info/20190410/config/onoff3_1.json new file mode 100644 index 0000000..2ecdea1 --- /dev/null +++ b/info/20190410/config/onoff3_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 527, + "y": 1085, + "w": 237, + "h": 197 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff4_1.json b/info/20190410/config/onoff4_1.json new file mode 100644 index 0000000..6bfb7f2 --- /dev/null +++ b/info/20190410/config/onoff4_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 507, + "y": 662, + "w": 172, + "h": 203 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff5_1.json b/info/20190410/config/onoff5_1.json new file mode 100644 index 0000000..9a6547d --- /dev/null +++ b/info/20190410/config/onoff5_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 584, + "y": 1098, + "w": 302, + "h": 257 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff6_1.json b/info/20190410/config/onoff6_1.json new file mode 100644 index 0000000..5c63530 --- /dev/null +++ b/info/20190410/config/onoff6_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 594, + "y": 732, + "w": 287, + "h": 235 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/onoff7_1.json b/info/20190410/config/onoff7_1.json new file mode 100644 index 0000000..a348d6e --- /dev/null +++ b/info/20190410/config/onoff7_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 490, + "y": 898, + "w": 237, + "h": 164 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/temlpate7.json b/info/20190410/config/temlpate7.json new file mode 100644 index 0000000..4a85572 --- /dev/null +++ b/info/20190410/config/temlpate7.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 493, + "y": 620, + "w": 220, + "h": 130 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template1.json b/info/20190410/config/template1.json new file mode 100644 index 0000000..309754b --- /dev/null +++ b/info/20190410/config/template1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 587, + "y": 700, + "w": 183, + "h": 184 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template2.json b/info/20190410/config/template2.json new file mode 100644 index 0000000..e3da42a --- /dev/null +++ b/info/20190410/config/template2.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 261, + "y": 47, + "w": 110, + "h": 84 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template3.json b/info/20190410/config/template3.json new file mode 100644 index 0000000..917b3ad --- /dev/null +++ b/info/20190410/config/template3.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 510, + "y": 760, + "w": 230, + "h": 140 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template4.json b/info/20190410/config/template4.json new file mode 100644 index 0000000..7648871 --- /dev/null +++ b/info/20190410/config/template4.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 670, + "y": 675, + "w": 200, + "h": 140 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template5.json b/info/20190410/config/template5.json new file mode 100644 index 0000000..d63f7a8 --- /dev/null +++ b/info/20190410/config/template5.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 570, + "y": 690, + "w": 320, + "h": 173 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/config/template6.json b/info/20190410/config/template6.json new file mode 100644 index 0000000..4740cad --- /dev/null +++ b/info/20190410/config/template6.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 590, + "y": 370, + "w": 267, + "h": 156 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190410/template/1-1_1.jpg b/info/20190410/template/1-1_1.jpg new file mode 100644 index 0000000..202ebab Binary files /dev/null and b/info/20190410/template/1-1_1.jpg differ diff --git a/info/20190410/template/2-1_1.jpg b/info/20190410/template/2-1_1.jpg new file mode 100644 index 0000000..d476fb7 Binary files /dev/null and b/info/20190410/template/2-1_1.jpg differ diff --git a/info/20190410/template/3-1_1.jpg b/info/20190410/template/3-1_1.jpg new file mode 100644 index 0000000..35d6287 Binary files /dev/null and b/info/20190410/template/3-1_1.jpg differ diff --git a/info/20190410/template/3-2_1.jpg b/info/20190410/template/3-2_1.jpg new file mode 100644 index 0000000..a5b5633 Binary files /dev/null and b/info/20190410/template/3-2_1.jpg differ diff --git a/info/20190410/template/4-1_1.jpg b/info/20190410/template/4-1_1.jpg new file mode 100644 index 0000000..fc80e15 Binary files /dev/null and b/info/20190410/template/4-1_1.jpg differ diff --git a/info/20190410/template/5-1_1.jpg b/info/20190410/template/5-1_1.jpg new file mode 100644 index 0000000..98d9d1c Binary files /dev/null and b/info/20190410/template/5-1_1.jpg differ diff --git a/info/20190410/template/6-1_1.jpg b/info/20190410/template/6-1_1.jpg new file mode 100644 index 0000000..ff704f6 Binary files /dev/null and b/info/20190410/template/6-1_1.jpg differ diff --git a/info/20190410/template/onoff1_1.jpg b/info/20190410/template/onoff1_1.jpg new file mode 100755 index 0000000..3112b0f Binary files /dev/null and b/info/20190410/template/onoff1_1.jpg differ diff --git a/info/20190410/template/onoff2_1.jpg b/info/20190410/template/onoff2_1.jpg new file mode 100755 index 0000000..527a863 Binary files /dev/null and b/info/20190410/template/onoff2_1.jpg differ diff --git a/info/20190410/template/onoff3_1.jpg b/info/20190410/template/onoff3_1.jpg new file mode 100755 index 0000000..d14b0b5 Binary files /dev/null and b/info/20190410/template/onoff3_1.jpg differ diff --git a/info/20190410/template/onoff4_1.jpg b/info/20190410/template/onoff4_1.jpg new file mode 100755 index 0000000..a29c433 Binary files /dev/null and b/info/20190410/template/onoff4_1.jpg differ diff --git a/info/20190410/template/onoff5_1.jpg b/info/20190410/template/onoff5_1.jpg new file mode 100755 index 0000000..10ff269 Binary files /dev/null and b/info/20190410/template/onoff5_1.jpg differ diff --git a/info/20190410/template/onoff6_1.jpg b/info/20190410/template/onoff6_1.jpg new file mode 100755 index 0000000..1e3be5d Binary files /dev/null and b/info/20190410/template/onoff6_1.jpg differ diff --git a/info/20190410/template/onoff7_1.jpg b/info/20190410/template/onoff7_1.jpg new file mode 100755 index 0000000..bbf8a30 Binary files /dev/null and b/info/20190410/template/onoff7_1.jpg differ diff --git a/info/20190410/template/template1.jpg b/info/20190410/template/template1.jpg new file mode 100644 index 0000000..639bead Binary files /dev/null and b/info/20190410/template/template1.jpg differ diff --git a/info/20190410/template/template2.jpg b/info/20190410/template/template2.jpg new file mode 100644 index 0000000..a74d2e2 Binary files /dev/null and b/info/20190410/template/template2.jpg differ diff --git a/info/20190410/template/template3.jpg b/info/20190410/template/template3.jpg new file mode 100644 index 0000000..8ef185b Binary files /dev/null and b/info/20190410/template/template3.jpg differ diff --git a/info/20190410/template/template4.jpg b/info/20190410/template/template4.jpg new file mode 100644 index 0000000..537b165 Binary files /dev/null and b/info/20190410/template/template4.jpg differ diff --git a/info/20190410/template/template5.jpg b/info/20190410/template/template5.jpg new file mode 100644 index 0000000..683bef0 Binary files /dev/null and b/info/20190410/template/template5.jpg differ diff --git a/info/20190410/template/template6.jpg b/info/20190410/template/template6.jpg new file mode 100644 index 0000000..14d2ebc Binary files /dev/null and b/info/20190410/template/template6.jpg differ diff --git a/info/20190410/template/template7.jpg b/info/20190410/template/template7.jpg new file mode 100644 index 0000000..1d6372e Binary files /dev/null and b/info/20190410/template/template7.jpg differ diff --git a/info/20190416/config/ConfigTemplate.json b/info/20190416/config/ConfigTemplate.json new file mode 100644 index 0000000..a940795 --- /dev/null +++ b/info/20190416/config/ConfigTemplate.json @@ -0,0 +1,38 @@ +{ + "name": "null", + "type": "Remember", + "ROI": { + "x": 0, + "y": 0, + "w": 0, + "h": 0 + }, + "startPoint": { + "x": 0, + "y": 0 + }, + "endPoint": { + "x": 0, + "y": 0 + }, + "centerPoint": { + "x": 0, + "y": 0 + }, + "startPointUp": { + "x": 0, + "y": 0 + }, + "endPointUp": { + "x": 0, + "y": 0 + }, + "centerPointUp": { + "x": 0, + "y": 0 + }, + "startValue": 0.0, + "totalValue": 0.0, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff1_1.json b/info/20190416/config/onoff1_1.json new file mode 100644 index 0000000..d0ebcc3 --- /dev/null +++ b/info/20190416/config/onoff1_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 428, + "y": 741, + "w": 152, + "h": 153 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff2_1.json b/info/20190416/config/onoff2_1.json new file mode 100644 index 0000000..6a85a0d --- /dev/null +++ b/info/20190416/config/onoff2_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 171, + "y": 47, + "w": 90, + "h": 90 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff3_1.json b/info/20190416/config/onoff3_1.json new file mode 100644 index 0000000..2ecdea1 --- /dev/null +++ b/info/20190416/config/onoff3_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 527, + "y": 1085, + "w": 237, + "h": 197 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff4_1.json b/info/20190416/config/onoff4_1.json new file mode 100644 index 0000000..6bfb7f2 --- /dev/null +++ b/info/20190416/config/onoff4_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 507, + "y": 662, + "w": 172, + "h": 203 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff5_1.json b/info/20190416/config/onoff5_1.json new file mode 100644 index 0000000..9a6547d --- /dev/null +++ b/info/20190416/config/onoff5_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 584, + "y": 1098, + "w": 302, + "h": 257 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff6_1.json b/info/20190416/config/onoff6_1.json new file mode 100644 index 0000000..5c63530 --- /dev/null +++ b/info/20190416/config/onoff6_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 594, + "y": 732, + "w": 287, + "h": 235 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/onoff7_1.json b/info/20190416/config/onoff7_1.json new file mode 100644 index 0000000..a348d6e --- /dev/null +++ b/info/20190416/config/onoff7_1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "ready", + "ROI": { + "x": 490, + "y": 898, + "w": 237, + "h": 164 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/temlpate7.json b/info/20190416/config/temlpate7.json new file mode 100644 index 0000000..6c3d4ce --- /dev/null +++ b/info/20190416/config/temlpate7.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 493, + "y": 620, + "w": 220, + "h": 130 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template1.json b/info/20190416/config/template1.json new file mode 100644 index 0000000..da6e640 --- /dev/null +++ b/info/20190416/config/template1.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 587, + "y": 700, + "w": 183, + "h": 184 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template2.json b/info/20190416/config/template2.json new file mode 100644 index 0000000..4b7d97a --- /dev/null +++ b/info/20190416/config/template2.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 261, + "y": 47, + "w": 110, + "h": 84 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template3.json b/info/20190416/config/template3.json new file mode 100644 index 0000000..20cd32e --- /dev/null +++ b/info/20190416/config/template3.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 510, + "y": 760, + "w": 230, + "h": 140 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template4.json b/info/20190416/config/template4.json new file mode 100644 index 0000000..0bf2e90 --- /dev/null +++ b/info/20190416/config/template4.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 670, + "y": 675, + "w": 200, + "h": 140 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template5.json b/info/20190416/config/template5.json new file mode 100644 index 0000000..62305c4 --- /dev/null +++ b/info/20190416/config/template5.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 570, + "y": 690, + "w": 320, + "h": 173 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/config/template6.json b/info/20190416/config/template6.json new file mode 100644 index 0000000..0acf712 --- /dev/null +++ b/info/20190416/config/template6.json @@ -0,0 +1,26 @@ +{ + "name": "test", + "type": "spring", + "ROI": { + "x": 590, + "y": 370, + "w": 267, + "h": 156 + }, + "startPoint": { + "x": 23, + "y": 149 + }, + "endPoint": { + "x": 148, + "y": 35 + }, + "centerPoint": { + "x": 147, + "y": 150 + }, + "startValue": 0, + "totalValue": 12, + "digitType": "False", + "result": 0.0 +} \ No newline at end of file diff --git a/info/20190416/template/onoff1_1.jpg b/info/20190416/template/onoff1_1.jpg new file mode 100644 index 0000000..3112b0f Binary files /dev/null and b/info/20190416/template/onoff1_1.jpg differ diff --git a/info/20190416/template/onoff2_1.jpg b/info/20190416/template/onoff2_1.jpg new file mode 100644 index 0000000..527a863 Binary files /dev/null and b/info/20190416/template/onoff2_1.jpg differ diff --git a/info/20190416/template/onoff3_1.jpg b/info/20190416/template/onoff3_1.jpg new file mode 100644 index 0000000..d14b0b5 Binary files /dev/null and b/info/20190416/template/onoff3_1.jpg differ diff --git a/info/20190416/template/onoff4_1.jpg b/info/20190416/template/onoff4_1.jpg new file mode 100644 index 0000000..a29c433 Binary files /dev/null and b/info/20190416/template/onoff4_1.jpg differ diff --git a/info/20190416/template/onoff5_1.jpg b/info/20190416/template/onoff5_1.jpg new file mode 100644 index 0000000..10ff269 Binary files /dev/null and b/info/20190416/template/onoff5_1.jpg differ diff --git a/info/20190416/template/onoff6_1.jpg b/info/20190416/template/onoff6_1.jpg new file mode 100644 index 0000000..1e3be5d Binary files /dev/null and b/info/20190416/template/onoff6_1.jpg differ diff --git a/info/20190416/template/onoff7_1.jpg b/info/20190416/template/onoff7_1.jpg new file mode 100644 index 0000000..bbf8a30 Binary files /dev/null and b/info/20190416/template/onoff7_1.jpg differ diff --git a/info/20190416/template/template1.jpg b/info/20190416/template/template1.jpg new file mode 100644 index 0000000..639bead Binary files /dev/null and b/info/20190416/template/template1.jpg differ diff --git a/info/20190416/template/template2.jpg b/info/20190416/template/template2.jpg new file mode 100644 index 0000000..a74d2e2 Binary files /dev/null and b/info/20190416/template/template2.jpg differ diff --git a/info/20190416/template/template3.jpg b/info/20190416/template/template3.jpg new file mode 100644 index 0000000..8ef185b Binary files /dev/null and b/info/20190416/template/template3.jpg differ diff --git a/info/20190416/template/template4.jpg b/info/20190416/template/template4.jpg new file mode 100644 index 0000000..537b165 Binary files /dev/null and b/info/20190416/template/template4.jpg differ diff --git a/info/20190416/template/template5.jpg b/info/20190416/template/template5.jpg new file mode 100644 index 0000000..683bef0 Binary files /dev/null and b/info/20190416/template/template5.jpg differ diff --git a/info/20190416/template/template6.jpg b/info/20190416/template/template6.jpg new file mode 100644 index 0000000..14d2ebc Binary files /dev/null and b/info/20190416/template/template6.jpg differ diff --git a/info/20190416/template/template7.jpg b/info/20190416/template/template7.jpg new file mode 100644 index 0000000..1d6372e Binary files /dev/null and b/info/20190416/template/template7.jpg differ diff --git a/locator.py b/locator.py index 57bce53..ba63808 100644 --- a/locator.py +++ b/locator.py @@ -2,6 +2,7 @@ import numpy as np import math from sklearn.metrics.pairwise import pairwise_distances +from configuration import * def getPointTemplate(pointID): """ @@ -9,7 +10,7 @@ def getPointTemplate(pointID): :param pointID: ID :return: the template for location """ - return cv2.imread("template/"+pointID+".jpg") + return cv2.imread(templatePath + "/"+pointID+".jpg") # return cv2.imread("templateForLocation/"+pointID+".jpg") diff --git a/ocr_config/TEST.json b/ocr_config/TEST.json new file mode 100644 index 0000000..e18df1c --- /dev/null +++ b/ocr_config/TEST.json @@ -0,0 +1,15 @@ +{ + "rectangle": { + "width": 110, + "height": 155 + }, + "widthSplit": [ + [3,50,91] + ], + "heightSplit": [ + [47,127] + ], + "decimal":[ + 2 + ] +} \ No newline at end of file diff --git a/video_/28-1.mp4 b/video_/28-1.mp4 deleted file mode 100644 index a96c22b..0000000 Binary files a/video_/28-1.mp4 and /dev/null differ diff --git a/video_/5-1.mp4 b/video_/5-1.mp4 deleted file mode 100644 index 9739e34..0000000 Binary files a/video_/5-1.mp4 and /dev/null differ diff --git a/video_/7-1.mp4 b/video_/7-1.mp4 deleted file mode 100644 index 11cc111..0000000 Binary files a/video_/7-1.mp4 and /dev/null differ diff --git a/video_/8-1.mp4 b/video_/8-1.mp4 deleted file mode 100644 index e795e80..0000000 Binary files a/video_/8-1.mp4 and /dev/null differ