OpenCV C++程序创建单色空白图像

下面是C++代码的解释,用C++工具OpenCV创建一个C++中的单色空白图像。

null

需要知道的事情:

(1) 该代码只能在Linux环境下编译。

(2) 要在windows中运行,请使用文件:“blank”。o’并在cmd中运行它。但是,如果它没有运行(系统架构中的问题),则在windows中通过对代码进行适当且明显的更改来编译它,例如:Use 代替

(3) 编译命令:g++-w blank。cpp-o blank`pkg config–libs opencv`

(4) 运行命令:/文章

在运行代码之前,请确保系统上安装了OpenCV。

代码片段:

// Title: Create a coloured image in C++ using OpenCV.

// highgui - an easy-to-use interface to 
// video capturing, image and video codecs,
// as well as simple UI capabilities.
#include "opencv2/highgui/highgui.hpp"

// Namespace where all the C++ OpenCV 
// functionality resides. 
using namespace cv;

// For basic input / output operations. 
// Else use macro 'std::' everywhere.
using namespace std;

int main()
{
    // To create an image
    // CV_8UC3 depicts : (3 channels,8 bit image depth
    // Height  = 500 pixels, Width = 1000 pixels
    // (0, 0, 100) assigned for Blue, Green and Red 
    //             plane respectively. 
    // So the image will appear red as the red 
    // component is set to 100.
    Mat img(500, 1000, CV_8UC3, Scalar(0,0, 100));
    
    // check whether the image is loaded or not
    if (img.empty()) 
    {
        cout << " Image not created. You"
                     " have done something wrong. ";
        return -1;    // Unsuccessful.
    }

    // first argument: name of the window
    // second argument: flag- types: 
    // WINDOW_NORMAL If this is set, the user can 
    //               resize the window.
    // WINDOW_AUTOSIZE If this is set, the window size
    //                is automatically adjusted to fit 
    //                the displayed image, and you cannot
    //                change the window size manually.
    // WINDOW_OPENGL  If this is set, the window will be
    //                created with OpenGL support.
    namedWindow("A_good_name", CV_WINDOW_AUTOSIZE);

    // first argument: name of the window
    // second argument: image to be shown(Mat object)
    imshow("A_good_name", img);
    
    waitKey(0); //wait infinite time for a keypress

    // destroy the window with the name, "MyWindow"
    destroyWindow("A_good_name");            

    return 0;
}
// END OF PROGRAM

以前的职位: https://www.geeksforgeeks.org/opencv-c-program-to-blur-an-image/

关于作者:

Aditya Prakash是印度学院的本科生 Aditya 信息技术部,瓦多达拉。他主要是用C++编写代码。他的座右铭是:迄今为止一切顺利。他打板球,看超级英雄电影,踢足球,并且是回答问题的超级粉丝。

如果你也想在这里展示你的博客,请参见 吉微博 在Geeksforgek上写客博。

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享