Skip to content

Commit

Permalink
Merge pull request #1 from szkszk95/master
Browse files Browse the repository at this point in the history
修改了一些w和h
  • Loading branch information
hjptriplebee authored Dec 7, 2018
2 parents 7187b13 + 01bcd66 commit 22ea8d7
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def meterFinderByTemplate(image, template):
topLeft = minLoc
else:
topLeft = maxLoc
bottomRight = (topLeft[0] + w, topLeft[1] + h)
bottomRight = (topLeft[0] + h, topLeft[1] + w)

return image[topLeft[1]:bottomRight[1], topLeft[0]:bottomRight[0]]
12 changes: 8 additions & 4 deletions Interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import cv2
import json
from SF6 import SF6
from youwen import youwen


def meterReaderCallBack(image, info):
"""call back function"""
Expand Down Expand Up @@ -44,6 +46,8 @@ def getInfo(ID):
# string to pointer
if info["type"] == "SF6":
info["type"] = SF6
elif info["type"] == "youwen":
info["type"] = youwen
info["template"] = cv2.imread("template/" + ID + ".jpg")
return info

Expand All @@ -64,13 +68,13 @@ def meterReader(image, meterIDs):
y = info["ROI"]["y"]
w = info["ROI"]["w"]
h = info["ROI"]["h"]
ROI = image[x:x + h, y:y + w]
ROI = image[y:y + h, x:x + w]
# call back
results[ID] = meterReaderCallBack(ROI, info)
return results


image = cv2.imread("image/2018-11-20-16-22-02.jpg")

print(meterReader(image, ["1_1"]))
# image = cv2.imread("image/2018-11-20-16-22-02.jpg")
image = cv2.imread("image/youwen_1.jpg")
print(meterReader(image, ["youwen_1"]))

2 changes: 1 addition & 1 deletion SF6.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def SF6(image, info):
cv2.imshow("meter", meter)
cv2.waitKey(0)

return 1
return 1
27 changes: 27 additions & 0 deletions config/youwen_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"distance": 10.0,
"horizontal": 10.0,
"vertical": 20.0,
"name": "youwen_1",
"type": "youwen",
"ROI": {
"x": 450,
"y":300,
"w": 800,
"h": 600
},
"startPoint": {
"x": 27,
"y": 70
},
"endPoint": {
"x": 62,
"y": 68
},
"centerPoint": {
"x": 43,
"y": 55
},
"startValue": 0.0,
"totalValue": 100.0
}
Binary file added image/youwen_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 image/youwen_2.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/youwen_3.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 template/youwen_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions youwen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from Common import *


def youwen(image, info):
"""
:param image: ROI image
:param info: information for this meter
:return: value
"""
# your method
print("YouWen Reader called!!!")
# template match
print(info["template"])
cv2.imshow("image", image)
cv2.waitKey(0)
meter = meterFinderByTemplate(image, info["template"])
cv2.imshow("meter", meter)
cv2.waitKey(0)

return 1

0 comments on commit 22ea8d7

Please # to comment.