From 2a0d2b310492fdcaa4c1d0e7de5d38e60a251400 Mon Sep 17 00:00:00 2001 From: Ziad Muhammed Date: Wed, 21 Sep 2022 16:35:57 +0200 Subject: [PATCH] feat: integrate with streaming --- main.py | 78 ++++++++++++++++++++++++++--------------------- testing/webcam.py | 24 +++++++++------ 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 58d8cb6..131c529 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import glob import imp import os @@ -20,7 +21,7 @@ import sys path = './outputs/' -url = "http://192.168.1.103:8080/video" +url = "http://192.168.98.146:8080/video" sys.path.insert(0, './localisation') import detect as detect # from segmentation.seg import Segmentation @@ -46,40 +47,47 @@ def printChars(chars, count): # Main which responsible for integration of whole image processing pipelines if __name__ == '__main__': - try: - countPlate = 1 - # stream(url) - - # localization - detect.crop_multiple("./localisation/data/demo")[0] - - for filename in os.scandir("./detections/"): - try: - # segmentation - _, chars = segmentChars(filename.path) - - # print chars segmented - printChars(chars, countPlate) - - # recognition - predicted_chars = classify_unlabelled_directory(f'{path}{countPlate}/') - - # print string - lp = predictChars(predicted_chars) - print(lp) - - os.rmdir(f'./outputs/{countPlate}') - countPlate += 1 - - # send string to middle-ware - endPoint(lp) - - except Exception: - # print("error") - continue - - except SystemExit: - pass + while True: + try: + countPlate = 1 + # stream(url) + + # localization + detect.crop_multiple("./localisation/data/demo/")[0] + + for filename in os.scandir("./detections/"): + try: + # segmentation + _, chars = segmentChars(filename.path) + + # print chars segmented + printChars(chars, countPlate) + + # recognition + predicted_chars = classify_unlabelled_directory(f'{path}{countPlate}/') + + # print string + lp = predictChars(predicted_chars) + print(lp) + + # countPlate += 1 + + # send string to middle-ware + # endPoint(lp) + # files = glob.glob('./detections/*') + # for file in files: + # os.remove(file) + # files = glob.glob('./outputs/*') + # for file in files: + # os.remove(file) + + except Exception: + # print("error") + continue + + except Exception: + print("outer error") + continue # segObject = Segmentation(filename.path) # chars = segObject.run() diff --git a/testing/webcam.py b/testing/webcam.py index e496026..625908c 100644 --- a/testing/webcam.py +++ b/testing/webcam.py @@ -1,12 +1,18 @@ +import glob + import cv2 as cv +import os -path = '../outputs/' +path = './localisation/data/images/1.png' -def stream(): - link = "http://192.168.1.103:8080/video" +def stream(link): # link of streaming + # link = "http://9.246.91.33:8080/video" capture = cv.VideoCapture(link) + files = glob.glob('./localisation/data/images/*') + for file in files: + os.remove(file) while True: _, frame = capture.read() @@ -15,16 +21,16 @@ def stream(): # take photo from streaming if cv.waitKey(1) == ord("q"): - cv.imwrite(f'{path}1.png', frame) - continue - - # exit streaming - if cv.waitKey(1) == ord('z'): + cv.imwrite(path, frame) break + # # exit streaming + # if cv.waitKey(1) == ord('z'): + # break + # destroy streaming capture.release() cv.destroyAllWindows() -#ds +# ds # stream()