Common method

From WRTnode Wiki Site
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

Cross-compiling opencv-2.4.4

Host Platform :ubuntu

Target Platform :OpenWrt system (mips)

Cross-compiler is mipsel-openwrt-linux-gcc(gcc version 4.6.4 )

get gcc version Information:

$./mipsel-openwrt-linux-gcc -v 

Since future versions opencv 2.0 outset use cmake configuration management. So we need to install the relevant tools, install cmake and cmake-gui (included in cmake-qt-gui). Executed in the terminal:

$sudo apt-get install cmake cmake-qt-gui 

Automatically installed in ubuntu.

Download opencv-2.4.4.tar.gz,Unzip ,Establish compile directory:

$tar -jxvf opencv-2.4.4.tar.gz
$cd opencv-2.4.4
$mkdir build
$cd build


Set the source path (OpenCV-2.4.4) and build path (OpenCV-2.4.4 / build), click configure.


Select the cross-compiler. Click Next to enter the selection screen.


Operating System Select mipsel-linux, cmake can not identify, view the README found cmake identification Linux, rather than mipsel-linux, after the change over will be a lot more options, including V4L and so on.

After selecting the Operating System as well as cross-compiler, click Finish.


The library does not need to be removed, the best modify the installation path (CMAKE_INSTALL_PREFIX), defaults to /usr/local, we can modify according to their own, I was /usr/local/openwrt.

Some configuration information last seen after clicking config. In the print information will Configuring done last sign, indicating config has been completed.

Finally, click generate, generate makefile, then do is compiled.


There will certainly be some errors during compilationv


mipsel-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find - lgtk-x11-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lgdk-x11-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -latk-1.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lgio-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lpangoft2-1.0 


The WITH_GTK removed, does not compile


/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lavcodec 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lavformat 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lavutil 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc- cannot find -lswscale 


The WITH_FFMPEG removed, does not compile.

Compile success!


$sudo make install


Test opencv-2.4.4

$ vim test.c
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#pragma warning(disable : 4996)
#pragma comment(lib, "cv.lib")
#pragma comment( lib, "cxcore.lib" )
#pragma comment( lib, "highgui.lib" )
int main( int argc, char** argv )
    char c;
    IplImage* pFrame = NULL;
    CvCapture* pCapture = NULL;
    char ImagesName[1024];
    int ImgNum=0;
    pCapture = cvCreateCameraCapture(-1);
    printf("pCapture = %d\n",pCapture);
    while(pFrame = cvQueryFrame( pCapture ))
        sprintf(ImagesName, "Image%.3d.jpg", ImgNum);
        cvSaveImage(ImagesName, pFrame,0);
        if(ImgNum > 5)
    return 0;

Here we will compile out of the library and header files put under our toolchain

$sudo cp /usr/local/openwrt/lib/*  xxx/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0. 9.33.2/lib -d -r 
$sudo cp /usr/local/openwrt/include/*  xxx/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0. 9.33.2/include -r 
$vim Makefile
CC = xxx/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0. 9.33.2/bin/mipsel-openwrt-linux-gcc
LFLAGS += -lpthread -lrt -lopencv_core -lopencv_highgui -lopencv_imgproc
 $(all): $(OBJECTS) 
 $(CC) $(CFLAGS) $(LFLAGS) $(OBJECTS) -o $(all) 
    @echo "Cleaning up directory." 
    rm -f *.a *.o $(all) 

Compile the test program, after which the executable program and libopencv * moved to run on WRTnode

ubuntu install opencv-2.4.4

1 First, run the following command in the terminal to make the necessary compiler environment installed.

$sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

2.Download the appropriate version to the PC, where we download OpenCV-2.4.4 Example.

$tar -jxvf OpenCV-2.4.4.tar.bz2
$cd OpenCV-2.4.4
$mkdir build
$cd build
$cmake ..
$sudo make install(Installed by default in /usr/local directory)

Here we can use to replace cmake cmake-gui.

3 Now you need to configure opencv library

$sudo vim /etc/

Add the /usr/local/lib to opencv.conf

$sudo ldconfig

ldconfig is a dynamic link library management command, in order to make the system dynamic link library shared by the need to run a dynamic link library management commands --ldconfig

By use ldconfig command, mainly in the default search directories (/lib and /usr/lib) and listed within the directory /etc/ dynamic library configuration files, search the dynamic link library that can be shared (format as previously described, lib * .so *), and then create a dynamic loader ( required connections and cache files. cache files by default /etc/, save this file has lined up dynamic Link Library list of names.

Open the bash.bashrc and add the following two code

$sudo vim /etc/bash.bashrc

1PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 2export PKG_CONFIG_PATH

8 Run the test program

$cd OpenCV-2.4.4
$cd sample/c

In facedetect executable program as an example:

$./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg 


$./facedetect  --scale=1.5 lena.jpg