下面是用C++ OpenCV工具对C++中的图像进行模糊处理的说明。
null
需要知道的事情:
(1) 该代码只能在Linux环境下编译。
(2) 编译命令:g++-w文章。cpp-o文章`pkg config–libs opencv`
(3) 运行命令:/文章
(4) 图像蝙蝠。jpg必须与代码位于同一目录中。
在运行代码之前,请确保系统上安装了OpenCV。
// Title: OpenCV C++ Program to blur an image. // Import the core header file #include <opencv2/core/core.hpp> // core - a compact module defining basic data structures, // including the dense multi-dimensional array Mat and // basic functions used by all other modules. // highgui - an easy-to-use interface to video // capturing, image and video codecs, as well // as simple UI capabilities. #include <opencv2/highgui/highgui.hpp> // imgproc - an image processing module that // includes linear and non-linear image filtering, // geometrical image transformations (resize, affine // and perspective warping, generic table-based // remapping) color space conversion, histograms, // and so on. #include <opencv2/imgproc/imgproc.hpp> // The stdio.h header defines three variable types, // several macros, and various functions for performing // input and output. #include <stdio.h> #include <iostream> // Namespace where all the C++ OpenCV functionality resides using namespace cv; using namespace std; // We can also use 'namespace std' if need be. int main() // Main function { // read the image data in the file "MyPic.JPG" and // store it in 'img' Mat image = imread("bat.jpg", CV_LOAD_IMAGE_UNCHANGED); // Mat object is a basic image container. // imread: first argument denotes the image to be loaded // the second arguments specifies the image format. // CV_LOAD_IMAGE_UNCHANGED (<0) loads the image as is // CV_LOAD_IMAGE_GRAYSCALE ( 0) loads the image as an // intensity one // CV_LOAD_IMAGE_COLOR (>0) loads the image in the // BGR format // If the second argument is not specified, it is // implied CV_LOAD_IMAGE_COLOR // Check for no data if (! image.data ) { cout << "Could not open or find the image."; return -1; // unsuccessful } // Function to blur the image // first argument: input source // second argument: output source // third argument: blurring kernel size blur(image,image,Size(10,10)); // Create a window // 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( "bat", CV_WINDOW_AUTOSIZE ); // Displays an image in the specified window. // first argument: name of the window // second argument: image to be shown(Mat object) imshow( "bat", image ); waitKey(0); // Wait infinite time for a keypress return 0; // Return from the main function }
关于作者:
Aditya Prakash是印度学院的本科生 信息技术部,瓦多达拉。他主要是用C++编写代码。他的座右铭是:迄今为止一切顺利。他打板球,看超级英雄电影,踢足球,并且是回答问题的超级粉丝。
如果你也想在这里展示你的博客,请参见 吉微博 在Geeksforgek上写客博。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END