My goal is to be able to capture an image using a Logitech hd C270 wencam on Ubuntu 20.04 using OpenCV but I’m encountering a problem that I don’t understand.
Hello,
My goal is to be able to capture an image using a Logitech hd C270 wencam on Ubuntu 20.04 using OpenCV but I’m encountering a problem that I don’t understand.
Here is my program :
`import cv2
def capture_image(device_path, ouput) :
cap = cv2.VideoCapture(device_path)
if not cap.isOpened():
print("Error open the device")
return
ret, frame = cap.read()
print(ret)
print(frame)
if not ret:
print("Error capture image")
return
cv2.imwrite(ouput, frame)
cap.release
print("imahe capturée")
if __name__ == "__main__":
device_path = "/dev/video0"
ouput = "image.jpg"
capture_image(device_path, ouput) `
when I launch my program
ret is False and
frame is None
This is my OS
Linux nahel-VirtualBox 5.15.0-105-generic #115~20.04.1-Ubuntu SMP Mon Apr 15 17:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
nahel@nahel-VirtualBox:/$ v4l2-ctl –list-device
C270 HD WEBCAM (usb-0000:00:06.0-2):
/dev/video0
/dev/video1
nahel@nahel-VirtualBox:/$ v4l2-ctl -V
Format Video Capture:
Width/Height : 640/480
Pixel Format : ‘YUYV’ (YUYV 4:2:2)
Field : None
Bytes per Line : 1280
Size Image : 614400
Colorspace : sRGB
Transfer Function : Rec. 709
YCbCr/HSV Encoding: ITU-R 601
Quantization : Default (maps to Limited Range)
Flags :
nahel@nahel-VirtualBox:/$ v4l2-ctl –list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
I tried my code on Windows and it worked