mini6410成功移植OPENCV-2.0.0实现人脸检测


研究这个东西很长时间了,以前是想在arm9上实现这个东西,但是夭折了,现在正好手里面有mini6410的板子,而且对浮点数运算支持较好。所以就试了试。

实现的功能:移植opencv-2.0.0到mini6410,利用QT图形库实现人脸检测。在mini6410上利用Video for Linux接口和QT图形库,对摄像头数据进行采集和显示,在利用opencv的函数对采集的一帧图片进行处理。在利用QT图形库进行显示。
开发环境及工具:

Ubuntu10.10 gcc version 4.4.5
arm-linux-gcc-4.4.1
qt-4.7.2
opencv-2.0.0

1.开发环境的搭建
主要是交叉编译安装qt-4.7.2和交叉编译安装opencv-2.0.0
他们的配置文件分别是:
(1)qt-4.7.2
./configure -qt-kbd-tty -qt-gfx-linuxfb -no-gfx-transformed -no-gfx-multiscreen -qt-mouse-pc -no-gfx-qvfb -no-gfx-vnc -qt-kbd-tty -qt-gfx-linuxfb -no-gfx-qvfb -no-gfx-vnc -qt-mouse-tslib -no-glib -prefix /usr/local/arm/QtEmbedded-4.7.2-arm-4.4.1 -embedded arm -release -shared -fast -no-largefile -qt-sql-sqlite -no-qt3support -no-xmlpatterns -no-mmx -no-3dnow -no-sse -no-sse2 -no-svg -no-webkit -qt-zlib -qt-gif -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -make libs -nomake tools -nomake examples -nomake docs -nomake demo -no-nis -no-cups -no-iconv -no-dbus -no-openssl -xplatform qws/linux-arm-g++ -little-endian -qt-freetype -depths 16,18,24 -I/usr/local/arm/tslib/include -L/usr/local/arm/tslib/lib -v -D__ARM_ARCH_5TEJ__
(2)opencv-2.0.0
./configure --host=arm-linux --without-carbon --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig --without-gtk --enable-static --disable-shared --disable-apps

配置之后显示
HighGUI configuration ================================================

    Windowing system --------------
    Use Carbon / Mac OS X:    no
    Use gtk+ 2.x:             no
    Use gthread:              no

    Image I/O ---------------------
    Use ImageIO / Mac OS X:   no
    Use libjpeg:              yes
    Use zlib:                 yes
    Use libpng:               yes
    Use libtiff:              no
    Use libjasper:            no
    Use libIlmImf/OpenEXR:    no

    Video I/O ---------------------
    Use QuickTime / Mac OS X: no
    Use xine:                 no
    Use gstreamer:            no
    Use ffmpeg:               no
    Use dc1394 & raw1394:     no
    Use dc1394_v2 & raw1394:  no
    Use v4l:                  yes
    Use v4l2:                 yes
    Use unicap:               no

Wrappers for other languages =========================================

    SWIG                     
    Python                    no
    Octave                    no

Additional build settings ============================================

    Build demo apps           no

Now run make ...
如果大家可以把ffmpeg也编译上,那么编写摄像头采集程序的时候就可以不用写采集的程序了。直接调用opencv的显示函数就可以拉。但是我一直不能把他编译到opencv中,所以就自己写的采集的程序。

然后就是make 和make install拉。祝大家顺利!

然后就是编写程序拉。大致的思路我说一下,因为移植gtk是相对比较复杂的,在嵌入式linux下。我们常用的图形库就是QT拉,所以我们主要的目的就是。利用V4l程序把摄像头的图像数据读出来,然后把图像数据显示QLabel上,主要是利用QPixmap读数据和显示。在将想要人脸检测的图像保存到本地。

保存图像代码
    unsigned char * pBuffer =video_dev.buffer;
    fp=fopen("./photo.jpg","w");
    fwrite(pBuffer,12000,1,fp);
    fclose(fp);
在利用IplImage把图片读到内存中。接着就是对他进行人脸检测处理。
void photo::detect_and_draw(IplImage *img)
{
    static CvScalar colors[] =
    {
        {{0,0,255}},
        {{0,128,255}},
        {{0,255,255}},
        {{0,255,0}},
        {{255,128,0}},
        {{255,255,0}},
        {{0,255,0}},
        {{255,0,255}}
    };

    double scale = 2;
    //建立一个空的灰度图
    IplImage* gray = cvCreateImage( cvSize(img->width,img->height), 8, 1 );
    //建立一个空圆形的灰度图
    IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale),
                         cvRound (img->height/scale)),
                     8, 1 );
    int i;
    //图像转换RGB模式转为灰度图
    cvCvtColor( img, gray, CV_BGR2GRAY );

    cvResize( gray, small_img, CV_INTER_LINEAR );
    cvEqualizeHist( small_img, small_img );
    cvClearMemStorage( storage );

    if( cascade )
    {
        double t = (double)cvGetTickCount();
        CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
                                            1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                            cvSize(30, 30) );
        t = (double)cvGetTickCount() - t;
        printf( "detection time = %gms\n", t/((double)cvGetTickFrequency()*1000.) );

        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            CvPoint center;
            int radius;
            center.x = cvRound((r->x + r->width*0.5)*scale);
            center.y = cvRound((r->y + r->height*0.5)*scale);
            radius = cvRound((r->width + r->height)*0.25*scale);
            //cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );
            cvRectangle(img,cvPoint(center.x-radius,center.y-radius),cvPoint(center.x+radius,center.y+radius),colors[i%8],3,8,0);
            //cvRect(center.x-radius,center.y-radius,center.x+radius,center.y+radius);

        }
    }
}

  • 1
  • 2
  • 下一页

相关内容