-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to synchronize between two cameras? #1
Comments
Hello @kevinkit,
Yes, this is absolutely possible. Try something like this: # import required libraries
from vidgear.gears import VideoGear
import cv2
import time
# define and start the stream on first source ( For e.g #0 index device)
stream1 = VideoGear(source=0, logging=True).start()
# define and start the stream on second source ( For e.g #1 index device)
stream2 = VideoGear(source=1, logging=True).start()
# infinite loop
while True:
frameA = stream1.read()
# read frames from stream1
frameB = stream2.read()
# read frames from stream2
# check if any of two frame is None
if frameA is None or frameB is None:
#if True break the infinite loop
break
# do something with both frameA and frameB here
cv2.imshow("Output Frame1", frameA)
cv2.imshow("Output Frame2", frameB)
# Show output window of stream1 and stream 2 seperately
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
if key == ord("w"):
#if 'w' key-pressed save both frameA and frameB at same time
cv2.imwrite("Image-1.jpg", frameA)
cv2.imwrite("Image-2.jpg", frameB)
#break #uncomment this line to break out after taking images
cv2.destroyAllWindows()
# close output window
# safely close both video streams
stream1.stop()
stream2.stop() Remember both streams and corresponding frames will be processed in the above example synchronously i.e. with no delay. To confirm this you can use a video file and its copy as different sources in above two streams and see if both streams play at the same time in the output windows. Kindly Test this example code and revert if you experience any difficulty. |
Closed. If you experience any problems, feel free to reopen it. |
Thank you and sorry for the late reply, I will test it as soon as I am having a dual camera setup again! |
Thank you for that great repository.
Is it possible to have two cameras taking images synchronized to each other? Or will there be an offset due to the multithreading nature?
The text was updated successfully, but these errors were encountered: