1.1 显示一张图片
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <filesystem>
using namespace std;
using namespace cv;
int main()
{
cout << "OpenCV_Version: " << CV_VERSION << endl;
Mat img = imread("C:/Users/Pictures/ScreenShot_20231010083129.jpeg");
imshow("picture", img);
waitKey(0);
return 0;
}
1.2 遍历显示目录中图片
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <filesystem>
using namespace std;
using namespace cv;
const string img_format_subport[3] = { ".png", ".jpeg", ".jpg" };
int main()
{
cout << "OpenCV_Version: " << CV_VERSION << endl;
for (const auto& entry :
std::filesystem::directory_iterator("C:/Users/Pictures/Camera Roll"))
{
if (entry.path().extension() == img_format_subport[0]
|| entry.path().extension() == img_format_subport[1]
|| entry.path().extension() == img_format_subport[2])
{
std::string fname = entry.path().string();
cv::Mat img = cv::imread(fname);
imshow("picture", img);
while (waitKey(1) != ' ');
cv::destroyAllWindows();
}
}
return 0;
}