Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why bitwise_and does not compute intersection?

I have written this lines of code:

cv::Mat maskC(m_imgSize, CV_8UC1, cv::Scalar::all(0));
cv::Mat maskPC(m_imgSize, CV_8UC1, cv::Scalar::all(0));
cv::Mat maskIntersection(m_imgSize, CV_8UC1, cv::Scalar::all(0));

cv::imshow("maskC", maskC);
cv::imshow("maskPC", maskPC);
cv::imshow("maskIntersection", maskIntersection);
cv::waitKey();

PointVector contourCvx = convexingContour(contourIn);
PointVector plateContourCvx = convexingContour(plateContourIn);

cv::fillConvexPoly(maskC, contourCvx, cv::Scalar::all(255));
cv::fillConvexPoly(maskPC, plateContourCvx, cv::Scalar::all(255));
cv::bitwise_and(maskC, maskPC, maskIntersection);

double mi=-1, ma=-1;
cv::minMaxLoc(maskIntersection, &mi, &ma, 0, 0);
std::cerr << "(min,max) = (" << mi << "," << ma << ") ";

cv::imshow("maskC", maskC);
cv::imshow("maskPC", maskPC);
cv::imshow("maskIntersection", maskIntersection);
cv::waitKey();

But the maskIntersection is not changed; it is still a zero matrix. The standard output is displaying: (min,max) = (0, 0) every time.

Why bitwise_and does not return the intersection of the two: maskC and maskPC?