网络摄像头在 python OpenCV 上显示灰屏

时间:2021-04-07 08:13:52

标签: python opencv

我正在尝试通过在 win 上使用 OpenCV 来显示视频。 用于检测条形码,但显示灰色屏幕。

Python 上的灰屏:

enter image description here

我在在线网站上测试了网络摄像头,它可以正常使用。 并且此代码可以在其他电脑win8.1上使用

import pyautogui
import time
import cv2
import numpy as np
from pyzbar.pyzbar import decode

#img = cv2.imread(1.png')
cap = cv2.VideoCapture(0)
cap.set(3,1080)
cap.set(4,720)


while True :
    success, img = cap.read()
    for barcode in decode(img):
        print(barcode.data)
        myData = barcode.data.decode('utf-8')
        print(myData)
        pts = np.array([barcode.polygon],np.int32)
        pts = pts.reshape((-1,1,2))
        cv2.polylines(img,[pts],True,(255,0,255),5)
        
        cv2.imwrite(str(myData)+".png",img)
        

    cv2.imshow('Result',img)
    key = cv2.waitKey(1)

    if key == ord('q'):
        break

0 个答案:

没有答案
相关问题