Problem with OpenCV

Hi!
I’m trying to run some code I compiled on the JetsonTK1 and I get these errors:

HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP
HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
//…some stuff my app prints …//
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /hdd/buildbot/slave_jetson_tk1_2/52-O4T-L4T/opencv/modules/imgproc/src/color.cpp, line 3739
terminate called after throwing an instance of ‘cv::Exception’
what(): /hdd/buildbot/slave_jetson_tk1_2/52-O4T-L4T/opencv/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

Aborted

in case you need to know:
these are the includes I have in my code:
#include “opencv2/highgui/highgui.hpp”
#include “opencv2/imgproc/imgproc.hpp”
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include
#include <opencv2/core/core.hpp>

and upon compiling I use -lopencv_core g++ -std=c++11 -lopencv_imgproc -lopencv_highgui

I also trying some stuff from this topic:
https://devtalk.nvidia.com/default/topic/802681/
with no success…

can anyone help?

Try to use this command before executing your sw:
export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
or this:
export LD_PRELOAD=“/usr/lib/libv4l/v4l2convert.so”

if one of the two is working you can add it at he end of your .bashrc file to automatically execute it when you start a terminal session

Thanks for the response, however… the directory /usr/lib/libv4l doesn’t exist on the board… what should I have installed to have it?

It could mean that your camera (camera driver) is generating images in a format OpenCV doesn’t understand, such as compressed video or YUV video instead of RGB, etc. First thing I recommend is that if you built or installed public OpenCV or any v4l or camera or multimedia libraries yourself then perhaps start from a clean system (ie: flash your board and install Grinch and OpenCV4Tegra), then see if your OpenCV install works with your camera, and if not then try 1 or 2 different webcams, because it is probably an issue with your webcam compatibility.

If so, you might decide to use V4L or Gstreamer or a similar API directly and see if they can access your camera, and if so then use that API to obtain camera images and then access the image from OpenCV.

thank you so much!
I think I figured the problem - I’m using threads and for somehow they don’t work, but that’s for another time!

thank you!

Howdid you resolve the issue ? since i am also getting same issue, i installed Opencv4tegra

I somewhat came over the error “Pixel format of incoming image is unsupported by OpenCV” thanks to @Myzhar.

Bur location of ‘v4l1compat.so’ and ‘v4l2convert.so’ is different in my Jetson TX2.

So I did:

$ export LD_PRELOAD=“/usr/lib/aarch64-linux-gnu/libv4l/v4l1compat.so”
$ export LD_PRELOAD=“/usr/lib/aarch64-linux-gnu/libv4l/v4l2convert.so”

Now I do not see the above error anymore, however, I got black window…

The window supposed to show camera input displays only black screens.

And I got another error “HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP.”

What should I do?

I am using cv::VideoCapture input(0);for using onboard camera in Jetson tX1. On running I got this error “Pixel format of incoming image is unsupported by OpenCV” . I tried $ export LD_PRELOAD=“/usr/lib/aarch64-linux-gnu/libv4l/v4l1compat.so”
$ export LD_PRELOAD=“/usr/lib/aarch64-linux-gnu/libv4l/v4l2convert.so”
still i am getting same error.

Please help in removing this error and also how can I use onboard camera using OpenCV or Openvx ?

@Eyshika: You cannot use the TX onboard camera directly in opencv, it is a bayer sensor and bayer format is not suitable for opencv.
You may use gstreamer plugin nvcamerasrc for debayering, but opencv4tegra doesn’t support it.
You could build your own version of opencv (I’d suggest 3.2.0) enabling gstreamer-1.0 support.
You may check:[url]https://devtalk.nvidia.com/default/topic/1001696/jetson-tx1/failed-to-open-tx1-on-board-camera/post/5117370/#5117370[/url]

@Honey: If i will install opencv 3.2.0 then there might be some directories mixmatch among opencv4tegr and opencv 3.2. and i cant remove opencv4tegra because this is what i wnt to use for my project. Do you have any other suggestions regarding this? Also, if not onboard camera then can i use Usb camera using the command I mentioned in my above post?

