openCV库自带的行人检测demo求助【100分】

WTK-CV 2012-03-15 04:21:31
如下是源代码
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace cv;
using namespace std;

void help()
{
printf(
"\nDemonstrate the use of the HoG descriptor using\n"
" HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\n"
"Usage:\n"
"./peopledetect (<image_filename> | <image_list>.txt)\n\n");
}

int main(int argc, char** argv)
{
Mat img;
FILE* f = 0;
char _filename[1024];

if( argc == 1 )
{
printf("Usage: peopledetect (<image_filename> | <image_list>.txt)\n");
return 0;
}
img = imread(argv[1]);

if( img.data )
{
strcpy(_filename, argv[1]);
}
else
{
f = fopen(argv[1], "rt");
if(!f)
{
fprintf( stderr, "ERROR: the specified file could not be loaded\n");
return -1;
}
}

HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("people detector", 1);

for(;;)
{
char* filename = _filename;
if(f)
{
if(!fgets(filename, (int)sizeof(_filename)-2, f))
break;
//while(*filename && isspace(*filename))
// ++filename;
if(filename[0] == '#')
continue;
int l = strlen(filename);
while(l > 0 && isspace(filename[l-1]))
--l;
filename[l] = '\0';
img = imread(filename);
}
printf("%s:\n", filename);
if(!img.data)
continue;

fflush(stdout);
vector<Rect> found, found_filtered;
double t = (double)getTickCount();
// run the detector with default parameters. to get a higher hit-rate
// (and more false alarms, respectively), decrease the hitThreshold and
// groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
t = (double)getTickCount() - t;
printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());
size_t i, j;
for( i = 0; i < found.size(); i++ )
{
Rect r = found[i];
for( j = 0; j < found.size(); j++ )
if( j != i && (r & found[j]) == r)
break;
if( j == found.size() )
found_filtered.push_back(r);
}
for( i = 0; i < found_filtered.size(); i++ )
{
Rect r = found_filtered[i];
// the HOG detector returns slightly larger rectangles than the real objects.
// so we slightly shrink the rectangles to get a nicer output.
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);
rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
}
imshow("people detector", img);
int c = waitKey(0) & 255;
if( c == 'q' || c == 'Q' || !f)
break;
}
if(f)
fclose(f);
return 0;
}


弄了好久,代码编译正常,通过。运行时,提示0xc000000d, 初始化失败。刚开始以为是HOGDescriptor初始化有问题,可自己重新初始化,依然报错0xc000000d。

也看过一个CSDN上的同样帖子,问题一样,他最后解决了,只是给了个确实是初始化对象失败的原因,但是没说具体修改方案,我也一直在弄了,还没解决掉,所以给个高分求助各位大侠

3Q
...全文
1964 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
MarkovLGXu 2014-06-17
  • 打赏
  • 举报
回复
我在多线程情况下遇到这个问题,已经解决,解决办法我写到了,看看能不能解决了 http://blog.csdn.net/eagleest/article/details/31741181
MarkovLGXu 2014-06-16
  • 打赏
  • 举报
回复
问题是怎么解决的呢?在控制台下面没问题,在线程里面出错!
YUQING0314 2014-04-03
  • 打赏
  • 举报
回复
引用 21 楼 haithink 的回复:
[quote=引用 19 楼 jzwsjcdown 的回复:] 楼主,可否可以说一下,怎么解决的啊??小弟也遇到了这个问题。。。 InputArray _svmdetector=HOGDescriptor::getDefaultPeopleDetector(); 运行这个就报错。。。。
我也是这个问题,貌似控制台就没事,GUI程序就出错!!!!⊙﹏⊙b汗[/quote] 请问这个问题后来解决了吗?怎么解决的?我也卡在这句上了。。。
r101ab 2013-10-25
  • 打赏
  • 举报
回复
求opencv的库,好人一生平安
pangdawa 2013-10-09
  • 打赏
  • 举报
回复
引用 19 楼 jzwsjcdown 的回复:
楼主,可否可以说一下,怎么解决的啊??小弟也遇到了这个问题。。。 InputArray _svmdetector=HOGDescriptor::getDefaultPeopleDetector(); 运行这个就报错。。。。
我也是这个问题,貌似控制台就没事,GUI程序就出错!!!!⊙﹏⊙b汗
luowanying 2013-09-05
  • 打赏
  • 举报
回复
引用 15 楼 a06131021 的回复:
实验了可行
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"

#include<iostream>

#include <XnCppWrapper.h>

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

#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace std ;

using namespace cv;

void help()
{
	printf(
			"\nDemonstrate the use of the HoG descriptor using\n"
			"  HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\n"
			"Usage:\n"
			"./peopledetect (<image_filename> | <image_list>.txt)\n\n");
}

