OpenCV Transplant (ii)

Source: Internet
Author: User

Original: 78667175?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!

The next step is to download OpenCV:
: http://blog.csdn.net/yanzi1225627/article/details/47668021

Download good after decompression: Unzip Opencv-2.4.11.zip
CD Opencv-2.4.11.zip
Build two folders to hold the configuration and installation path:
sudo mkdir/usr/local/opencv/install_opencv-d
sudo mkdir/usr/local/opencv/config_opencv-d

Then configure with CMake:
sudo Cmake-gui

In the where is the source code: write the path of the OpenCV file
In the Where to build the binaries: write the working directory as CMake compiled arm version
Then click Configure

Here Generator remain UNIX makefiles and select the fourth option: Specify options for Cross-compiling
Last Click Next

Here Targeting System selected is Linux (previously I chose Arm-linux, a bit pit, choose this no v4l support),
Then I chose the tool chain, I used a friendly 4.4.3 toolchain, Compliers wrote the cross-compiler tool ARM-LINUX-GCC, arm-linux-g++
Target Root writes the containing folder where the cross-compilation tool ARM-LINUX-G++/GCC is located
Finally click Finish to

Then in the middle red configuration:
Cancel WITH_GTK
Cancel With_tiff
Select With_qt
GTK configuration compared to the trouble, I have been configured before Ubuntu has QT, so we cancel out, directly with Qt most GUI. If there is no QT configured, it is still not optional.
Finally click on Configure, you will find an error: "Error in the configuration process,project files may be invalid
CMake Warning at Cmake/opencvfindlibsgui.cmake:18 (find_package):
by does providing "Findqt5core.cmake" in Cmake_module_path this project has
Asked CMake to find a package configuration file provided by ' Qt5core ', but
CMake did not find one.

Could not find a package configuration file provided by ' Qt5core ' with any
Of the following names:
Qt5coreconfig.cmake
Qt5core-config.cmake
The first one is a warning, regardless, the next is the error, said "Qt5core" did not find.
My QT installation path is:/work/qt/my_qt/
So just fill the/work/qt/my_qt/lib/cmake/qt5core with the Qt5core_dir option,
Similarly, the bottom of a few options to fill, Qt5gui_dir, qt5test_dir and so on ....

Click on the Generate button to generate makefile in the/USR/LOCAL/OPENCV/INSTALL_OPENCV directory after clicking the Configure error.

Cd/usr/local/opencv/config_opencv
To modify the path of the installation OpenCV:
sudo vi CMakeCache.txt
Found: cmake_install_prefix:path=/usr/local
Modified to: CMAKE_INSTALL_PREFIX:PATH=/USR/LOCAL/OPENCV/INSTALL_OPENCV
This is my own installation path.

Then sudo make compiles
Finally, the/usr/local/opencv/install_opencv/lib file is ported to the Development Board root file lib

Well, let's test it out:
Find a test example from the Internet, and then modify the following, Test.cpp:

#include <cv.h>#include<cxcore.h>#include#include<iostream>using namespacestd;intMainintargcChar**argv) {Cvcapture* Capture =NULL; Iplimage* frame =NULL; if(! (Capture = Cvcapturefromcam (0)) {cout<<"Can not open camera.\n"<<Endl; return-1; } Cvnamedwindow ("Video",1);  while(frame =Cvqueryframe (Capture)) {Cvshowimage ("Video", frame); cout<<"Have capture\n"<<Endl; } cout<<"No capture\n"<<Endl; Cvdestroywindow ("Video"); Cvreleasecapture (&capture); return 0;}

Compile:

arm-linux-g++-i/usr/local/opencv/install_opencv/include/opencv/-l/usr/local/opencv/install_opencv/lib/-LCV- Lcxcore-lhighgui-lpthread-lrt-o Test Test.cpp

Appear:
Test.cpp:21:note:the mangling of ' va_list ' have changed in GCC 4.4
In gcc 4.4, ' va_list ' has been changed, so when we compile, we add the-wno-psabi option:

arm-linux-g++-wno-psabi-i/usr/local/opencv/install_opencv/include/opencv/-l/usr/local/opencv/install_opencv/ lib/-lcv-lcxcore-lhighgui-lpthread-lrt-o Test Test.cpp

So, is that OK?
No way! Appear:
/usr/local/arm/opt/friendlyarm/toolschain/4.4.3/bin/. /lib/gcc/arm-none-linux-gnueabi/4.4.3/. /.. /.. /.. /arm-none-linux-gnueabi/bin/ld:cannot FIND-LCV
Collect2:ld returned 1 exit status
Here hint LCV can't find, why?
Or I said before, the article on the internet is a few years ago, so old.
Open our OpenCV Lib can see, there is no such library,

So the hint naturally can not find, so to change to our now OpenCV library:

arm-linux-g++-wno-psabi-i/usr/local/opencv/install_opencv/include/opencv/-l/usr/local/opencv/install_opencv/ lib/-lopencv_core-lopencv_highgui-lpthread-lrt-o Test Test.cpp

Two warning appear:
/usr/local/arm/opt/friendlyarm/toolschain/4.4.3/bin/. /lib/gcc/arm-none-linux-gnueabi/4.4.3/. /.. /.. /.. /arm-none-linux-gnueabi/bin/ld:warning:.. /.. /lib/libopencv_imgproc.so, needed by/usr/local/opencv/lib_opencv/lib//libopencv_highgui.so, not found (try using- Rpath Or-rpath-link)
/usr/local/arm/opt/friendlyarm/toolschain/4.4.3/bin/. /lib/gcc/arm-none-linux-gnueabi/4.4.3/. /.. /.. /.. /arm-none-linux-gnueabi/bin/ld:warning:.. /.. /lib/libopencv_core.so, needed by/usr/local/opencv/lib_opencv/lib//libopencv_highgui.so, not found (try Using-rpath Or-rpath-link)

The three. So files that will be needed: libopencv_core.so libopencv_highgui.so libopencv_imgproc.so Copy these libraries into the compiler's lib:

sudo cp-d *libopencv_core* *libopencv_highgui* *libopencv_imgproc*  /usr/local/arm/opt/friendlyarm/toolschain/ 4.4. 3/arm-none-linux-gnueabi/lib

The compiled test file is then placed on the board for execution.

Test Two:

1#include <opencv2/core/core.hpp>2#include <opencv2/highgui/highgui.hpp>3#include <iostream>4 5 using namespaceCV; 6 using namespacestd;7 8 intMain ()9 {   Ten     //Loading Pictures OneMat image= Imread ("girl.jpg");  AMat logo= Imread ("fly.jpg");  -     //define a mat type for storing, ROI for images - Mat Imageroi; the  -imageroi= Image (Rect (Ten,Ten, logo.cols,logo.rows));//defines a cols*rows rectangle window with the upper-left corner coordinates (_x, _y) -  -     //Add the logo to the original +     //parameters: graphs, weights, graphs, weights, added constants, output graphs -Addweighted (Imageroi,0.5, logo,0.3,0., Imageroi);  +  Acout <<"start Add picture......\n"<<Endl;  at     //output a JPG image to the project directory -Imwrite ("fly_girl.jpg", image);  -  - Waitkey ();  -  -     return 0;  in }  

Makefile:

1CC = arm-linux-g++2Lflags =-wno-Psabi3LIBS =-l/usr/local/opencv/install_opencv/lib/-l/work/qt/my_qt/Lib4Cppflags =-lqt5widgets-lqt5gui-lqt5core-lpthread-lopencv_core-lopencv_highgui-lpthread-LRT5LINC + =-i/usr/local/opencv/install_opencv/include/opencv/6OBJS: =Open7  out:=Open8 9$( out): $ (OBJS). cppTen${CC} ${lflags} ${libs} ${linc} ${cppflags}-o [email protected] $^ One  A Clean : -RM $ ( out)

This is the Girl.jpg diagram:

This is the Fly.jpg diagram:

This is synthesized using OPENCV:



OpenCV Transplant (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.