以下是使用工具OpenCV对C++中的Image进行模糊处理的C++代码的说明。
要知道的事情:
(1)该代码仅在Linux环境中编译。
(2)编译命令:g ++ -w article.cpp -o article`pkg-config –libs opencv`
(3)运行命令:./ article
(4)图像bat.jpg必须与代码位于同一目录中。
在运行代码之前,请确保已在系统上安装了OpenCV。
// Title: OpenCV C++ Program to blur an image.
// Import the core header file
#include
// 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
// 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
// The stdio.h header defines three variable types,
// several macros, and various functions for performing
// input and output.
#include
#include
// 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.\n";
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
}
OpenCV Python程序来模糊图像
关于作者:
Aditya Prakash是印度学院的一名本科生瓦达达拉信息技术学院。他主要使用C++编写代码。他的座右铭是:到目前为止一切都很好。他打板球,看超级英雄电影,踢足球,并且是回答问题的忠实粉丝。
如果您还希望在此处展示您的博客,请参阅GBlog,以在GeeksforGeeks上撰写访客博客。
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。