以下是对使用工具OpenCV在C++中创建单色空白图像的C++代码的说明。
要知道的事情:
(1)该代码仅在Linux环境中编译。
(2)要在Windows中运行,请使用文件“ blank.o”并在cmd中运行它。但是,如果它没有运行(系统体系结构中的问题),则可以通过对代码进行适当且明显的更改在Windows中对其进行编译,例如:使用
(3)编译命令:g ++ -w blank.cpp -o blank`pkg-config –libs opencv`
(4)运行命令:./ article
在运行代码之前,请确保已在系统上安装了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 << "\n Image not created. You"
" have done something wrong. \n";
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是印度学院的一名本科生瓦达达拉信息技术学院。他主要使用C++编写代码。他的座右铭是:到目前为止一切都很好。他打板球,看超级英雄电影,踢足球,并且是回答问题的忠实粉丝。
如果您还希望在此处展示您的博客,请参阅GBlog,以在GeeksforGeeks上撰写来宾博客。
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。