Ask Your Question
0

blob or Contour overlap area

asked 2015-02-23 02:44:02 -0600

Hi All,

Is there any option for finding blob or contour overlap area in opencv.

Thanks Raj

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-02-23 05:20:04 -0600

There is no standard method to find contour overlap, but this function will do the trick:

     int calculateIntersectionArea(const cv::Mat& blobImg, const std::vector<cv::Point> contour1, const std::vector<cv::Point> contour2)
{
    cv::Mat aux1 = cv::Mat::zeros(blobImg.size(), CV_8UC1);
    cv::Mat aux2 = cv::Mat::zeros(blobImg.size(), CV_8UC1);

    cv::rectangle(aux1, cv::boundingRect(contour1), 255, -1, 8, 0);
    cv::rectangle(aux2, cv::boundingRect(contour2), 255, -1, 8, 0);

    cv::bitwise_and(blobImg, aux1, aux1);
    cv::bitwise_and(blobImg, aux2, aux2);

    cv::Mat intersectionMat = aux1 & aux2;

    cv::Scalar intersectionArea = cv::sum(intersectionMat);

    return (intersectionArea[0]);
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-23 02:44:02 -0600

Seen: 1,177 times

Last updated: Feb 23 '15