void CheckOpenNIError( XnStatus result, string status )
{ 
	if( result != XN_STATUS_OK ) 
		cerr << status << " Error: " << xnGetStatusString( result ) << endl;
}

/*
int main(int argc, char** argv)
{
	XnStatus result = XN_STATUS_OK;  
//	xn::DepthMetaData depthMD;
	xn::ImageMetaData imageMD;

	//OpenCV
//	IplImage*  imgDepth16u=cvCreateImage(cvSize(640,480),IPL_DEPTH_16U,1);
	
//	IplImage*  depthShow=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);

	IplImage* imgRGB8u=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
	IplImage* showImage=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);

	
//	cvNamedWindow("depth",1);
//	cvNamedWindow("image",1);
	char key=0;

	//【2】
	// context
	xn::Context context; 
	result = context.Init(); 
	CheckOpenNIError( result, "initialize context" );  

	// creategenerator  
//	xn::DepthGenerator depthGenerator;  
//	result = depthGenerator.Create( context ); 
//	CheckOpenNIError( result, "Create depth generator" );  

	xn::ImageGenerator imageGenerator;
	result = imageGenerator.Create( context ); 
	CheckOpenNIError( result, "Create image generator" );

	//【3】
	//map mode  
	XnMapOutputMode mapMode; 
	mapMode.nXRes = 640;  
	mapMode.nYRes = 480; 
	mapMode.nFPS = 30; 
//	result = depthGenerator.SetMapOutputMode( mapMode );  
	result = imageGenerator.SetMapOutputMode( mapMode );  

	//【4】
	// correct view port  
//	depthGenerator.GetAlternativeViewPointCap().SetViewPoint( imageGenerator ); 

	//【5】
	//read data
	result = context.StartGeneratingAll();  
	//【6】
	result = context.WaitNoneUpdateAll();  


    HOGDescriptor hog;
    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

	cvNamedWindow( "peopleDetect", 1 ) ;

	//减小检测图像的大小
	double scale = 0.5 ;
	IplImage* downScaleImage = cvCreateImage( cvSize(640*scale, 480*scale), IPL_DEPTH_8U,3 ) ;

	while( (key!=27) && !(result = context.WaitNoneUpdateAll( )) )
	{
		imageGenerator.GetMetaData(imageMD);
		memcpy(imgRGB8u->imageData,imageMD.Data(),640*480*3);

		cvCvtColor(imgRGB8u,showImage,CV_RGB2BGR);

		cvResize( showImage, downScaleImage ) ;
		

		//Hog处理人体检测
		fflush( stdout ) ;
		vector<Rect> found, found_filtered;

	    double t = (double)getTickCount();
	    // run the detector with default parameters. to get a higher hit-rate
	    // (and more false alarms, respectively), decrease the hitThreshold and
	    // groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
	    
		hog.detectMultiScale( downScaleImage, found, 0, Size(8,8), Size(32,32), 1.1, 2 );
	    
		t = (double)getTickCount() - t;

	    printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());
	    
		size_t i, j;
	    for( i = 0; i < found.size(); i++ )
	    {
		    Rect r = found[i];
		    for( j = 0; j < found.size(); j++ )
			    if( j != i && (r & found[j]) == r)
				    break;
		    if( j == found.size() )
			    found_filtered.push_back(r);
	    }
	    for( i = 0; i < found_filtered.size(); i++ )
	    {
		    Rect r = found_filtered[i];
		    // the HOG detector returns slightly larger rectangles than the real objects.
		    // so we slightly shrink the rectangles to get a nicer output.
		    r.x += cvRound(r.width*0.1);
		    r.width = cvRound(r.width*0.8);
		    r.y += cvRound(r.height*0.07);
		    r.height = cvRound(r.height*0.8);

			cvRectangle(downScaleImage, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
	    }

		cvResize( downScaleImage, showImage ) ;

		cvShowImage( "peopleDetect", showImage ) ;

		key = cvWaitKey(20) ;

	}
	

	cvDestroyWindow("peopleDetect") ;

	cvReleaseImage( &showImage ) ;
	cvReleaseImage( &imgRGB8u ) ;
	cvReleaseImage( &downScaleImage ) ;

	context.StopGeneratingAll();
	context.Shutdown();

	
	return 0 ;

}
*/

