gpt4 book ai didi

python - TypeError:来自Jetson Nano上的Raspberry Pi Camera的cv2.imread()的错误参数类型

转载 作者:行者123 更新时间:2023-12-02 16:59:47 28 4
gpt4 key购买 nike

我正在使用Python 3.6.9,OpenCV版本4.1.0和最新版本的Ubuntu在Jetson Nano上运行树莓派相机。我正在运行代码:

import cv2
print(cv2.__version__)
dispW=320
dispH=240
flip=2
cam_set='nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam = cv2.VideoCapture(cam_set)
while True:
ret, frame = cv2.imread(cam)
cv2.imshow('Camera',frame)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()

当我运行它时,它将引发一个错误,并追溯到第11行,并说“ret,frame = cv2.imread(cam)”具有TypeError:内置操作的错误参数类型。我可以使用opencv加载图像,但是运行视频似乎总是会引发此错误。命令行中的“ls -l / dev / video0”工作正常,因此我知道我已连接到摄像机。谢谢!

最佳答案

根据文档:Python: cv2.imread(filename[, flags]) → retvalimread在需要此代码段时会期望有一条路径:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

关于python - TypeError:来自Jetson Nano上的Raspberry Pi Camera的cv2.imread()的错误参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62348993/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com