#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
包含头文件:
#include <opencv2/opencv.hpp>:引入 OpenCV 库。#include <iostream>:引入标准输入输出流库。命名空间:
using namespace cv; 和 using namespace std;:使用 OpenCV 和标准库的命名空间,避免每次调用函数时都需要加前缀。主函数:
imread 函数读取图片文件,并检查是否成功读取。namedWindow 创建一个窗口,并使用 imshow 显示图片。waitKey(0) 等待用户按键关闭窗口。这个简单的例子展示了如何使用 OpenCV 读取和显示图像。你可以根据需要进一步扩展功能,例如添加图像处理操作或保存处理后的图像。
上一篇:qt c++
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站