int main(int argc, char** argv)
{
	IplImage* person = cvLoadImage( "person.jpg", 1 ) ;

    HOGDescriptor hog;
    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

	cvNamedWindow( "peopleDetect", 1 ) ;

	
	//Hog处理人体检测
	vector<Rect> found, found_filtered;

    double t = (double)getTickCount();
    // run the detector with default parameters. to get a higher hit-rate
    // (and more false alarms, respectively), decrease the hitThreshold and
    // groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
    
	hog.detectMultiScale( person, found, 0, Size(8,8), Size(32,32), 1.05, 2 );
    
	t = (double)getTickCount() - t;

    printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());
    
	size_t i, j;
    for( i = 0; i < found.size(); i++ )
    {
	    Rect r = found[i];
	    for( j = 0; j < found.size(); j++ )
		    if( j != i && (r & found[j]) == r)
			    break;
	    if( j == found.size() )
		    found_filtered.push_back(r);
    }
    for( i = 0; i < found_filtered.size(); i++ )
    {
	    Rect r = found_filtered[i];
	    // the HOG detector returns slightly larger rectangles than the real objects.
	    // so we slightly shrink the rectangles to get a nicer output.
	    r.x += cvRound(r.width*0.1);
	    r.width = cvRound(r.width*0.8);
	    r.y += cvRound(r.height*0.07);
	    r.height = cvRound(r.height*0.8);

		cvRectangle(person, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
    }

	cvShowImage( "peopleDetect", person ) ;
	cvWaitKey() ;
	
	cvDestroyWindow("peopleDetect") ;
	cvReleaseImage( &person ) ;
	
	return 0 ;
}
为什么我运行出来却检测不到人体呢?试了很多图片都不行。。这个问题困扰我很久了,急求答案啊!
jzwsjcdown 2013-05-21
  • 打赏
  • 举报
回复
楼主,可否可以说一下,怎么解决的啊??小弟也遇到了这个问题。。。 InputArray _svmdetector=HOGDescriptor::getDefaultPeopleDetector(); 运行这个就报错。。。。
WTK-CV 2012-06-15
  • 打赏
  • 举报
回复
看来大家对这个比较关注,不好意思 最近比较忙

最近基于HOG+BOOST做了关于手势识别相关研究 目前效果一般,等把效果等等做得稍微好点了 发个总结目标训练检测的帖子到CSDN与大家一起学习。
xuhaohunter 2012-06-11
  • 打赏
  • 举报
回复
这个解决了。但怎么根据OPenCV的CVSVM,CVBOOST,或者libSVM生成的模型,得到自己的HOG?
a06131021 2012-06-01
  • 打赏
  • 举报
回复
请无视,楼上代码中注释部分,那个是我用OpenNI读取Kinect摄像头的代码,忘 了删除了,
还有#include <XnCppWrapper.h>也忘记注释了
a06131021 2012-06-01
  • 打赏
  • 举报
回复
实验了可行
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"

#include<iostream>

#include <XnCppWrapper.h>

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

#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace std ;

using namespace cv;

void help()
{
printf(
"\nDemonstrate the use of the HoG descriptor using\n"
" HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\n"
"Usage:\n"
"./peopledetect (<image_filename> | <image_list>.txt)\n\n");
}

void CheckOpenNIError( XnStatus result, string status )
{
if( result != XN_STATUS_OK )
cerr << status << " Error: " << xnGetStatusString( result ) << endl;
}

/*
int main(int argc, char** argv)
{
XnStatus result = XN_STATUS_OK;
// xn::DepthMetaData depthMD;
xn::ImageMetaData imageMD;

//OpenCV
// IplImage* imgDepth16u=cvCreateImage(cvSize(640,480),IPL_DEPTH_16U,1);

// IplImage* depthShow=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);

IplImage* imgRGB8u=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
IplImage* showImage=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);


// cvNamedWindow("depth",1);
// cvNamedWindow("image",1);
char key=0;

//【2】
// context
xn::Context context;
result = context.Init();
CheckOpenNIError( result, "initialize context" );

// creategenerator
// xn::DepthGenerator depthGenerator;
// result = depthGenerator.Create( context );
// CheckOpenNIError( result, "Create depth generator" );

xn::ImageGenerator imageGenerator;
result = imageGenerator.Create( context );
CheckOpenNIError( result, "Create image generator" );

//【3】
//map mode
XnMapOutputMode mapMode;
mapMode.nXRes = 640;
mapMode.nYRes = 480;
mapMode.nFPS = 30;
// result = depthGenerator.SetMapOutputMode( mapMode );
result = imageGenerator.SetMapOutputMode( mapMode );

//【4】
// correct view port
// depthGenerator.GetAlternativeViewPointCap().SetViewPoint( imageGenerator );

//【5】
//read data
result = context.StartGeneratingAll();
//【6】
result = context.WaitNoneUpdateAll();


HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

cvNamedWindow( "peopleDetect", 1 ) ;

//减小检测图像的大小
double scale = 0.5 ;
IplImage* downScaleImage = cvCreateImage( cvSize(640*scale, 480*scale), IPL_DEPTH_8U,3 ) ;

while( (key!=27) && !(result = context.WaitNoneUpdateAll( )) )
{
imageGenerator.GetMetaData(imageMD);
memcpy(imgRGB8u->imageData,imageMD.Data(),640*480*3);

cvCvtColor(imgRGB8u,showImage,CV_RGB2BGR);

cvResize( showImage, downScaleImage ) ;


//Hog处理人体检测
fflush( stdout ) ;
vector<Rect> found, found_filtered;

double t = (double)getTickCount();
// run the detector with default parameters. to get a higher hit-rate
// (and more false alarms, respectively), decrease the hitThreshold and
// groupThreshold (set groupThreshold to 0 to turn off the grouping completely).

hog.detectMultiScale( downScaleImage, found, 0, Size(8,8), Size(32,32), 1.1, 2 );

t = (double)getTickCount() - t;

printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());

size_t i, j;
for( i = 0; i < found.size(); i++ )
{
Rect r = found[i];
for( j = 0; j < found.size(); j++ )
if( j != i && (r & found[j]) == r)
break;
if( j == found.size() )
found_filtered.push_back(r);
}
for( i = 0; i < found_filtered.size(); i++ )
{
Rect r = found_filtered[i];
// the HOG detector returns slightly larger rectangles than the real objects.
// so we slightly shrink the rectangles to get a nicer output.
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);

cvRectangle(downScaleImage, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
}

cvResize( downScaleImage, showImage ) ;

cvShowImage( "peopleDetect", showImage ) ;

key = cvWaitKey(20) ;

}


cvDestroyWindow("peopleDetect") ;

cvReleaseImage( &showImage ) ;
cvReleaseImage( &imgRGB8u ) ;
cvReleaseImage( &downScaleImage ) ;

context.StopGeneratingAll();
context.Shutdown();


return 0 ;

}
*/

