blob or Contour overlap area
Hi All,
Is there any option for finding blob or contour overlap area in opencv.
Thanks Raj
add a comment
Hi All,
Is there any option for finding blob or contour overlap area in opencv.
Thanks Raj
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]);
}
Asked: 2015-02-23 02:44:02 -0600
Seen: 1,217 times
Last updated: Feb 23 '15