基本思想:进行两个区域的相交比计算
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
//Mat test = imread("/home/ubuntu/CLionProjects/test/1.jpg");
Mat img = Mat::zeros(Size(400, 400), CV_8UC1);
Rect rec(100, 100, 100, 100);
img(rec) = Scalar(255, 255, 255);
imshow("img1", img);
Mat img1 = Mat::zeros(Size(400, 400), CV_8UC1);
Rect rec1(170, 150, 130, 120);
img1(rec1) = Scalar(255, 255, 255);
imshow("img2", img1);
Mat dst = Mat::zeros(Size(400, 400), CV_8UC1);;
bitwise_and(img, img1, dst);
int iVal255 = countNonZero(dst);
cout << "相交比的面积为" << iVal255 << endl;
imshow("and", dst);
waitKey(0);
return 0;
}
/home/ubuntu/CLionProjects/test/cmake-build-debug/test
相交比的面积为1500
标签:14,img,OpenCV4.4,相交,400,Mat,img1,dst,255 From: https://blog.51cto.com/u_12504263/5718736