矩形交叉点问题

时间:2018-03-18 20:26:12

标签: c++ opencv intersection

使用OpenCV 3.1:我创建了一个简单的变更检测程序。我添加了一个功能,用户可以在检测到更改的位置创建约束。用户可以在框架视图中选择ROI,并且只能在其中注册更改。我想用交集来做这件事。将轮廓转换为矩形,然后将所述rects与所有ROI的用户规定进行比较(如果没有设置的程序创建单个ROI大小的帧)。我已经看过使用了交叉,但它并不想为我工作。

tuple<Mat, bool, bool> checkContours(Mat frame, int minArea, vector<vector<Point>> contours, bool occupied, bool initialFrame,vector<Rect> masterROI){
    int foundContourCount;
    Rect boundRect, intersectingRect;
    vector<Rect> boundRectList;
    if (contours.size() > 1){
        foundContourCount = 0;

        //remove all contours with too small an area
        for(int i = 0; i < contours.size(); i++){
            //get the boundboxes and save the ROI as an Image
            if (contourArea(contours[i]) < minArea){
                continue;
            }
            boundRect = boundingRect( Mat(contours[i]));
            boundRectList.push_back(boundRect);
        }

        //confirm that there are rects in the list
        cout << boundRectList.size() << endl;

        //check if valid bournding areas intersect the provided ROI's
        for(int i = 0; i < masterROI.size();i++){
            for(int ii = 0; i < boundRectList.size();ii++){
                intersectingRect = boundRectList[ii] & masterROI[i];
                if(intersectingRect.area() > 0){
                    //cout << "found one" << endl;
                    rectangle( frame, boundRect.tl(), boundRect.br(), Scalar(0,255,0), 1, 8, 0 );
                    foundContourCount++;
                }
            }
        }

0 个答案:

没有答案