27、Opencv进行区域的相交比计算

基本思想:进行两个区域的相交比计算

 

27、Opencv进行区域的相交比计算_第1张图片

 

#include 
#include 
#include 
#include 

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

 

你可能感兴趣的:(OpenCV)