我在线程上编写了用于面部检测的代码,然后我将为眼睛,鼻子和嘴巴写。
但是有一个错误--- 'threadface_func' : undeclared identifier
---
我找不到它是什么。
#include <iostream>
#include "cv.h"
#include "highgui.h"
#include <pthread.h>
typedef struct parameter_t{
CvSeq * detectRect_face;
IplImage* capturedImg;
CvHaarClassifierCascade * pCascade_face;
CvMemStorage * storage;
}parameter_t;
int main ( int argc, const char* argv[] )
{
CvCapture* capture = cvCaptureFromCAM(0);
IplImage* capturedImg;
int resCount = 1;
char path[50];
int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH;
CvHaarClassifierCascade * pCascade_face;
pthread_t threadface;
pCascade_face = (CvHaarClassifierCascade *)cvLoad("C:/Users/Furkan/Desktop/Computer Vision/Programlar/opencv/data/haarcascades/haarcascade_frontalface_alt.xml");
cvNamedWindow("FaceDetection");
while (true)
{
CvMemStorage * storage;
CvSeq * detectRect_face;
capturedImg = cvQueryFrame(capture);
storage = cvCreateMemStorage(0);
parameter_t my_parameters;
int k=pthread_create(&threadface,0,threadface_func,(void*)&my_parameters);
if(k!=0)
{
printf("Create thread failed! error");
return 1;
}
cvShowImage("FaceDetection", capturedImg);
int ch = cvWaitKey(1);
if(ch==27)
break;
else
if(ch == 115)
{
sprintf(path,"d:/resim%d.bmp",resCount++);
cvSaveImage(path,capturedImg,0);
}
}
cvDestroyWindow("FaceDetection");
cvReleaseCapture(&capture);
return 0;
}
void* threadface_func(void* parameter){
parameter_t *p =(parameter_t*)parameter;
p->detectRect_face=cvHaarDetectObjects(p->capturedImg,p->pCascade_face,p->storage,1.15, 3, 0,cvSize(25, 15));
for(int i=0;i<(p->detectRect_face ? p->detectRect_face->total:0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem(p->detectRect_face, i);
CvPoint pt1 = { r->x, r->y };
CvPoint pt2 = { r->x + r->width, r->y + r->height };
cvRectangle(p->capturedImg, pt1, pt2, CV_RGB(255,0,0), 1,8, 0);
}
return 0;
}
请帮忙......
答案 0 :(得分:3)
在C中,必须在引用函数之前声明函数。您在threadface_func
的中间引用了函数main()
,因此您必须在此之前将其声明。
简单的解决方法是将其添加到main()
:
void* threadface_func(void* parameter);
或者,您可以在main()
之前移动整个函数。