下面是使用C++ OpenCV对C++中的视频进行模糊编码的说明。
null
需要知道的事情:
(1) 该代码只能在Linux环境下编译。
(2) 要在windows中运行,请使用文件:“blur_video”。o’并在cmd中运行它。但是,如果它没有运行(系统架构中的问题),则在windows中通过对代码进行适当且明显的更改来编译它,例如:Use
(3) 编译命令:g++-w blur_vid。cpp-o blur_vid `pkg-configlibs opencv`
(4) 运行命令:/模糊视频
(5) 视频有点颠簸。mp4必须与代码位于同一目录中。
在运行代码之前,请确保在//系统上安装了OpenCV。
解释代码片段:
#include "opencv2/highgui/highgui.hpp" // highgui - an interface to video and image capturing. #include <opencv2/imgproc/imgproc.hpp> // For dealing with images #include <iostream> // The header files for performing input and output. using namespace cv; // Namespace where all the C++ OpenCV functionality resides. using namespace std; // For input output operations. int main() { VideoCapture cap("Bumpy.mp4"); // cap is the object of class video capture that tries to capture Bumpy.mp4 if ( !cap.isOpened() ) // isOpened() returns true if capturing has been initialized. { cout << "Cannot open the video file. "; return -1; } double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video // The function get is used to derive a property from the element. // Example: // CV_CAP_PROP_POS_MSEC : Current Video capture timestamp. // CV_CAP_PROP_POS_FRAMES : Index of the next frame. namedWindow("A_good_name",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo" // first argument: name of the window. // second argument: flag- types: // WINDOW_NORMAL : The user can resize the window. // WINDOW_AUTOSIZE : The window size is automatically adjusted to //fit the displayed image() ), and you cannot change the window size manually. // WINDOW_OPENGL : The window will be created with OpenGL support. while(1) { Mat frame; // Mat object is a basic image container. frame is an object of Mat. if (!cap.read(frame)) // if not success, break loop // read() decodes and captures the next frame. { cout<<" Cannot read the video file. "; break; } blur(frame,frame,Size(10,10)); // To blur the image. imshow("A_good_name", frame); // first argument: name of the window. // second argument: image to be shown(Mat object). if(waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } return 0; } // END OF PROGRAM
关于作者:
Aditya Prakash是印度学院的本科生 信息技术部,瓦多达拉。他主要是用C++编写代码。他的座右铭是:迄今为止一切顺利。他打板球,看超级英雄电影,踢足球,并且是回答问题的超级粉丝。
如果你也想在这里展示你的博客,请参见 吉微博 在Geeksforgek上写客博。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END