opencv.cpp文件
#include <iostream>
#include "opencv.hpp"
#include "opencv_test.h"
using namespace cv;
using namespace std;
int main()
{
Mat srcImage = imread("result.jpg");
if (srcImage.data == nullptr)
{
cerr << "图片文件不存在" << endl;
return 0;
}
namedWindow("原图", WINDOW_NORMAL);
imshow("原图", srcImage);
imwrite("output.jpg", srcImage);
Mat image_mini;
namedWindow("缩小图", WINDOW_NORMAL);
resize(srcImage, image_mini, cv::Size(srcImage.cols / 10, srcImage.rows/10));
imshow("缩小图", image_mini);
Rect m_select;
namedWindow("剪裁图", WINDOW_NORMAL);
m_select = Rect(0, 0, srcImage.rows / 10, srcImage.cols / 10);
Mat ROI = srcImage(m_select);
imshow("剪裁图", ROI);
cv::String pattern ="C:/Users/86178/Desktop/6mm-light-on-dark/img/*.png" ;
Read read;
vector<Mat> img = read.ReadImage(pattern);
int c = waitKey(2000);
cout << " c = " << c << endl;
waitKey();
destroyWindow("剪裁图");
waitKey();
destroyAllWindows();
waitKey();
return 0;
}
vector<Mat> Read::ReadImage(cv::String pattern)
{
vector<cv::String> fn;
glob(pattern, fn, false);
vector<Mat> images;
size_t count = fn.size();
for (size_t i = 0; i < count; i++)
{
images.emplace_back(cv::imread(fn[i]));
imshow("img", imread(fn[i]));
waitKey(0);
}
return images;
}
***opencv.h文件***
```c
#pragma once
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
class Read {
public:
vector<Mat> ReadImage(cv::String pattern);
};
|