Cross compilation of OpenCV on gumstixBuild the cross toolchainBuilding the cross toolchain is painful and time consuming. I followed one technical article to build the cross compiler for XScale architecture. If you don't want to challenge your patience, you can download my built toolchain here. If you know Chinese,you can refer to that article here. Cross compile OpenCV
export PATH="~/crosstool/bin:$PATH" Change into OpenCV directory ./configure --host=arm-linux --without-gtk --without-highgui --without-v4l --without-carbon --without-quicktime \ --without-1394libs --without-ffmpeg --without-python --without-swig --enable-static --disable-shared --disable-apps \ CXX=arm-iwmmxt-linux-gnueabi-g++ CPPFLAGS=-I/usr/include –host=arm-linux means your target platform is embedded system, and the following parameters tell the compiler to skip several libraries. I have to skip highgui library because I don't know how to make that library work on gumstix. I compile OpenCV into static library by add –enable-static –disable-shared. The cross compiler is arm-iwmmxt-linux-gnueabi-g++. make make install The default libraries are in the /usr/local/lib Use OpenCVA sample program
//opencvtest.c
#include <cv.h>
#include <cxcore.h>
#include <sys/time.h>
#include <stdio.h>
inline void print_time(struct timeval time1,struct timeval time2){
printf("Time used: %fms\n",((time2.tv_sec-time1.tv_sec)*1e6+time2.tv_usec-time1.tv_usec)/1000.0f);
}
int main(int argc,char *argv[]){
struct timeval time1,time2; //declare the timer
IplImage *pImg;
IplImage *pImg_gray;
pImg=cvCreateImage(cvSize(400,300),8,3);
pImg_gray=cvCreateImage(cvGetSize(pImg),pImg->depth,1);
gettimeofday(&time1,NULL);
cvCvtColor(pImg,pImg_gray,CV_RGB2GRAY); //Convert GRB to gray
gettimeofday(&time2,NULL);
printf("cvCvtColor\n");
print_time(time1,time2);
cvReleaseImage(&pImg);
cvReleaseImage(&pImg_gray);
return 0;
}
Cross compilation requires libz.a and libpng.a. Cross compile the program
arm-angstrom-linux-gnueabi-g++ opencvtest.c -o opencvtest -I/usr/local/include/opencv /usr/local/lib/libhighgui.a \ /usr/local/lib/libcvaux.a /usr/local/lib/libcv.a /usr/local/lib/libcxcore.a /usr/local/lib/libpng.a /usr/local/lib/libz.a -lpthread -ldl The order of the static libraries is crucial. Other order might result in undefined reference error. |