|
|
@@ -9,15 +9,15 @@ from queue import Queue |
|
|
|
|
|
|
|
inputQueue = mp.Queue() |
|
|
|
vehicleDetectionQueue = mp.Queue() |
|
|
|
numberPlateOcrQueue = mp.Queue() |
|
|
|
displayQueue = mp.Queue() |
|
|
|
outputQueue = mp.Queue() |
|
|
|
class ReadFrame(th.Thread): |
|
|
|
def __init__(self,source) -> None: |
|
|
|
def __init__(self,source,name='Input thread',custom_id=1) -> None: |
|
|
|
super().__init__() |
|
|
|
self.frameId = 1 |
|
|
|
self.stopped = False |
|
|
|
self.grabbed = True |
|
|
|
self.name = f'{name} {custom_id}' |
|
|
|
|
|
|
|
|
|
|
|
self.videoCaptureObject = cv2.VideoCapture(source) |
|
|
|
print(f'Reading from source = {source}') |
|
|
@@ -25,48 +25,58 @@ class ReadFrame(th.Thread): |
|
|
|
global inputQueue |
|
|
|
|
|
|
|
def run(self): |
|
|
|
while self.grabbed: |
|
|
|
while (self.grabbed): |
|
|
|
(self.grabbed, self.frame) = self.videoCaptureObject.read() |
|
|
|
inputQueue.put((self.frame,self.frameId)) |
|
|
|
print(f"IP frame added with id {self.frameId}\n") |
|
|
|
print(f"{self.name}frame added with id {self.frameId}\n") |
|
|
|
self.frameId+=1 |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
class VehicleDetection(mp.Process): |
|
|
|
def __init__(self,name='Vehicle Detection Process',custom_id=1): |
|
|
|
super(VehicleDetection,self).__init__() |
|
|
|
self.name = f'{name} {custom_id}' |
|
|
|
|
|
|
|
global inputQueue |
|
|
|
def run(self): |
|
|
|
while True: |
|
|
|
while (True): |
|
|
|
(frame,frameId) = inputQueue.get() |
|
|
|
#inputQueue.task_done() |
|
|
|
print(f"\n VD Got frame with ID {frameId}") |
|
|
|
print(f"{self.name}Got frame with ID {frameId} qsize = {inputQueue.qsize()}\n") |
|
|
|
#do some processing here. |
|
|
|
vehicleDetectionQueue.put((frame,frameId)) |
|
|
|
|
|
|
|
if(inputQueue.qsize() < 1): |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NumberPlateOcr(mp.Process): |
|
|
|
def __init__(self,name='Number plate OCR Process',custom_id=1): |
|
|
|
super(NumberPlateOcr,self).__init__() |
|
|
|
self.name=f'{name} {custom_id}' |
|
|
|
|
|
|
|
|
|
|
|
global inputQueue |
|
|
|
global numberPlateOcrQueue |
|
|
|
def run(self): |
|
|
|
while True: |
|
|
|
(frame,frameId) = vehicleDetectionQueue.get() |
|
|
|
#inputQueue.task_done() |
|
|
|
print(f"\n NP Got frame with ID {frameId}") |
|
|
|
print(f"{self.name} Got frame with ID {frameId}\n") |
|
|
|
#do some processing here. |
|
|
|
numberPlateOcrQueue.put((frame,frameId)) |
|
|
|
outputQueue.put((frame,frameId)) |
|
|
|
|
|
|
|
class DisplayFrame(mp.Process): |
|
|
|
global numberPlateOcrQueue |
|
|
|
global displayQueue |
|
|
|
class outputframe(th.Thread): |
|
|
|
def __init__(self,name='output thread',custom_id=1): |
|
|
|
super().__init__() |
|
|
|
self.name = f'{name} {custom_id}' |
|
|
|
|
|
|
|
def run(self): |
|
|
|
while True: |
|
|
|
(frame,frameId) = numberPlateOcrQueue.get() |
|
|
|
print(f'DF got frame with ID {frameId}') |
|
|
|
#display image here with frame ID |
|
|
|
outputQueue.put((frame,frameId)) |
|
|
|
(frame,frameId) = outputQueue.get() |
|
|
|
print(f'{self.name} got frame {frameId}\n') |
|
|
|
|
|
|
|
class SaveOutput(mp.Process): |
|
|
|
global displayQueue |
|
|
|
#Takes all the (frame,frameId) and then sorts them and merges them in a video using some tool. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -92,6 +102,7 @@ if __name__ == '__main__': |
|
|
|
numberPlateOcrProcess.start() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#disable profiler here. |
|
|
|
app_profiler.disable() |
|
|
|
|
|
|
|