OpenCv 3.3 and integrated Camera Problems!

The Opencv version is 3.3.0 and Tegra # R28 (release), REVISION: 1.0, GCID: 9379712, BOARD: t186ref, EABI: aarch64, DATE: Thu Jul 20 07:59:31 UTC 2017

Cuda ARCH Bin is on 6.2

Hi, I get “Failed to open camera.”

@Elektrische - Can you confirm that you do not have VisionWorks installed? I believe that the issue is the missing library libgstreamer1.0-dev

You can check to see if it’s there:
$ dpkg -s libgstreamer1.0-dev

Kangalow, that was it Thank you , and thanks everybody !!

Hello everybody,
I use tx2 developer board. Opencv 3.2 is installed according to the instructions of Jetsonhacks. I would like to write a c ++ program, which takes a video from the on-board-camera. For this I have found here an introduction, however for TX1:
https://devtalk.nvidia.com/default/topic/943129/jetson-tx1/highgui-error-v4l-v4l2-while-opening-camera-with-opencv4tegra-l4t-r24/post/4921383/#4921383
If I execute the code listed there from the moderator “kayccc”, I get the error message “Fail to open camera”

VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"); //open the default camera
if(!cap.isOpened()) { // check if we succeeded
cerr << "Fail to open camera " << endl;
return -1;
}
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("original", frame);
waitKey(1);
}
// the camera will be deinitialized automatically in VideoCapture destructor
cap.release();

If I take the settings for gst-launch from the sample code, I see in the console the start of the pipeline, but without image.

I have found here in the forum more examples of gst-launch-1.0, For example:

gst-launch-1.0 -ev nvcamerasrc ! 'video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)I420, framerate=(fraction)30/1' ! nvvidconv ! 'video/x-raw, format=(string)BGRx' ! videoconvert ! 'video/x-raw, format=(string)BGR' ! appsink

This example works well.

When I insert these settings into the sample code of moderator “kayccc” I still get the message “Fail to open camera”.

I can not see where the error is.

Thanks for the efforts

Best regards

A possible cause for this error could be using an opencv build not supporting gstreamer, such as opencv4tegra.
I suggest you add this line at the beginning of your code :

std::cout << cv::getBuildInformation() << std::endl;

and check its output for which opencv version is running and if it has gstreamer-1.0 support enabled.

Hi, thanks for the quick response. That was the problem. Have opencv with gstreamer support newly built, and lo and behold, it works.
Best regards

Hi DaneLLL,

I was referred to this post to remove the bottleneck/slow performance caused by ‘videoconvert’ in gstreamer pipeline in OpenCV. I was able to do that using OpenCV 3.3, R28 and on-board camera.

But now I have to use R24.2.1 on TX1 because the drivers provided by Leopard Imaging work only on R24.2.1. I installed OpenCV 3.3 using the instructions in the link above. For a lot of the required packages it said they were not found.

And (I think) due to that, I still have to use ‘videoconvert’ in the gstreamer pipeline. Otherwise OpenCV fails to open the camera.

Can you tell me if there is a solution to get OpenCV 3.3(or any other version) on R24.2.1 to accept NV12/I420 to appsink?

Thanks!

Hi vchinta,
What is the error you see in building OpenCV 3.3 on r24.2.1? We don’t try it yet but other users may share experience.

I started a new thread for it under Jetson TX1.

Link - [url]https://devtalk.nvidia.com/default/topic/1025004/jetson-tx1/opencv-on-r24-2-1-i420-to-appsink/?offset=3#5213974[/url]

i run capture code and i get an error like this

btw i’m using logitech 720p

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV Unable to stop the stream: Device or resource busy OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp, line 10638 Traceback (most recent call last): File “capbless.py”, line 8, in gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.error: /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor please

please helping me
thank you so much

Could you post your “capbless.py” code for debugging? Otherwise the following post might help.

[url]TX2 Camera not working? - Jetson TX2 - NVIDIA Developer Forums

this is my code sir.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

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

cap.release()
cv2.destroyAllWindows()

@olivia.vyasitanggang, /dev/video0 (the device you’d be using when you do ‘cv2.VideoCapture(0)’) on Jetson TX2 is the onboard camera. That onboard camera device only spits out Bayer video data (RGGB, RG10, BG10, RG12, etc.) and thus cannot be accessed by cv2.VideoCapture() directly.

There are a couple of alternatives for you:

  1. Use GStreamer pipeline with ‘nvcamerasrc’ to access the onboard camera. (You should be able to find a lot of references on this forum regarding how to do that.)
  2. Use a USB webcam, say /dev/video1, and do cv2.VideoCapture(1).

Also feel free to check out my blog post for more information, “How to Capture and Display Camera Video with Python on Jetson TX2”: [url]https://jkjung-avt.github.io/tx2-camera-with-python/[/url]