Hi guys,
I’m trying to use multi-threading to increase the speed of my program and more precisely the fps for a real-time application.
To make it simple here is how I try to make things work:
- I capture an image from the live-feed of the oboard camera (thread 1)
- I apply some treatment on this image (thread 2)
- I show the image continuously (thread 3)
Here are the 2 scripts (Thread definition and Main):
from threading import Thread, RLock
import cv2
from AphidFunction import *
lock=RLock()
class VideoShow(Thread):
def __init__(self,grabbed,frame):
Thread.__init__(self)
self.frame=frame
self.grabbed=grabbed
def run(self):
while self.grabbed == True:
with lock:
cv2.imshow('Frame',self.frame)
class VideoGet(Thread):
def __init__(self,source):
Thread.__init__(self)
self.stream=cv2.VideoCapture(source)
(self.grabbed,self.frame)=self.stream.read()
def run(self):
with lock:
(self.grabbed, self.frame)=self.stream.read()
class detection(Thread):
def __init__(self,frame):
Thread.__init__(self)
self.frame=frame
def run(self):
while True:
with lock:
hsv=image_treatment(self.frame)
img=find_aphids(hsv)
self.frame=img
And the Main:
#!/usr/bin/env python
from VideoThread import *
thread_get=VideoGet(source)
thread_get.start()
frame1=thread_get.frame
grabbed1=thread_get.grabbed
thread_detection=detection(frame1)
thread_detection.start()
thread_show=VideoShow(grabbed1,frame1)
thread_show.start()
while True:
frame = thread_get.frame
ok=thread_get.grabbed
thread_detection.frame=frame
thread_show.grabbed=ok
thread_show.frame=thread_detection.frame
Unfortunately I have this recurring error I don’t get…I don’t even use the locateROI function:
error: /home/nvidia/OpenCV3.4/opencv-3.4.0/modules/core/src/matrix.cpp:991: error: (-215) dims <= 2 && step[0] > 0 in function locateROI
Any idea ?
I also tried to put the while loop of the Main directly in the Thread script but the same error occurs.
PS: AphidsFunction is a home-made script describing image_treatment and find_aphids function. They work well.