I have a stereocam and I want both cameras to work seperately so that I can perform camera caliberation and other techniques to implement stereo vision. Code of displaying it is basic openCV if anyone wants to see heres the code:
import cv2
def capture_dual_camera_module(camera_index_left=1, camera_index_right=2):
"""
Captures video streams from two cameras (stereo camera) simultaneously.
Args:
camera_index_left (int, optional): Index of the left camera (default: 0).
camera_index_right (int, optional): Index of the right camera (default: 1).
Returns:
None
"""
cap_left = cv2.VideoCapture(camera_index_left)
cap_right = cv2.VideoCapture(camera_index_right)
if not (cap_left.isOpened() and cap_right.isOpened()):
print("Error: One or both camera streams could not be opened.")
return
while True:
# Capture frames from both cameras
ret_left, frame_left = cap_left.read()
ret_right, frame_right = cap_right.read()
if not ret_left or not ret_right:
print("Error: Couldn't read frames from one or both camera streams.")
break
# Display the resulting frames (adjust window names for clarity):
cv2.imshow('Left Camera', frame_left)
cv2.imshow('Right Camera', frame_right)
# Break the loop on 'q' key press
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release capture resources
cap_left.release()
cap_right.release()
cv2.destroyAllWindows()
if name == “main“:
capture_dual_camera_module()
I have a stereo camera which works just fine when operated normally as a usb cam. But what I want is to control both modules seperately. I tried it using openCV by passing camera index. The problem here is that webcam of my laptop has index 0 and usb stereo cam has index 1. When I pass indexes [0 1] it releases webcam and one camera of stereocam. When I pass indexes [1 2] it shows error:
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
Error: One or both camera streams could not be opened.
This is the camera I am using