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
$cmake-gui

Eopencv1.png

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

Opencv2.png

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

Opencv3.png

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.

Opencv4.png

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.

$make

There will certainly be some errors during compilationv

Error:

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-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find - lgtk-x11-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lgdk-x11-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -latk-1.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lgio-2.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lpangoft2-1.0 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipse

Review:

The WITH_GTK removed, does not compile

Error:

/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lavcodec 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lavformat 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lavutil 
/home/lijp/openwrt/trunk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lswscale 

Review:

The WITH_FFMPEG removed, does not compile.

Compile success!

Install:

$sudo make install

Eeopencv5.png

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 ))
    {
        ImgNum=ImgNum+1;
        sprintf(ImagesName, "Image%.3d.jpg", ImgNum);
        cvSaveImage(ImagesName, pFrame,0);
        if(ImgNum > 5)
            break;
    }
    cvReleaseCapture(&pCapture);
    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
all=test 
LFLAGS += -lpthread -lrt -lopencv_core -lopencv_highgui -lopencv_imgproc
 OBJECTS=test.o 
 $(all): $(OBJECTS) 
 $(CC) $(CFLAGS) $(LFLAGS) $(OBJECTS) -o $(all) 
clean: 
    @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 ..
$make
$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/ld.so.conf.d/opencv.conf

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/ld.so.conf 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 (ld.so) required connections and cache files. cache files by default /etc/ld.so.cache, 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
$./build_all.sh

In facedetect executable program as an example:

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

Or:

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