求opencv行人检测正确率得代码

小生快跑 小生快跑 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在网上看到都是HOG行人检测的事例,但是没有最后计算出检测的正确率。
请老师能不能根据下面的代码,写出检测正确率。我是编程的菜鸟,不会编程。多谢各位高手了。不胜感激。


#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;

// static 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];
//char *_filename="posListINRIA.txt";

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

//img = imread("negListINRIA.txt");

//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;
// }
//}

f = fopen("TestData.txt", "rt"); //这是我测试的图片路径文件

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

for(;;)
{
char* filename = _filename;
if(f)
{
if(!fgets(filename, (int)sizeof(_filename)-2, f)) //每次读取一行,即一张图片的路径
//destination,maxnumber,souce,返回读取的字符串,遇到换行或EOF结束
//最多能读取maxnumber-1个字符,因为默认会加上‘\0’,要给它预留位置
break;
//while(*filename && isspace(*filename))
// ++filename;
if(filename[0] == '#')
continue;
int l = (int)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);
/*
img – Source image.
found_locations – objects boundaries(x,y,width,height).
hit_threshold – Threshold for the distance between features and SVM classifying plane.
win_stride – Window stride. It must be a multiple of block stride.
padding – Mock parameter to keep the CPU interface compatibility. It must be (0,0). ????
scale0 – Coefficient of the detection window increase.
group_threshold – Coefficient to regulate the similarity threshold. When detected, some
objects can be covered by many rectangles. 0 means not to perform grouping. 原本能检测一个人,当设为4的时候居然没了
*/
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);// tl:the top-left corner,br: the bottom-right corner
}
imshow("people detector", img);
int c = waitKey(5000) & 255;
if( c == 'q' || c == 'Q' || !f)
break;
}
if(f)
fclose(f);
return 0;
}
...全文

相关推荐

基于python的opencv行人检测(带简单按钮界面)

基于python语言的opencv行人检测,通过OpenCV自带的HOG+SVM行人检测器图片中的行人,并根据界面提示按钮,选择相应的操作。

ntt_117

OpenCV实例(六)行人检测

行人检测是目标检测的一个分支。目标检测的任务是从图像中识别出预定义类型目标,并确定每个目标的位置。用来检测行人的目标检测系统被称为行人检测系统。行人检测主要用来判断输入图片(或视频)内是否包含行人。若检测到行人,则给出其具体的位置信息。该位置信息是智能视频监控、人体行为分析、智能驾驶、智能机器人等应用的关键基础。由于行人可能处于移动状态,也可能处于静止状态,且外观容易受到体型、姿态、衣着、拍摄角度、遮挡等多种因素的影响,因此行人检测在计算机视觉领域内成为研究热点与难点。

小幽余生不加糖

OpenCV_基于HOG特征的行人检测

OpenCV中提供了HOG的行人检测(pedestrain detection)类。 cv::HOGDescriptor类的构造函数的各参数的定义: CV_WRAP HOGDescriptor() : winSize(64,128), // detect window blockSize(16,16),

icvpr

行人检测Opencv实现

代码全部都是用Opencv实现的,可能在精度方面不是很理想。 这个代码识别的是视频也可识别图片不过需要自己修改

qq_40116678

opencv实现行人检测

用opencv自带分类器实现视频中运动中的行人的检测,工程中包括两个分类器,haarcascade_upperbody.xml和haarcascade_fullbody.xml,是人体全身分类器和上半身分类器,分别识别全身和上半身。

FYJUNJIE
评论 5
收藏 已收藏
分享
返回顶部