OpenCV出错

时间:2011-12-09 21:46:35

标签: c visual-studio-2010 opencv

我正在尝试使用已安装的OpenCV库运行简单代码 并出现错误:应用程序无法正确启动(0xc0150002)。

visual studio 2010 OpenCV 2.1.0

我到处搜索,但无法找到解决这个问题的方法...... 这是我的代码。我该怎么办?

#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#ifdef _EiC
#define WIN32
#endif

static CvMemStorage* storage_face = 0; //Memory Storage to Sore faces

static CvHaarClassifierCascade* cascade_face = 0; 

void detect_and_draw( IplImage* image );

//Haar cascade - if your openc CV is installed at location C:/OpenCV2.0/
const char* cascade_name_face ="C:/OpenCV2.0/data/haarcascades/haarcascade_frontalface_alt.xml";

/////////////////////////////////////////////////////////////////////////////////

int main()
{
    IplImage  *image =0;
    image = cvLoadImage("picci.jpg",1);
    if(!image)
    {
        printf("Error loading image\n");
        return -1;
    }

    cascade_face = (CvHaarClassifierCascade*)cvLoad( cascade_name_face, 0, 0, 0 );

    if( !cascade_face )
    {
        printf("ERROR: Could not load classifier of face  cascade\n" );
        return -1;
    }

    storage_face = cvCreateMemStorage(0);
    cvNamedWindow( "result", 1 );

    // Call function to detect and Draw rectagle around face
    detect_and_draw( image);

    // Wait for key event. 
    cvWaitKey(0);

    // release resourses
    cvReleaseImage( &image );
    cvReleaseHaarClassifierCascade(&cascade_face );
    cvReleaseMemStorage( &storage_face);
    cvDestroyWindow("result");

    return 0;
}

////////////////////////////  Function To detect face //////////////////////////

void detect_and_draw( IplImage* img )
{

    double scale = 2;

    // create a gray image for the input image
    IplImage* gray = cvCreateImage( cvSize(img->width,img->height), 8, 1 );
    // Scale down the ie. make it small. This will increase the detection speed
    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 );

    // Equalise contrast by eqalizing histogram of image
    cvEqualizeHist( small_img, small_img );

    cvClearMemStorage( storage_face);

    if( cascade_face )
    {
        // Detect object defined in Haar cascade. IN our case it is face
        CvSeq* faces = cvHaarDetectObjects( small_img, cascade_face, storage_face,
                                            1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                            cvSize(30, 30) );

        // Draw a rectagle around all detected face 
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect r = *(CvRect*)cvGetSeqElem( faces, i );
            cvRectangle( img, cvPoint(r.x*scale,r.y*scale),cvPoint((r.x+r.width)*scale,(r.y+r.height)*scale),CV_RGB(255,0,0),3,8,0 );

        }
    }

    cvShowImage( "result", img );
    cvReleaseImage( &gray );
    cvReleaseImage( &small_img );
}

1 个答案:

答案 0 :(得分:0)

两个潜在的问题:

  1. 您的应用无法找到OpenCV DLL,您可能需要将OpenCV DLL复制到相应的bin / release或bin / debug目录中。
  2. 或者OpenCV二进制文件使用的CRT版本与您在系统上安装的版本不同。您是否在系统上构建了OpenCV二进制文件?这可能有所帮助。