import cv2
import keyboard
from time import sleep
cap = cv2.VideoCapture(2, cv2.CAP_DSHOW)
cap .set(cv2.CAP_PROP_FRAME_WIDTH, 480)
cap .set(cv2.CAP_PROP_FRAME_HEIGHT, 320)
cap2 = cv2.VideoCapture(3, cv2.CAP_DSHOW)
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, 480)
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, 320)
num = 0
while cap.isOpened():
"""
succes1, img = cap.read()
succes2, img2 = cap2.read()
"""
succes1 = cap.grab()
succes1, img = cap.retrieve()
succes2 = cap2.grab()
succes2, img2 = cap2.retrieve()
k = cv2.waitKey(5)
if k == 27:
break
if keyboard.is_pressed('s'): # wait for 's' key to save and exit
cv2.imwrite('images/stereoLeft/imageL' + str(num) + '.png', img)
cv2.imwrite('images/stereoright/imageR' + str(num) + '.png', img2)
print("images saved!")
num += 1
sleep(0.5)
cv2.imshow('Img 1',img)
cv2.imshow('Img 2',img2)
# Release and destroy all windows before termination
cap.release()
cap2.release()
cv2.destroyAllWindows()
im using the code above to get images in order to calibrate my stereo camera which uses 1 usb for both cams , however i cant have my 2nd camera have higher resolution then my first , and i cant set them both up to 720p, even tho if i open 1 on 720p here and other on windows app with 720p. Highest i can go with both of them is 480x320. Any ideas why my resolutions are stuck ?
This is the error i get :
"Traceback (most recent call last):
File "d:\Self\cvpack\StereoVisionDepthEstimation\calibration_images.py", line 39, in <module>
cv2.imshow('Img 2',img2)
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1i5nllza\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'"