簡體   English   中英

無法在 Jetson Xavier 的 python 中使用 OpenCV 捕獲視頻

[英]Cannot capture video using OpenCV in python in Jetson Xavier

我正在嘗試讀取 Jetson Xavier(ubuntu 18)上的相機圖像。 我面臨一個問題。 當我運行以下代碼時,它會發出警告並給出黑色(完整)圖像。

[警告:0] 全局 /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) 打開 OpenCV | GStreamer 警告:無法查詢視頻 position:狀態=0,值=-1,持續時間=-1

cam=cv2.VideoCapture(0)
if cam.isOpened():
    grab,img = cam.read()
    if grab is True:
        cv2.imshow('sample image',img)
    else:
        print(f"Image not found")
else:
    print("Camera not openedd")
       

cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows() # destroys the window showing image

如果我使用“dev/video0”來讀取圖像,即

cam=cv2.VideoCapture('dev/video0')

我收到未打開相機的警告和自定義錯誤消息

[警告:0] 全局 /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) 打開 OpenCV | GStreamer 警告:打開 bin 時出錯:沒有元素“dev” [WARN:0] 全局 /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer 警告:GStreamer:管道尚未創建相機未打開

然后我創建了 gstream 字符串並將其傳遞給視頻捕獲,如下所示。 字符串如下

gstr = 'varguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'

cap = cv2.VideoCapture(gstr, cv2.CAP_GSTREAMER)

我收到以下錯誤

Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:645 No cameras available

(python3:15402): GStreamer-CRITICAL **: 19:08:54.835: gst_mini_object_set_qdata: assertion 'object != NULL' failed
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Traceback (most recent call last):

我是jetson的新手,請指導我。 謝謝

你可以試試下面的代碼。 Also make sure you have installed OpenCV from source not using pip because Jetson Nano and Xavier make some problems when you install OpenCV from pip.

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM