jetsonhacks / buildOpenCVTX2

Build and install OpenCV for the NVIDIA Jetson TX2
MIT License
276 stars 153 forks source link

videocapture error #2

Closed zhanglaplace closed 6 years ago

zhanglaplace commented 7 years ago

Hi, when i use opencv Videocapture to open the camera ,it shows HIGHGUI ERROR:V4L2,pixel format of incoming image is unsuppoted by OpenCV

HoneyPatouceul commented 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.

peter-moran commented 6 years ago

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.

gigimushroom commented 6 years ago

I had the same error from videoio when using cv::videocapture. I fixed it by turning on libv4l lib when building opencv.

Alro10 commented 6 years ago

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

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)
cv2.imshow('fram2',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

It worked for me!