我有一个连接到 jetson nano 的树莓派相机 v2。我可以通过运行命令gst-launch-1.0 nvarguscamerasrc sensor_mode=0 来加载相机!'video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12' !nvvidconv 翻转方法=0 !'视频/x-raw,宽度=960,高度=616'!nvvidconv !nvegl变换!nveglglessink -e成功。
现在我正在尝试在 python 中构建一个模块,它将加载相机并将图像写入磁盘。但我收到错误[WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer 警告:无法查询视频位置:状态=0,值=-1,持续时间=-1
我构建的代码在我的带有 USB 摄像头的 Windows 机器上运行良好。
有人可以帮我解决这个问题吗?
蟒蛇版本 - 3.6.9
opencv 版本 - 4.1.1
代码 -
import cv2
import PIL
from PIL import Image
camera_port = 0
ramp_frames = 30
GSTREAMER_PIPELINE = 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1920, height=1080, format=(string)NV12, framerate=21/1 ! nvvidconv flip-method=0 ! video/x-raw, width=960, height=616, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'
camera = cv2.VideoCapture(GSTREAMER_PIPELINE, cv2.CAP_GSTREAMER)
def get_image():
retval, im = camera.read()
return im
for i in range(ramp_frames):
temp = camera.read()
camera_capture = get_image()
im_rgb = cv2.cvtColor(cam`enter code here`era_capture, cv2.COLOR_BGR2RGB)
Image.fromarray(im_rgb).save('webcamfeed.jpg')
del(camera)