Opencv
VideoCapture.py
import cv2
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
ret, frame = camera.read()
cv2.imshow('camera', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite("capout.jpg ", frame)
break
camera.release()
cv2.destroyAllWindows()
With the Windows standard camera, when 1080p is selected, the image is normally output from the webcam, but when using Opencv's Video capture, both sides are filled with black as shown in the reference image, and the resolution itself is also extended. I feel the roughness. The frame rate does not increase even though the camera can shoot 60fps movies at 1080p. (The set value is reflected in the get function of VideoCapture, but when the frame rate is actually measured, it peaks at 30 fps.)
A similar phenomenon was reported on the following site, so I tried the solution and solved it. OpenCV capturing imagem with black side bars
VideoCapture2.py
import cv2
#Change streaming to DSHOW
camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
ret, frame = camera.read()
cv2.imshow('camera', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite("capout.jpg ", frame)
break
camera.release()
cv2.destroyAllWindows()
I don't know if the direct cause is bad Windows or a problem with the version of Opencv, but I was able to solve it by using a streaming format called DirectSHOW. Please refer to the explanation about DirectSHOW below. qiita_directshow Until now, I have used Opencv's Video capture normally, but until now (another environment) there was no problem with the default streaming, so the question remains. In addition, if we can confirm options that cannot be used or significant delays due to this change, we will add them.
Recommended Posts