Browse Source

skeleton works with return in vehicleDetection process class 's run() method

refactoring
Atmadeep Arya 3 years ago
parent
commit
2af48ff7dd
3 changed files with 57 additions and 36 deletions
  1. +1
    -0
      config/config.py
  2. +24
    -15
      example2.py
  3. +32
    -21
      skeleton.py

+ 1
- 0
config/config.py View File

@@ -11,6 +11,7 @@ class PARAMS(object):
_YOLOV3_OD_INPUT_IMAGE_SIZE = (416,416) #(Width, Height) _YOLOV3_OD_INPUT_IMAGE_SIZE = (416,416) #(Width, Height)
#_YOLOV3_OD_NUMBER_PLATE_OBJECT_LIST = ['car','bus','truck','motorbike'] #_YOLOV3_OD_NUMBER_PLATE_OBJECT_LIST = ['car','bus','truck','motorbike']
_YOLOV3_OD_NUMBER_PLATE_OBJECT_LIST = ['car'] _YOLOV3_OD_NUMBER_PLATE_OBJECT_LIST = ['car']
_OBJECT_DETECTION_PROCESS_CORES = 2


# Number Plate Detection # Number Plate Detection
_YOLOV3_NP_WEIGHT = os.path.join(_CMD_PMT_,'resources/trainedModels/yolov3_number_plate_detection/lapi.weights') _YOLOV3_NP_WEIGHT = os.path.join(_CMD_PMT_,'resources/trainedModels/yolov3_number_plate_detection/lapi.weights')


+ 24
- 15
example2.py View File

@@ -4,41 +4,50 @@ import time
import random import random
from queue import Queue from queue import Queue


inputQueue = mp.Queue(10)
inputQueue = mp.JoinableQueue()
inputQueue2 = mp.Queue(10) inputQueue2 = mp.Queue(10)


class ProducerThread(Thread): class ProducerThread(Thread):
def __init__(self,name='',custom_id,daemon=False):
super(ProducerThread, self).__init__()
self.name = "{}-{}".format(name,custom_id)
self.setDaemon(daemon)
global inputQueue global inputQueue
def run(self): def run(self):
numbers = range(40) numbers = range(40)
while True:
counter = 0
while counter < 20:
num = random.choice(numbers) num = random.choice(numbers)
inputQueue.put(num) inputQueue.put(num)
print("\nPut",num) print("\nPut",num)
time.sleep(.05)
time.sleep(.08)
counter+=1

class ConsumerProcess1(Thread):
def __init__(self,name,custom_id,daemon=False):
super(ConsumerProcess1,self).__init__()
self.name = "{}-{}".format(name,custom_id)
self.daemon = daemon


class ConsumerProcess1(mp.Process):
global inputQueue global inputQueue
def run(self): def run(self):
while True:
while (not inputQueue.empty()):
num = inputQueue.get() num = inputQueue.get()
inputQueue.task_done()
print("\nGot", num) print("\nGot", num)
time.sleep(.1) time.sleep(.1)

class ConsumerProcess2(mp.Process):
global



if __name__ == "__main__": if __name__ == "__main__":
print("this is example 2") print("this is example 2")
time.sleep(2) time.sleep(2)
a=ProducerThread()
b=ConsumerProcess1()
a=ProducerThread(name = 'producer thread',custom_id=1,daemon=False)
b=ConsumerProcess1(name = 'consumer process',custom_id=1,daemon=True)
a.start() a.start()
b.start() b.start()
a.join()
b.join()


print(a.ident,a.name,"\n")
print(b.ident,b.name,"\n")

+ 32
- 21
skeleton.py View File

@@ -9,15 +9,15 @@ from queue import Queue


inputQueue = mp.Queue() inputQueue = mp.Queue()
vehicleDetectionQueue = mp.Queue() vehicleDetectionQueue = mp.Queue()
numberPlateOcrQueue = mp.Queue()
displayQueue = mp.Queue()
outputQueue = mp.Queue() outputQueue = mp.Queue()
class ReadFrame(th.Thread): class ReadFrame(th.Thread):
def __init__(self,source) -> None:
def __init__(self,source,name='Input thread',custom_id=1) -> None:
super().__init__() super().__init__()
self.frameId = 1 self.frameId = 1
self.stopped = False self.stopped = False
self.grabbed = True self.grabbed = True
self.name = f'{name} {custom_id}'


self.videoCaptureObject = cv2.VideoCapture(source) self.videoCaptureObject = cv2.VideoCapture(source)
print(f'Reading from source = {source}') print(f'Reading from source = {source}')
@@ -25,48 +25,58 @@ class ReadFrame(th.Thread):
global inputQueue global inputQueue
def run(self): def run(self):
while self.grabbed:
while (self.grabbed):
(self.grabbed, self.frame) = self.videoCaptureObject.read() (self.grabbed, self.frame) = self.videoCaptureObject.read()
inputQueue.put((self.frame,self.frameId)) 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 self.frameId+=1
return


class VehicleDetection(mp.Process): 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 global inputQueue
def run(self): def run(self):
while True:
while (True):
(frame,frameId) = inputQueue.get() (frame,frameId) = inputQueue.get()
#inputQueue.task_done() #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. #do some processing here.
vehicleDetectionQueue.put((frame,frameId)) vehicleDetectionQueue.put((frame,frameId))

if(inputQueue.qsize() < 1):
return
class NumberPlateOcr(mp.Process): 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 inputQueue
global numberPlateOcrQueue global numberPlateOcrQueue
def run(self): def run(self):
while True: while True:
(frame,frameId) = vehicleDetectionQueue.get() (frame,frameId) = vehicleDetectionQueue.get()
#inputQueue.task_done() #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. #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): def run(self):
while True: 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() numberPlateOcrProcess.start()

#disable profiler here. #disable profiler here.
app_profiler.disable() app_profiler.disable()


Loading…
Cancel
Save