我的第一个opencv的调试好的程序,开心

// Exercise4.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream> 


//#define OPENCV_CPP_INTERFACE
#include "opencv2/opencv.hpp"
#include <opencv2/core/core.hpp>           // cv::Mat
#include <opencv2/highgui/highgui.hpp>     // cv::imread()
#include <opencv2/imgproc/imgproc.hpp>     // cv::Canny()
using namespace cv;
int main()
{
    cv::Mat image1;
    cv::Mat image2;
    std::string image_filepath1 = "/Users/xxoo/source/repos/Exercise4/Exercise4/fd1.bmp";
    std::string image_filepath2 = "/Users/xxoo/source/repos/Exercise4/Exercise4/fd2.bmp";

    image1 = cv::imread(image_filepath1, 0);
    image2 = cv::imread(image_filepath2, 0);
    //================================================================
    //check if the image is properly laoded
    if (image1.data == NULL) {
        std::cout << "unable to load image1 with file path: " << image_filepath1 << std::endl;
        std::cout << "ending execution..." << std::endl;
        return 0;
    }
    if (image2.data == NULL) {
        std::cout << "unable to load image2 with file path: " << image_filepath2 << std::endl;
        std::cout << "ending execution..." << std::endl;
        return 0;

    }
    cv::Mat image_sub = abs(image1 - image2);

    cv::imshow("image1", image1);
    cv::imshow("image2", image2);
    cv::imshow("image_sub", image_sub);
    std::cout << "Press any key while focusing on the GUI to continue..." << std::endl;
    cv::waitKey();

}
 

猜你喜欢

转载自blog.csdn.net/weixin_42462804/article/details/83053535