diff --git a/Interface.py b/Interface.py index a4055e1..e54a998 100644 --- a/Interface.py +++ b/Interface.py @@ -15,12 +15,14 @@ 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 configuration import * @@ -86,8 +88,8 @@ def getInfo(ID): info["type"] = oilTempreture elif info["type"] == "blenometer": info["type"] = checkBleno - elif info["type"] == "onoffIndoor": - info["type"] = onoffIndoor + elif info["type"] == "contactStatus": + info["type"] = contactStatus elif info["type"] == "onoffOutdoor": info["type"] = onoffOutdoor elif info["type"] == "onoffBattery": diff --git a/algorithm/onoff/contactStatus.py b/algorithm/onoff/contactStatus.py new file mode 100644 index 0000000..bf2d100 --- /dev/null +++ b/algorithm/onoff/contactStatus.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Apr 16 19:32:29 2019 +@author: sun +""" +import cv2 +import numpy as np +import math +import json +from algorithm.Common import meterFinderBySIFT, meterFinderByTemplate +## +# 获取图像的灰度矩阵 +def getMatrix(img): + gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + return gray_img + + +# 实现图像的卷积操作 +def imgConvoluting(image, filter): + w, h = filter.shape + con_img = image.copy() + filter_w, filter_h = filter.shape + for i in range(1, len(image) + 1 - w): + for j in range(1, len(image[i]) + 1 - h): + con_img[i][j] = (image[i:i + filter_w:, j:j + filter_h:] * filter).sum() + + return con_img + + +# 使用二阶微分实现检测,实现图像的锐化 +def imgEnhance(image, c): + raw_img = image.copy() + res_img = image.copy() + + image = cv2.GaussianBlur(image, (17, 17), 1) + + filter = np.array([[0, 1, 0], [1, -4, 1], [0, 1, 0]]) + + filter_img = imgConvoluting(image, filter) + + for i in range(len(image)): + for j in range(len(image[i])): + res_img[i][j] = raw_img[i][j] + c * filter_img[i][j] + + return res_img + + +# 读取图像数据到矩阵 +def readImg(filepath): + if filepath == "": + return None + + img = cv2.imread(filepath) + return img + + +def hasCircle(img): + ''' + :param img: 二值图,图像边缘信息 + :return: + ''' + + circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 50, param1=80, param2=30, minRadius=10, maxRadius=40) + + if circles is None: + return False + + return True + +def contactStatus(image, info): + """ + :param image:whole image + :param info:开关配置 + :return: True代表O,False代表1 + """ + debug=False + if debug: + cv2.imshow("image", image) + cv2.imshow("template",info['template']) + cv2.waitKey(0) + + + #image = meterFinderBySIFT(image, info) + image = meterFinderByTemplate(image, info['template']) + #获取图像灰度矩阵 + image = getMatrix(image) + #边缘检测 + image = cv2.Canny(image, 10, 200) + + return hasCircle(image) +# if __name__ == "__main__": +# # img = readImg("./case/case1.png") +# #img = getMatrix("../images/meterReader/contact1_1.png") +# img = cv2.imread("../../info/20190410/template/contact1_1.png") +# +# # 图像边缘增强 +# #img = imgEnhance(img, 1) +# #cv2.imshow("img", img) +# # 边缘检测 +# +# # ret,th = cv2.threshold(img,10,255,cv2.THRESH_BINARY) +# # ret,th = cv2.threshold(img,100,255,cv2.THRESH_BINARY) #case1与case3均适用 +# +# # print(img) +# +# +# # Otsu 滤波 +# # ret2,th2 = cv2.threshold(img,0,100,cv2.THRESH_BINARY+cv2.THRESH_OTSU) +# +# # cv2.imwrite("gass.png", img) +# # cv2.waitKey(0) +# # cv2.destroyWindow() \ No newline at end of file diff --git a/image/contact1.jpg b/image/contact1.jpg new file mode 100644 index 0000000..04303b4 Binary files /dev/null and b/image/contact1.jpg differ diff --git a/image/contact2.png b/image/contact2.png new file mode 100644 index 0000000..3f0abb2 Binary files /dev/null and b/image/contact2.png differ diff --git a/image/contact3.jpg b/image/contact3.jpg new file mode 100644 index 0000000..8632ffe Binary files /dev/null and b/image/contact3.jpg differ diff --git a/image/contact4.jpg b/image/contact4.jpg new file mode 100644 index 0000000..fad5aae Binary files /dev/null and b/image/contact4.jpg differ diff --git a/image/contact5.jpg b/image/contact5.jpg new file mode 100644 index 0000000..2ab7a4c Binary files /dev/null and b/image/contact5.jpg differ diff --git a/image/contact6.jpg b/image/contact6.jpg new file mode 100644 index 0000000..feebf27 Binary files /dev/null and b/image/contact6.jpg differ diff --git a/image/contact7.jpg b/image/contact7.jpg new file mode 100644 index 0000000..25e9618 Binary files /dev/null and b/image/contact7.jpg differ diff --git a/info/20190410/config/contact1_1.json b/info/20190410/config/contact1_1.json new file mode 100644 index 0000000..1e10c04 --- /dev/null +++ b/info/20190410/config/contact1_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 255, + "y": 741, + "w": 194, + "h": 151 + }, + "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/contact2_1.json b/info/20190410/config/contact2_1.json new file mode 100644 index 0000000..255a094 --- /dev/null +++ b/info/20190410/config/contact2_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 58, + "y": 41, + "w": 115, + "h": 70 + }, + "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/contact3_1.json b/info/20190410/config/contact3_1.json new file mode 100644 index 0000000..65d71da --- /dev/null +++ b/info/20190410/config/contact3_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 241, + "y": 754, + "w": 253, + "h": 141 + }, + "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/contact4_1.json b/info/20190410/config/contact4_1.json new file mode 100644 index 0000000..f51464b --- /dev/null +++ b/info/20190410/config/contact4_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 303, + "y": 685, + "w": 202, + "h": 128 + }, + "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/contact5_1.json b/info/20190410/config/contact5_1.json new file mode 100644 index 0000000..93a0d83 --- /dev/null +++ b/info/20190410/config/contact5_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 195, + "y": 676, + "w": 337, + "h": 185 + }, + "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/contact6_1.json b/info/20190410/config/contact6_1.json new file mode 100644 index 0000000..a45b1a0 --- /dev/null +++ b/info/20190410/config/contact6_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 272, + "y": 377, + "w": 297, + "h": 170 + }, + "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/contact7_1.json b/info/20190410/config/contact7_1.json new file mode 100644 index 0000000..7b2d250 --- /dev/null +++ b/info/20190410/config/contact7_1.json @@ -0,0 +1,27 @@ +{ + "name": "test", + "type": "contactStatus", + "ROI": { + "x": 254, + "y": 617, + "w": 219, + "h": 123 + }, + "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/contact1_1.jpg b/info/20190410/template/contact1_1.jpg new file mode 100644 index 0000000..0d028ab Binary files /dev/null and b/info/20190410/template/contact1_1.jpg differ diff --git a/info/20190410/template/contact2_1.jpg b/info/20190410/template/contact2_1.jpg new file mode 100644 index 0000000..027ddde Binary files /dev/null and b/info/20190410/template/contact2_1.jpg differ diff --git a/info/20190410/template/contact3_1.jpg b/info/20190410/template/contact3_1.jpg new file mode 100644 index 0000000..74f269f Binary files /dev/null and b/info/20190410/template/contact3_1.jpg differ diff --git a/info/20190410/template/contact4_1.jpg b/info/20190410/template/contact4_1.jpg new file mode 100644 index 0000000..398895d Binary files /dev/null and b/info/20190410/template/contact4_1.jpg differ diff --git a/info/20190410/template/contact5_1.jpg b/info/20190410/template/contact5_1.jpg new file mode 100644 index 0000000..017c79a Binary files /dev/null and b/info/20190410/template/contact5_1.jpg differ diff --git a/info/20190410/template/contact6_1.jpg b/info/20190410/template/contact6_1.jpg new file mode 100644 index 0000000..7995f4e Binary files /dev/null and b/info/20190410/template/contact6_1.jpg differ diff --git a/info/20190410/template/contact7_1.jpg b/info/20190410/template/contact7_1.jpg new file mode 100644 index 0000000..6dd2eef Binary files /dev/null and b/info/20190410/template/contact7_1.jpg differ