11

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.

om9
  • 179
  • 1
  • 2
  • 5
  • Maybe [that](http://stackoverflow.com/questions/14655969/opencv-error-the-function-is-not-implemented) could help you? – Étienne Apr 30 '13 at 07:11
  • Thanks Etienne for your response. In my case I am trying to cross compile and I have all the libraries in the toolchain. Also the paths are exported properly. I updated the problem as the cmake in first place is unable to locate gtk and hence cross compiles without GTK support. I am trying to fix that. – om9 May 02 '13 at 11:01
  • 1
    If `ldd` is available on the target, check what libraries the executable is looking for. – another.anon.coward May 03 '13 at 18:31
  • [Write a proper `pkg-config` file (**.pc**) for GTK.](http://people.freedesktop.org/~dbn/pkg-config-guide.html) – karlphillip May 14 '14 at 16:21

3 Answers3

11

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.

Morix Dev
  • 2,700
  • 1
  • 28
  • 49
Varun Kumar
  • 119
  • 1
  • 6
2

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.
drahnr
  • 6,782
  • 5
  • 48
  • 75
  • Just to be clear. I need to transfer lib files (e.g. libgdk-x11-2.0.so.0) from ARM linux to x86 linux and set the PKG_CONFIG_PATH on x86 to point to that path? – Gossamer May 14 '14 at 06:51
  • Usually you crosscompile the whole buildroot at once (unless you know the libs were compiled with a compatible compiler – nasty things may happen when using i.e. gcc-3.3 mixed with gcc-4.x) – drahnr Jul 08 '14 at 14:16
0

Opencv highgui error

Have to reinstall opencv using cmake

git clone https://github.com/Itseez/opencv.git
cd ~/opencv 
mkdir release 
cd release 
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_IPP=OFF ..
make -j4 sudo 
make install
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages