0
我試圖運行簡單的代碼與已安裝的OpenCV庫 並且有一個錯誤:應用程序無法正確啓動(0xc0150002)。錯誤與OpenCV
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);
}
你確定它是c#嗎? –
不對我的錯誤 – TTTT
看看這個帖子,也許吧? http://stackoverflow.com/questions/2690374/windows-7-64-visual-studio-2008-opencv2-1-error-the-application-was-unable – psycho