I have two cameras and this is important to read the frames with OpenCV
exactly at the same time, I thought something like Lock
but I cannot figure out the way I can implement this.
I need some trigger to push and enable the threads to read frames, and then wait for another trigger hit, something like below :
def get_frame(queue, cap):
while running:
if(read_frame):
queue.put(cap.read());
else:
# without this sleep this function just consumes unnecessary CPU time
time.sleep(some_time);
q = Queue.Queue()
# for every camera
for u in xrange(2):
t = threading.Thread(target=get_frame, args = (q, caps[u]))
t.daemon = True
t.start()
The problems with the above implementation are :
- I need the sleep time to be defined since I don't know the
delay
in between every frame read (i.e. it might be long or short, depending on the calculation) - This does not enable me to read once for every trigger hit.
So this approach won't work, Any suggestions?