Closed zhanglaplace closed 6 years ago
You are trying to access the camera with v4l2 interface, but your camera doesn't provide the expected format for opencv (gray8 or BGR). The onboard camera is a bayer sensor. You can use gstreamer interface, if you've configured opencv with gstreamer-1.0 support, for making a pipeline that converts into BGR.
FYI, I've put together a guide for using gstreamer with OpenCV on the TX2. Just scroll down to the OpenCV section to see how to compile with gstreamer support and some example code.
I had the same error from videoio when using cv::videocapture. I fixed it by turning on libv4l lib when building opencv.
Can you try to run this code?
import numpy as np import cv2
cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)300, height=(int)300,format=(string)I420, framerate=(fraction)20/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
while(True):
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)
cv2.imshow('fram2',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() cv2.destroyAllWindows()
It worked for me!
Hi, when i use opencv Videocapture to open the camera ,it shows HIGHGUI ERROR:V4L2,pixel format of incoming image is unsuppoted by OpenCV