如何在人物周围绘制边界框 [英] How do I draw a bounding box around a person

查看:126
本文介绍了如何在人物周围绘制边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在大学里学习OpenCV项目。我正在编写一个代码,使用框架差异方法执行视频文件的简单背景减法,我成功但我想在减去图像中移动的人周围绘制一个边界框。



我尝试过:



I am starting to learn OpenCV for a project in college. I was working on a code that performs a simple background subtraction of video file using the frame difference method which i succeeded but i wanted to draw a bounding box around the person moving in the subtracted image.

What I have tried:

#include"opencv2\imgproc.hpp"
#include"opencv2\highgui.hpp"
#include"opencv2\video.hpp"
#include"opencv\cv.h"
#include<vector>
#include<stdint.h>
#include<iostream>

using namespace cv;
using namespace std;

Mat currentframe;
Mat prevframe, difframe;
vector<vector<point> > contours;
vector<vec4i> hierarchy;
int area = 0;
int idx = 5;
Rect rect;

int main(int argc, char* argv[]) {

	//Capture Video
	VideoCapture cap("1.mp4");
	if (!cap.isOpened()) {
		cerr << "Unable to open file" << endl;
		return -1;
	}

	

	//namedWindow("Input_Seq", 1);

	namedWindow("Frame Difference", 1);


	while (1) {
		cap >> currentframe;

		if (currentframe.empty())
			break;
		cvtColor(currentframe, currentframe, CV_BGR2GRAY);

		cap >> prevframe;

		if (prevframe.empty())
			break;
		cvtColor(prevframe, prevframe, CV_BGR2GRAY);

		absdiff(currentframe, prevframe, difframe);
		

		//GaussianBlur(difframe, difframe, Size(3, 3), 0, 1, BORDER_DEFAULT);
		Canny(difframe, difframe, 30, 100, 3);
		findContours(difframe, contours, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

		
		

		imshow("Input_Seq", currentframe);
		imshow("Frame Difference", difframe);
		char c = (char)waitKey(25);
		if (c == 27)
			break;
	}
	cap.release();
	destroyAllWindows();
	return 0;
}

推荐答案

有一些事情,你没有使用 rect 任何地方的对象。为什么?难道不应该抓住绑定被发现者的盒子吗?您将检测到的矩形将用于渲染人物周围的框。



我写了一篇涵盖这方面的文章,但我正在处理面孔。因此,在检测到这个事实后,我拍摄了那张脸的区域,并用提供的X Y值绘制了一个矩形。你可以在这种情况下做同样的事情,阅读文章了解更多信息,在ASP.NET Web应用程序中突出显示上传图像中的面部 [ ^ ]。
There are a few things, you are not using the rect object anywhere. Why? Isn't that supposed to capture the box bounding the found person? The rect which you will detect, will be used to render the box around the person.

I wrote an article covering this aspect, but I was working with faces. So after detecting the fact, I took the area of that face and drew a rectangle with the provided X Y values. You can do the same in this case, read the article for more on that, Highlighting the faces in uploaded image in ASP.NET web applications[^].


这篇关于如何在人物周围绘制边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