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

黄色指示器 #91

Open
wants to merge 3 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
8 changes: 0 additions & 8 deletions Algorithm/Remember.py

This file was deleted.

19 changes: 19 additions & 0 deletions Algorithm/others/colorIndicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cv2
import numpy as np

from Algorithm.utils.Finder import meterFinderByTemplate, meterFinderBySIFT

def colorIndicator(ROI, info):
res = False
image = meterFinderBySIFT(ROI, info)
HSV = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# color = [np.array([26, 43, 46]), np.array([34, 255, 255])]
color = [np.array([11, 43, 46]), np.array([34, 255, 255])]
Lower = color[0]
Upper = color[1]
mask = cv2.inRange(HSV, Lower, Upper)
upmask = mask[int(0.25*mask.shape[0]):int(0.5*mask.shape[0]), :]
upmask = cv2.bitwise_and(np.ones(upmask.shape, np.uint8), upmask)
if np.sum(upmask) / upmask.shape[0]*upmask.shape[1] > 0.2:
res = True
return res
74 changes: 60 additions & 14 deletions Algorithm/pressure/digitPressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


def digitPressure(image, info):
# cv2.imshow("img ", image)
# cv2.waitKey(0)
template = meterFinderBySIFT(image, info)

# 存储图片
Expand All @@ -27,6 +29,7 @@ def digitPressure(image, info):
try:
os.mkdir("storeDigitData/thresh/" + str(i))
os.mkdir("storeDigitData/rgb/" + str(i))
savePicture(template, info)
except IOError:
continue

Expand Down Expand Up @@ -60,7 +63,6 @@ def rgbRecognize(template, info):
# 网络初始化
MyNet = newNet(if_rgb=True)
myRes = []
imgNum = int((len(os.listdir("storeDigitData/")) - 1) / 3)
for i in range(len(heightSplit)):
split = widthSplit[i]
myNum = ""
Expand All @@ -73,9 +75,6 @@ def rgbRecognize(template, info):
num = MyNet.recognizeNet(img)
myNum = myNum + num

# 存储图片
cv2.imwrite("storeDigitData/rgb/{}/{}_{}{}_p{}.bmp".format(
num, imgNum, i, j, num), img)
myRes.append(myNum)

if ifShow:
Expand Down Expand Up @@ -105,6 +104,62 @@ def bitRecognize(template, info):
# 灰度图
gray = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)

# 针对不同的数字表类型进行不同的增强
if info["digitType"] != "TTC":
Blur = cv2.GaussianBlur(gray, (5, 5), 0)
Hist = cv2.equalizeHist(Blur)
thresh = cv2.adaptiveThreshold(Hist, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 15, 11)
else:
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, block, param)
if ifOpen == "close":
p = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, p)

# 网络初始化
MyNet = newNet(if_rgb=False)
myRes = []

for i in range(len(heightSplit)):
split = widthSplit[i]
myNum = ""
for j in range(len(split) - 1):
if "decimal" in info.keys() and j == info["decimal"][i]:
myNum += "."
continue
# 得到分割的图片区域
img = thresh[heightSplit[i][0]:heightSplit[i][1], split[j]:split[j + 1]]
rgb_ = dst[heightSplit[i][0]:heightSplit[i][1], split[j]:split[j + 1]]
num = MyNet.recognizeNet(img)
myNum = myNum + num

myRes.append(myNum)

if ifShow:
cv2.imshow("rec", dst)
cv2.imshow("template", template)
print(myRes)
cv2.waitKey(0)
cv2.destroyAllWindows()
return myRes

def savePicture(template, info):
template = cv2.GaussianBlur(template, (3, 3), 0)

# 读取标定信息
widthSplit = info["widthSplit"]
heightSplit = info["heightSplit"]

# 将info中的参数加入代码中
block = info["thresh"]["block"]
param = info["thresh"]["param"]
ifOpen = info["ifopen"]

# 由标定点得到液晶区域
dst = boxRectifier(template, info)

# 灰度图
gray = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)

# 针对不同的数字表类型进行不同的增强
if info["digitType"] != "TTC":
Blur = cv2.GaussianBlur(gray, (5, 5), 0)
Expand All @@ -124,7 +179,7 @@ def bitRecognize(template, info):

# 网络初始化
MyNet = newNet(if_rgb=False)
myRes = []

imgNum = int((len(os.listdir("storeDigitData/")) - 1) / 3)

for i in range(len(heightSplit)):
Expand All @@ -137,7 +192,6 @@ def bitRecognize(template, info):
# 得到分割的图片区域
img = thresh[heightSplit[i][0]:heightSplit[i][1], split[j]:split[j + 1]]
rgb_ = dst[heightSplit[i][0]:heightSplit[i][1], split[j]:split[j + 1]]

