Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merge pull request #1 from hjptriplebee/master #76

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *


Expand Down Expand Up @@ -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":
Expand Down
112 changes: 112 additions & 0 deletions algorithm/onoff/contactStatus.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added image/contact1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/contact7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions info/20190410/config/contact1_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact2_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact3_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact4_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact5_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact6_1.json
Original file line number Diff line number Diff line change
@@ -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

}
27 changes: 27 additions & 0 deletions info/20190410/config/contact7_1.json
Original file line number Diff line number Diff line change
@@ -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

}
Binary file added info/20190410/template/contact1_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact2_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact3_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact4_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact5_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact6_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added info/20190410/template/contact7_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.