我能够检测到所有的方块/矩形(任何轮廓包括4个点)在一个给定的摄像头框架。但我面临的问题是,它检测到一个单一的正方形/矩形为3-4个正方形/矩形,其覆盖范围大致相同(不完全相同)。
问题:--我想删除那些给我类似的“正方形”的CvSeq,它已经被处理/绘制了。

示例:让我们假设一个矩形是{(3,3), (3, 50), (20,4), (25,56)},另一个矩形是{(2,2), (4, 52), (21,6), (23,58)},所以on....so,如果您看到,那么这两个矩形覆盖了image..so的相似部分,我只想保留其中的一个。
在我的代码中,在收到CvSeq中包含的所有方块的信息后,我试图绘制正方形的部分如下:
// the function draws all the squares in the image
void drawSquares( IplImage* img, CvSeq* squares ) // CvSeq* squares--> "square" contains all the points for all the squares.
{
CvSeqReader reader;
IplImage* cpy = cvCloneImage( img );
int i;
// initialize reader of the sequence
cvStartReadSeq( squares, &reader, 0 );
// read 4 sequence elements at a time (all vertices of a square)
for( i = 0; i < squares->total; i += 4 ) // increaing i by 4 because one square consists of 4 points
{
CvPoint pt[4], *rect = pt;
int count = 4;
// read 4 vertices
CV_READ_SEQ_ELEM( pt[0], reader );
CV_READ_SEQ_ELEM( pt[1], reader );
CV_READ_SEQ_ELEM( pt[2], reader );
CV_READ_SEQ_ELEM( pt[3], reader );
// draw the square as a closed polyline
cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );
}
// show the resultant image
cvShowImage( wndname, cpy );
cvReleaseImage( &cpy );
}发布于 2014-02-07 14:41:07
查找重叠矩形并应用cv::groupRect量()
更多的这里。
发布于 2014-01-30 21:19:19
看看squares.c中的这段代码
for( c = 0; c < 3; c++ )
{
// extract the c-th color plane
cvSetImageCOI( timg, c+1 );
cvCopy( timg, tgray, 0 );
// try several threshold levels
for( l = 0; l < N; l++ )
{我建议暂时简化这一点,以便您移除这两个循环。使用CvColor将原始图像转换为灰度,然后首先应用单个CvCanny和单个CvThreshold操作。您可以对参数进行实验,然后在基本检测工作完成后再做更复杂的事情。
https://stackoverflow.com/questions/21390101
复制相似问题