num = MyNet.recognizeNet(img)
myNum = myNum + num

Expand All @@ -146,12 +200,4 @@ def bitRecognize(template, info):
num, imgNum, i, j, num), img)
cv2.imwrite("storeDigitData/rgb/{}/{}_{}{}_p{}.bmp".format(
num, imgNum, i, j, num), rgb_)
myRes.append(myNum)

if ifShow:
cv2.imshow("rec", dst)
cv2.imshow("template", template)
print(myRes)
cv2.waitKey(0)
cv2.destroyAllWindows()
return myRes
30 changes: 10 additions & 20 deletions Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
from Algorithm.pressure.normalPressure import normalPressure
from Algorithm.pressure.colorPressure import colorPressure


from Algorithm.onoff.contactStatus import contactStatus
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.contactStatus import contactStatus

from Algorithm.others.colordetect import colordetect
from Algorithm.others.Cabinet_indicator import indicatorimg
from Algorithm.others.Knob_status import knobstatus
from Algorithm.others.colorIndicator import colorIndicator

from configuration import *

Expand Down Expand Up @@ -78,7 +77,7 @@ def getInfo(ID):
info["type"] = digitPressure
elif info["type"] == "normalPressure":
info["type"] = normalPressure
elif info["type"] == "contact":
elif info["type"] == "contactStatus":
info["type"] = contactStatus
elif info["type"] == "colorPressure":
info["type"] = colorPressure
Expand All @@ -100,19 +99,14 @@ def getInfo(ID):
info["type"] = onoffBattery
elif info["type"] == "videoDigit":
info["type"] = videoDigit
elif info["type"] == "ready":
elif info["type"] == "readyStatus":
info["type"] = readyStatus
elif info["type"] == "spring":
elif info["type"] == "springStatus":
info["type"] = springStatus
elif info["type"] == "colordetect":
info["type"] = colordetect
elif info["type"] == "cabinetindicator":
info["type"] = indicatorimg
elif info["type"] == "Knob":
info["type"] = knobstatus
elif info["type"] == "colorIndicator":
info["type"] = colorIndicator
else:
info["type"] = None

info["template"] = cv2.imread(templatePath + "/" + ID + ".jpg")
if info["digitType"] != "False":
info.update(json.load(open(os.path.join("ocr_config", info["digitType"] + ".json"))))
Expand Down Expand Up @@ -145,11 +139,7 @@ def meterReader(recognitionData, meterIDs):
# cv2.waitKey(0)
if x != 0 or y != 0 or w != 0 or h != 0:
ROI = recognitionData[y:y + h, x:x + w]
else:
ROI = recognitionData
try:
results.append(meterReaderCallBack(ROI, info))
except AttributeError:
print("Error in ", ID)
results = [0]
else:
results.append(meterReaderCallBack(recognitionData, info))
return results
17 changes: 12 additions & 5 deletions TestServiceSample.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,29 @@ def startClient(results):

def codecov(imgPath):
images = os.listdir(imgPath)
config = os.listdir(configPath)

for im in images:
if im.startswith(".DS"):
continue
image = cv2.imread(imgPath + "/" + im)
print(im)
pos = im.split(".")[0].split("-")
cfg = im.split(".")[0]+"_1"
cfg = "rcs0_1" # im.split(".")[0]+"_1"
# for i in range(1, 6):
# cfg = pos[0] + "-" + pos[1] + "_" + str(i)
# if cfg + ".json" in config:
# receive2 = meterReader(image, [cfg])
# print(cfg, receive2)
if image.shape[0] > 600:
shrink = image.shape[0] / 600
image = cv2.resize(image, (0, 0), fx=1 / shrink, fy=1 / shrink)
print("image shrink: ", image.shape)
receive2 = meterReader(image, [cfg])
print(cfg, receive2)
print("codecov done")


def testVideo():
def videoTest():
video_path = "info/20190128/IMAGES/video_"
for file in os.listdir(video_path):
if file.startswith(".DS"):
Expand Down Expand Up @@ -83,8 +88,10 @@ def testVideo():

# codecov("info/20190410/IMAGES/Pic")
# codecov("info/20190410/IMAGES/Pic_2")
codecov("info/20190515/IMAGES/image")
# codecov("info/20190514/image/")

# codecov("info/20190523/image/")
codecov("info/split/image/")

#
# codecov("info/20190416/IMAGES/image")

Expand Down
2 changes: 1 addition & 1 deletion ocr_config/KWH.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"widthSplit": [
[19,37,56,77,95,96],
[19,37,56,77,95,96]
[19,37,56,77,78,96]
],
"heightSplit": [
[28,49],
Expand Down