If you configure your opencv build with another install path (for example -DCMAKE_INSTALL_PREFIX=/usr/local/opencv-3.2.0), then it will be installed in another location than opencv4tegra installed in /usr.
It means that you will have to provide include path to gcc with -I/usr/local/opencv-3.2.0/include and libs path with -L/usr/local/opencv-3.2.0/lib, otherwise opencv4tegra will be found by default. For execution, you may also have to add /usr/local/opencv-3.2.0/lib to environment variable LD_LIBRARY_PATH.
Also note if you are using scripts using pkg-config that /usr/lib/pkgconfig/opencv.pc of opencv4tegra may be found before /usr/local/opencv-3.2.0/lib/pkgconfig/opencv.pc.

I am struggling with Jetson TX2.

I first followed http://dev.t7.ai/jetson/opencv/.

But it was written for Jetson TX2.

I needed additional modification: https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945.

After force recovery, I did:

$ sudo apt-get purge libopencv4tegra-dev libopencv4tegra
$ sudo apt-get purge libopencv4tegra-repo
$ sudo apt-get update

$ sudo apt-get install build-essential
$ sudo apt-get install cmake libavcodec-dev libavformat-dev libgtk2.0-dev pkg-config

$ sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

$ sudo apt-get install python2.7-dev
$ sudo apt-get install python-dev python-numpy
$ sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

$ sudo apt-get install libgtkglext1 libgtkglext1-dev
$ sudo apt-get install qtbase5-dev

$ sudo apt-get install libv4l-dev v4l-utils qv4l2 v4l2ucp

$ curl -L https://github.com/opencv/opencv/archive/3.2.0.zip -o opencv-3.2.0.zip
$ unzip opencv-3.2.0.zip
$ cd opencv-3.2.0

$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D CUDA_ARCH_BIN=“6.2” -D CUDA_ARCH_PTX=“” -D WITH_OPENGL=ON -D WITH_LIBV4L=ON …

$ sudo emacs -nw /usr/local/cuda-8.0/include/cuda_gl_interop.h
±---------------------------------------------------------------------------------------------------+
|diff --git a/cuda_gl_interop.h b/cuda_gl_interop.h
|index 0f4aa17…e8c538c 100644
|— a/cuda_gl_interop.h
|+++ b/cuda_gl_interop.h
|@@ -59,13 +59,13 @@
|
| #else /* APPLE /
|
|-#if defined(arm) || defined(aarch64)
|-#ifndef GL_VERSION
|-#error Please include the appropriate gl headers before including cuda_gl_interop.h
|-#endif
|-#else
|+//#if defined(arm) || defined(aarch64)
|+//#ifndef GL_VERSION
|+//#error Please include the appropriate gl headers before including cuda_gl_interop.h
|+//#endif
|+//#else
| #include <GL/gl.h>
|-#endif
|+//#endif
|
| #endif /
APPLE */
±---------------------------------------------------------------------------------------------------+

$ cd /usr/lib/aarch64-linux-gnu/
$ sudo ln -sf tegra/libGL.so libGL.so

$ cd ~/opencv-3.2.0/release/
$ make -j4
$ sudo make install

And built in camera is working fine in Python code: https://devtalk.nvidia.com/default/topic/987537/jetson-tx1/videocapture-fails-to-open-onboard-camera-l4t-24-2-1-opencv-3-1/.

OpenCV4Tega does not support a Jetson TX2 built in camera.

hi wiany11,

have you ever solved the "The window supposed to show camera input displays only black screens.And I got another error “HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP.”

thanks

Does your opencv version have V4L2 support ?

If not, be sure to have installed package libv4l-dev, reconfigure opencv enabling V4L/V4L2 support, rebuild and install.

hi Honey_Patouceul,

i have installed V4L2, but i have no idea my opencv version has V4L2 support. btw, do you mean the Opencv or the OpenCV4Tegra? and how to reconfigure opencv enabling V4L/V4L2 support.

can you do me a favor?

thanks

One nice thing in opencv is that it has a run time function for telling you the config it has been built from:

#include <opencv2/opencv.hpp>
#include <iostream>

int main()
{
	std::cout << cv::getBuildInformation() << std::endl;
	return 0;
}

In the output of running this, you’ll know which version of opencv you’re running and the various options supported or not. In section Video I/O, you will check such line (this output is from opencv-3.3 on my TX2):

V4L/V4L2:                    Using libv4l1 (ver 1.10.0) / libv4l2 (ver 1.10.0)

Have you built your own version of opencv or are you just using the default opencv4tegra ?

Hi Honey_Patouceul

Thanks for helping. I have successfully installed opencv 3.3 and use it instead of opencv4tegra. Here is my shell: https://github.com/zimenglan-sysu-512/OpenCVBuild4TX2