linux下编译安装libjpeg与opencv1.0

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jacky_Ponder/article/details/56008871

Opencv1.0OpenCV最基础的版本,编译后的库文件最小,利于后续嵌入式移植,本博文主要为后续的OpenCV1.0交叉编译做准备。

安装编译opencv的依赖包

sudo apt-get install libgtk2.0-dev pkg-config

无法显示摄像头采集到的视频,可能是因为没有安装libgtk2.0-devpkg-config

opencv中与图像显示相关的函数是基于libgtk2.0-devpkg-config用于组织编译后的opencv头文件与库文件等信息。

 

1.1编译与安装libjpeg(jpegsrc.v6b.tar)

#./configure --enable-shared --enable-static --prefix=/usr/local/libjpeg

#make

#make install

 

编译过程问题:

/usr/bin/install -c -m 644 ./cjpeg.1 /home/zz/jpeg-6b/jpeg/man/man1/cjpeg.1

/usr/bin/install: 无法创建一般文件‘/home/zz/jpeg-6b/jpeg/man/man1/cjpeg.1: 没有那个文件或目录

make: *** [install] Error 1

 

首先要 在你安装的目录下建立4个文件目录:/bin/include/lib/man/man1。如果你没有建立这4个文件目录的话,在make install的时候你会遇到上面的问题。

 

1.2编译与安装opencv1.0

#./configure --prefix=/usr/local/opencv

#make

#make install

编译过程问题:

1../../cxcore/include/cxmisc.h:133:6: error: #elif with no expression

修改  cxmisc.h  133行  #elif   #else.

2

../../../otherlibs/highgui/.libs/libhighgui.so: undefined reference to `cvCaptureFromCAM_V4L(int)'

T添加 #define HAVE_CAMV4L cvconfig.h  24 in

3

cvcap_v4l.cpp:208:28: fatal error: linux/videodev.h: No such file or directory

install libv4l-dev and link to it with the following commands:

sudo apt-get install libv4l-dev

sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h

1.3测试范例

#include "cv.h"
#include "highgui.h" 
 
#include <stdio.h> 
#include <stdlib.h>
#include <string.h> 
#include <assert.h> 
#include <math.h> 
#include <float.h> 
#include <limits.h> 
#include <time.h> 
#include <ctype.h>  
 
#ifdef _EiC 
#define WIN32 
#endif 
 
static CvMemStorage* storage = 0; 
static CvHaarClassifierCascade* cascade = 0;  
 
void detect_and_draw( IplImage* image ); 
 
int main( int argc, char** argv )
{ 
    IplImage *frame, *frame_copy = 0;
 
 
 
const char* cascade_name;
 
cascade_name = argv[1];
 
    const char* input_name;
 
input_name = argv[2];
if(cascade_name)
{
printf("cascade_name:%s\n", cascade_name);
}
else
{
printf("cascade_name:NULL\n");
}
if(input_name)
{
printf("%s\n", input_name);
}
else
{
printf("input_name:lena.jpg\n");
}
 
    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
 
    if( !cascade ){ 
        return -1; 
    }
 
    storage = cvCreateMemStorage(0); 
 
    cvNamedWindow( "result", 1 );
 
const char* filename = input_name ? input_name : (char*)"lena.jpg"; 
IplImage* image = cvLoadImage( filename, 1 ); 
 
if( image )
{
    detect_and_draw( image );
    cvWaitKey(0);
    cvReleaseImage( &image );
}
  cvDestroyWindow("result");
  return 0;
}
 
void 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}},
        {{255,0,0}},
        {{255,0,255}}
    };

    double scale = 1.3; 
    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; 
 
    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 );
        }
    }
    cvShowImage( "result", img );
    cvReleaseImage( &gray );
    cvReleaseImage( &small_img ); 
}

 


 

猜你喜欢

转载自blog.csdn.net/Jacky_Ponder/article/details/56008871