【发布时间】:2015-07-24 14:47:24
【问题描述】:
假设我有以下输出图像:
基本上,我有视频流,我只想在输出图像中获取矩形的坐标。这是我的 C++ 代码:
while(1)
{
capture >> frame;
if(frame.empty())
break;
cv::cvtColor( frame, gray, CV_BGR2GRAY ); // Grayscale image
Canny( gray, canny_output, thresh, thresh * 2, 3 );
// Find contours
findContours( canny_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
// Draw contours
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
cv::imshow( "w", drawing );
waitKey(20); // waits to display frame
}
谢谢。
【问题讨论】:
-
请注意您的矩形被分割成 2 或 3 个轮廓(您会看到,因为它们具有不同的颜色)。看起来您的输入材料不够好(例如边缘图像中的小孔或某事)。
标签: c++ opencv pattern-recognition