【发布时间】:2013-01-08 11:09:31
【问题描述】:
你好 peeps 我已经开发了一个绘制输入图像轮廓的软件,现在我不会把它提升到一个新的水平,并在感兴趣的对象(即一个人)周围绘制边界框。我查看了 boundingRect() 函数,但我很难理解它。也许有不同的功能算法绘制边界框.....?
这是我的程序的代码:
#include "iostream"
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv\ml.h>
#include<opencv\cxcore.h>
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
#include <opencv2/highgui/highgui.hpp> // Video write
using namespace cv;
using namespace std;
Mat image; Mat image_gray; Mat image_gray2; Mat threshold_output;
int thresh=100, max_thresh=255;
int main(int argc, char** argv) {
//Load Image
image =imread("C:/Users/Tomazi/Pictures/Opencv/tomazi.bmp");
//Convert Image to gray & blur it
cvtColor( image,
image_gray,
CV_BGR2GRAY );
blur( image_gray,
image_gray2,
Size(3,3) );
//Threshold Gray&Blur Image
threshold(image_gray2,
threshold_output,
thresh,
max_thresh,
THRESH_BINARY);
//2D Container
vector<vector<Point>> contours;
//Fnd Countours Points, (Imput Image, Storage, Mode1, Mode2, Offset??)
findContours(threshold_output,
contours, // a vector of contours
CV_RETR_EXTERNAL,// retrieve the external contours
CV_CHAIN_APPROX_NONE,
Point(0, 0)); // all pixels of each contours
// Draw black contours on a white image
Mat result(threshold_output.size(),CV_8U,Scalar(255));
drawContours(result,contours,
-1, // draw all contours
Scalar(0), // in black
2); // with a thickness of 2
//Create Window
char* DisplayWindow = "Source";
namedWindow(DisplayWindow, CV_WINDOW_AUTOSIZE);
imshow(DisplayWindow, result);
waitKey(5000);
return 1;
}
谁能提出解决方案...?也许指导我一些资源、教程等。阅读 OpenCV 文档并查看我仍然不理解的 boundingRect() 函数。请帮忙:)
【问题讨论】:
-
您的问题是如何获取边界框的参数或如何使用
rectangle函数实际绘制它? -
both :/ 如果您可以将我引导到一些简单的资源或教程,或者如果您可以在此处向我解释它甚至更好。谢谢
标签: c++ opencv bounding-box