无法在OpenCV中更改输入视频分辨率

时间:2019-04-17 15:32:49

标签: python-3.x opencv video-capture

我无法在opencv中设置视频捕获分辨率。它被硬编码为1280 x720。我将分辨率设置为640 x360。但是,它仍然显示分辨率为1280 x 720。

106 cap = cv2.VideoCapture(RECORDED_FILE_DEMO)
107 if not cap.isOpened():
108     raise Exception("could not open RECORDED_FILE_DEMO")
109 
110 cap1 = cv2.VideoCapture(RECORDED_FILE_REF)
111 if not cap1.isOpened():
112     raise Exception("could not open RECORDED_FILE_REF")
113 cap1.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
114 cap1.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
115 
116 
117 def show_frame():
118     #print("DEBUG:<show_frame> Im here")
119     cap.set(3, 640)
120     cap.set(4, 360)
121     ret, frame = cap.read()
122     frame = cv2.flip(frame, 1)
123     #frame = cv2.resize(frame,(1200,600))
124     width = cap.get(3)
125     height = cap.get(4)
126     print("DEBUG:<show_frame> width = ", width)
127     print("DEBUG:<show_frame> height = ", height)
128     cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
129     img = Image.fromarray(cv2image)
130     imgtk = ImageTk.PhotoImage(image=img)
131     label1.imgtk = imgtk
132     label1.configure(image=imgtk)
133     #while(pauseFlag == True):
134         #time.sleep(0.001)
135     label1.after(15, show_frame)

输出显示为宽度= 1280,高度= 720

1 个答案:

答案 0 :(得分:0)

也许您的相机不支持该分辨率。 例如,以下是raspberry pi camera支持的模式。