Skip to content

Commit

Permalink
Merge pull request #7 from hjptriplebee/master
Browse files Browse the repository at this point in the history
video interface
  • Loading branch information
buyi1128 authored Jan 21, 2019
2 parents 65723a3 + 0014768 commit 65c8045
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
17 changes: 12 additions & 5 deletions FlaskService.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ def meterReaderAPI():

meterIDs = getMeterIDs(imageID)

imageByte = data["image"].encode("ascii")
imageByte = base64.b64decode(imageByte)
imageArray = np.asarray(bytearray(imageByte), dtype="uint8")
image = cv2.imdecode(imageArray, cv2.IMREAD_COLOR)
# imageByte = data["image"].encode("ascii")
# imageByte = base64.b64decode(imageByte)
# imageArray = np.asarray(bytearray(imageByte), dtype="uint8")
# image = cv2.imdecode(imageArray, cv2.IMREAD_COLOR)

path = data["path"]

if path[-4] != ".jpg":
recognitionData = cv2.VideoCapture(path)
else:
recognitionData = cv2.imread(path)

result = meterReader(image, meterIDs)
result = meterReader(recognitionData, meterIDs)
sendData = json.dumps(result).encode("utf-8")

return sendData
Expand Down
26 changes: 16 additions & 10 deletions Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from algorithm.SF6 import SF6Reader
from algorithm.oilTempreture import oilTempreture
from algorithm.highlightDigitMeter import highlightDigit
from algorithm.videoDigit import videoDigit


from algorithm.arrest.countArrester import countArrester
Expand Down Expand Up @@ -99,6 +100,8 @@ def getInfo(ID):
info["type"] = highlightDigit
elif info["type"] == "onoffBattery":
info["type"] = onoffBattery
elif info["type"] == "videoDigit":
info["type"] = videoDigit
else:
info["type"] = None
info["template"] = cv2.imread("template/" + ID + ".jpg")
Expand All @@ -107,23 +110,26 @@ def getInfo(ID):
return info


def meterReader(image, meterIDs):
def meterReader(recognitionData, meterIDs):
"""
global interface
:param image: camera image
:param recognitionData: image or video
:param meterIDs: list of meter ID
:return:
"""
results = {}
for ID in meterIDs:
# get info from file
info = getInfo(ID)
# ROI extract
x = info["ROI"]["x"]
y = info["ROI"]["y"]
w = info["ROI"]["w"]
h = info["ROI"]["h"]
ROI = image[y:y + h, x:x + w]
# call back
results[ID] = meterReaderCallBack(ROI, info)
if info["digitType"] == "VIDEO":
results[ID] = meterReaderCallBack(recognitionData, info)
else:
# ROI extract
x = info["ROI"]["x"]
y = info["ROI"]["y"]
w = info["ROI"]["w"]
h = info["ROI"]["h"]
ROI = recognitionData[y:y + h, x:x + w]
# call back
results[ID] = meterReaderCallBack(ROI, info)
return results
7 changes: 7 additions & 0 deletions algorithm/videoDigit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

def videoDigit(video, info):
"""
:param video: video
:param info: info
:return:
"""

0 comments on commit 65c8045

Please # to comment.