Skip to content
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

Closed
kevinkit opened this issue Mar 18, 2019 · 4 comments
Closed

How to synchronize between two cameras? #1

kevinkit opened this issue Mar 18, 2019 · 4 comments
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!

Comments

@kevinkit
Copy link

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?

@abhiTronix abhiTronix added EXEMPLARY 🎖️ Exemplary for newcomers QUESTION ❓ User asked about the working/usage of VidGear APIs. labels Mar 18, 2019
@abhiTronix
Copy link
Owner

abhiTronix commented Mar 18, 2019

Hello @kevinkit,

Is it possible to have two cameras taking images synchronized to each other?

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.

@abhiTronix abhiTronix added the WAITING TO TEST ⏲️ Asked user to test the suggested example/binary/solution label Mar 18, 2019
@abhiTronix
Copy link
Owner

Closed. If you experience any problems, feel free to reopen it.

@abhiTronix abhiTronix added SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! and removed EXEMPLARY 🎖️ Exemplary for newcomers WAITING TO TEST ⏲️ Asked user to test the suggested example/binary/solution labels Mar 19, 2019
@kevinkit
Copy link
Author

Thank you and sorry for the late reply, I will test it as soon as I am having a dual camera setup again!

@abhiTronix abhiTronix pinned this issue May 14, 2019
@OptogeneticsandNeuralEngineeringCore

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!
Projects
None yet
Development

No branches or pull requests

3 participants