Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime Opencv HighGui Error- "HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP". Opencv cross compiled. Host=64bit Ubuntu 12.04. Target=ARM-Cortex-A9

I am a beginner at OpenCV and trying my best to get a simple application running on an embedded platform. I cross-compiled OpenCV 2.4.4 and built it WITH_GTK=ON, WITH_UNICAP=ON, WITH_V4L=ON as needed for camera and GUI support. The following sample code cross-compiles on host:

#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv; 
int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if (!cap.isOpened()) // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges", 1);
    for (;;) {
        Mat frame;
        cap >> frame;   // get a new frame from camera
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if (waitKey(30) >= 0)
            break;
    }
    return 0;
}

Compiling this way for static linking:

arm-linux-gnueabi-g++ -mcpu=cortex-a9 -mfpu=neon -static opencv_camshow.cpp -o exe -I/home/om/OpenCV-2.4.4/platforms/linux/build_soft/install/include -L/home/om/OpenCV-2.4.4/platforms/linux/build_soft/install/lib -L/home/om/OpenCV-2.4.4/platforms/linux/build_soft/3rdparty/lib -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_imgproc -lopencv_core -lopencv_contrib -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_flann -lopencv_photo -lopencv_videostab -pthread -lm -lrt -lzlib -static

Here is the problem. When I try to run the executable file 'exe' on the target, I get this runtime error:

HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/om/OpenCV-2.4.4/modules/highgui/src/window.cpp, line 652

terminate called after throwing an instance of 'cv::Exception'

what(): /home/om/OpenCV-2.4.4/modules/highgui/src/window.cpp:652: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

I re-installed libgtk2.0-dev, pkg-config exists & re-compiled OpenCV , but this hasn't helped. Please let me know if someone knows how to overcome this issue. Thanks in advance. ~Om

More info: I figured out what is causing this problem but not yet fixed it...

From my understanding the problem lies in the cmake scripts of opencv. It does not acknowledge existence of GTK and hence cross compiles with no gtk support. This after making sure that the arm-based gtk library is present in the toolchain's lib folder and its path exported to system paths.

like image 787
om9 Avatar asked Apr 29 '13 20:04

om9


2 Answers

After doing the cmake statement Verify whether the output of cmake includes the following text: V4L/V4L2: Using libv4l.

If it is not there, then install v4l2ucp, v4l-utils and libv4l-dev from synaptic package manager. Then cmake and build again.

This worked for me but I was using OpenCV with python bindings on Ubuntu 12.04.

like image 149
Varun Kumar Avatar answered Oct 14 '22 10:10

Varun Kumar


In order to cross compile you need to tell pkg-config to lookup the proper path (by default this will be your host config/.pc files!)

From pkg-config website

  • searching directories listed in $PKG_CONFIG_PATH
  • when $PKG_CONFIG_LIBDIR is specified, it will override the compiled in default directory (e.g. /usr/lib/pkgconfig) and the PKG_CONFIG_PATH. Note that when specifying PKG_CONFIG_LIBDIR, pkg-config will completely ignore the content in PKG_CONFIG_PATH, even if the documentation states different things.
like image 26
drahnr Avatar answered Oct 14 '22 10:10

drahnr