int main(int argc, char** argv)
{
IplImage* person = cvLoadImage( "person.jpg", 1 ) ;

HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

cvNamedWindow( "peopleDetect", 1 ) ;


//Hog处理人体检测
vector<Rect> found, found_filtered;

double t = (double)getTickCount();
// run the detector with default parameters. to get a higher hit-rate
// (and more false alarms, respectively), decrease the hitThreshold and
// groupThreshold (set groupThreshold to 0 to turn off the grouping completely).

hog.detectMultiScale( person, found, 0, Size(8,8), Size(32,32), 1.05, 2 );

t = (double)getTickCount() - t;

printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());

size_t i, j;
for( i = 0; i < found.size(); i++ )
{
Rect r = found[i];
for( j = 0; j < found.size(); j++ )
if( j != i && (r & found[j]) == r)
break;
if( j == found.size() )
found_filtered.push_back(r);
}
for( i = 0; i < found_filtered.size(); i++ )
{
Rect r = found_filtered[i];
// the HOG detector returns slightly larger rectangles than the real objects.
// so we slightly shrink the rectangles to get a nicer output.
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);

cvRectangle(person, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
}

cvShowImage( "peopleDetect", person ) ;
cvWaitKey() ;

cvDestroyWindow("peopleDetect") ;
cvReleaseImage( &person ) ;

return 0 ;
}
xuhaohunter 2012-04-28
  • 打赏
  • 举报
回复
我也在调试OpenCV2.3.1自带的行人检测代码,遇到了一些问题。谁能发我一份调好的代码。434879601@qq.com
xuhaohunter 2012-04-28
  • 打赏
  • 举报
回复
发我一份调好的代码。
xuhaohunter 2012-04-28
  • 打赏
  • 举报
回复
我也在调试OPENCV2.3.1自带的行人检测程序,遇到了一些问题。有人能把调好的代码发我一份吗?谢谢了。434879601@qq.com
imlab 2012-03-23
  • 打赏
  • 举报
回复
建议装OpenCV2.3的库试试,我用的就是2.3+VS2005.编译时需要CMake工具,网上自己找找。
libing64 2012-03-16
  • 打赏
  • 举报
回复
img = imread(argv[1]);
argc 和argv 是在命令行下运行时会用到的参数,argc是可执行文件的名字,argv是要用到的参数
例如:在命令行下,(已经进入文件夹) detect.exe lean.jpg 回车 就会将lean.jpg读入进行人脸检测~

楼主如果使用编译器的话,直接给filename赋值如E:\\imnage\\lean.jpg,将原来程序中的关于argv和argc的删掉就可以了~
向立天 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 cimage 的回复:]

无法进入单步调试,不然就好解决了~F5 直接提示0xc000000d
[/Quote]
main函数都进不去?
WTK-CV 2012-03-16
  • 打赏
  • 举报
回复
无法进入单步调试,不然就好解决了~F5 直接提示0xc000000d
向立天 2012-03-16
  • 打赏
  • 举报
回复
调试看看呢
向立天 2012-03-16
  • 打赏
  • 举报
回复
注释掉main函数内所有代码试试
加载更多回复(4)

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