Pārlūkot izejas kodu

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

refactoring
Atmadeep Arya pirms 3 gadiem
vecāks
revīzija
2af48ff7dd
3 mainītis faili ar 57 papildinājumiem un 36 dzēšanām
  1. +1
    -0
      config/config.py
  2. +24
    -15
      example2.py
  3. +32
    -21
      skeleton.py

+ 1
- 0
config/config.py Parādīt failu

@@ -11,6 +11,7 @@ class PARAMS(object):
_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']
_OBJECT_DETECTION_PROCESS_CORES = 2

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


+ 24
- 15
example2.py Parādīt failu

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

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

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
def run(self):
numbers = range(40)
while True:
counter = 0
while counter < 20:
num = random.choice(numbers)
inputQueue.put(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
def run(self):
while True:
while (not inputQueue.empty()):
num = inputQueue.get()
inputQueue.task_done()
print("\nGot", num)
time.sleep(.1)

class ConsumerProcess2(mp.Process):
global


if __name__ == "__main__":
print("this is example 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()
b.start()
a.join()
b.join()

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

+ 32
- 21
skeleton.py Parādīt failu

@@ -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()


Notiek ielāde…
Atcelt
Saglabāt