Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

opencv c++

作者:卍…`傷`   发布日期:2025-04-10   浏览:85

#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" << std::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>#include <iostream> 引入了 OpenCV 和标准输入输出流库。
  • 命名空间:使用 cvstd 命名空间,避免每次调用函数时都需要加上前缀。
  • 主函数main 函数是程序的入口点。
    • 检查命令行参数的数量是否正确(需要一个图像文件路径)。
    • 使用 imread 函数读取图像文件,并检查是否成功读取。
    • 创建一个窗口并显示图像。
    • 使用 waitKey(0) 等待用户按键关闭窗口。

这段代码展示了如何使用 OpenCV 读取、显示和处理图像的基本操作。

上一篇:c++ 单例模式

下一篇:c++ 协程

大家都在看

c++闭包

c++单引号和双引号的区别

c++ 注释

c++如何判断素数

c++ 获取系统时间

c++进制转换函数

c++ tcp

c++ gcd函数

c++ cli

c++ weak_ptr

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站