python-opencv cannot open the camera under Ubuntu, open VIDEOIO(V4L2:/dev/video0): can't open camera by index

python-opencv cannot open the camera under Ubuntu

When we use opencv under ubuntu to obtain camera images, an error is reported.
open VIDEOIO(V4L2:/dev/video0): can‘t open camera by index

1. To solve this problem, first use the shortcut key WIN+R to open the terminal under the Windows system and enterservices.msc

Insert image description here

2. Find the VMware USB Arbitration Servuce service and ensure that this function starts normally

3. Open the virtual machine settings, select the USB controller, set USB compatibility to USB3.1, and click OK

Insert image description here
Insert image description here

4. Click on the virtual machine, select the removable device, select "IMC Networks Integrated Camera", and click Connect

Insert image description here

Then observe the lower right corner of the virtual machine desktop. If there is a small green dot on the camera, it means the connection is successful.

Insert image description here

Then let’s test it, the camera picture

import cv2 as cv2

cap = cv2.VideoCapture(0)
cap.set(3, 640) #设置窗口宽度,前面3表示设置宽度,后面表示宽度设置为640
# cap.set(4, 480) #设置窗口高度,前面4表示设置高度,后面表示高度设置为480
while True:
    success, img = cap.read()
    cv2.imshow("Video", img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

####### This is the picture transmitted back by the camera
Insert image description here

Guess you like

Origin blog.csdn.net/m0_63715549/article/details/130713418
Recommended