opencv 有关cvseq类的问题 5C

这段代码返回的值到底是什么?一个矩阵序列?
CvSeq* findSquares4(IplImage* img, CvMemStorage* storage, int minarea, int maxarea, int minangle, int maxangle, int(&temp)[30])
{
CvSeq* contours;//边缘
int N = 6; //阈值分级
CvSize sz = cvSize(img->width & -2, img->height & -2);
IplImage* timg = cvCloneImage(img);//拷贝一次img
IplImage* gray = cvCreateImage(sz, 8, 1); //img灰度图
IplImage* pyr = cvCreateImage(cvSize(sz.width / 2, sz.height / 2), 8, 3); //金字塔滤波3通道图像中间变量
IplImage* tgray = cvCreateImage(sz, 8, 1); ;
CvSeq* result;
double s, t;
int sk = 0;
CvSeq* squares = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), storage);

cvSetImageROI(timg, cvRect(0, 0, sz.width, sz.height));
//金字塔滤波 
cvPyrDown(timg, pyr, 7);
cvPyrUp(pyr, timg, 7);
//在3个通道中寻找矩形 
for (int c = 0; c < 3; c++) //对3个通道分别进行处理 
{
    cvSetImageCOI(timg, c + 1);
    cvCopy(timg, tgray, 0);  //依次将BGR通道送入tgray         
    for (int l = 0; l < N; l++)
    {
        //不同阈值下二值化
        cvThreshold(tgray, gray, 75, 250, CV_THRESH_BINARY);
        cvShowImage("111", gray);
        cvFindContours(gray, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
        while (contours)
        { //多边形逼近             
            result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0);

            //如果是凸四边形并且面积在范围内 
            if (result->total == 4 && fabs(cvContourArea(result, CV_WHOLE_SEQ)) > minarea  && fabs(cvContourArea(result, CV_WHOLE_SEQ)) < maxarea &&  cvCheckContourConvexity(result))
            {

                s = 0;
                //判断每一条边
                for (int i = 0; i < 5; i++)
                {
                    if (i >= 2)
                    {   //角度            
                        t = fabs(angle((CvPoint*)cvGetSeqElem(result, i), (CvPoint*)cvGetSeqElem(result, i - 2), (CvPoint*)cvGetSeqElem(result, i - 1)));
                        s = s > t ? s : t;
                    }
                }
                //这里的S为直角判定条件 单位为角度
                if (s > minangle && s < maxangle)
                {
                    for (int i = 0; i < 4; i++)
                        cvSeqPush(squares, (CvPoint*)cvGetSeqElem(result, i));
                    CvRect rect = cvBoundingRect(contours, 1);       // 获取矩形边界框 
                    CvPoint p1;
                    p1 = cvPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);   //矩形中心坐标  
                    std::cout << "X:" << p1.x << "Y:" << p1.y << std::endl;
                }
            }
            contours = contours->h_next;
        }
    }
    std::cout << "圆的数量是" << sk << std::endl;
    temp[26] = sk;


    sk = 0;
}
cvReleaseImage(&gray);
cvReleaseImage(&pyr);
cvReleaseImage(&tgray);
cvReleaseImage(&timg);

return squares;

}

1个回答

木有大佬帮帮忙 的嘛?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问