I'm trying to read images from an IDS GV-5240CP camera plugged to my laptop via ethernet using Python and OpenCV.
This is what I am supposed to get :
A 1280x1024 image (here resized for upload)
But using this code:
import cv2
cap = cv2.VideoCapture(1)
_, frame = cap.read()
print(frame.shape)
cv2.imshow("Out", frame)
cv2.waitKey(2000)
cap.release()
cv2.destroyAllWindows()
cv2.imwrite('Test2.png', frame)
I get:
How can I set my video capture to the native resolution?
CodePudding user response:
VideoCapture
uses 640x480 by default.
If you want a different resolution, specify it in the constructor or use the set()
method with CAP_PROP_FRAME_WIDTH
and so on. Details in the docs.
cap = cv2.VideoCapture(1, apiPreference=cv2.CAP_ANY, params=[
cv2.CAP_PROP_FRAME_WIDTH, 1280,
cv2.CAP_PROP_FRAME_HEIGHT, 1024])
CodePudding user response:
out = cv2.VideoWriter(("E:", 'output.avi'), fourcc, 20.0, (640, 480)) try using this and change the resolution according to your need, tho it will download or use cv2.resize(frame,(w,h),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)