OpenCV C++ Program to blur a Video Last Updated : 23 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The following is the explanation to the C++ code to blur a video in C++ using the tool OpenCV. Things to know: (1) The code will only compile in Linux environment. (2) To run in windows, please use the file: 'blur_video.o' and run it in cmd. However if it does not run(problem in system architecture) then compile it in windows by making suitable and obvious changes to the code like: Use <iostream.h> in place of <iostream>. (3) Compile command: g++ w blur_vid.cpp o blur_vid `pkgconfig libs opencv` (4) Run command: ./blur_vid (5) The video Bumpy.mp4 has to be in the same directory as the code. Before you run the code, please make sure that you have OpenCV installed on your // system. Code Snippets Explained: C++ #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. \n"; 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<<"\n Cannot read the video file. \n"; 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 Comment More infoAdvertise with us Next Article OpenCV C++ Program to blur a Video K kartik Follow Improve Article Tags : Project C++ OpenCV Practice Tags : CPP Similar Reads OpenCV C++ Program to play a video The following is the explanation to the C++ code to play a video in C++ using the tool OpenCV. Things to know: (1) The code will only compile in Linux environment. (2) To run in windows, please use the file: 'play_video.o' and run it in cmd. However if it does not run(problem in system architecture) 3 min read OpenCV C++ Program to blur an image The following is the explanation to the C++ code to blur an Image in C++ using the tool OpenCV. Things to know: (1) The code will only compile in Linux environment. (2) Compile command: g++ -w article.cpp -o article `pkg-config --libs opencv` (3) Run command: ./article (4) The image bat.jpg has to b 5 min read Python | Play a video using OpenCV OpenCV (Open Source Computer Vision) is a computer vision library that contains various functions to perform operations on Images or videos. OpenCV library can be used to perform multiple operations on videos. Letâs see how to play a video using the OpenCV Python. To capture a video, we need to crea 2 min read Python OpenCV: Capture Video from Camera Python provides various libraries for image and video processing. One of them is OpenCV. OpenCV is a vast library that helps in providing various functions for image and video operations. With OpenCV, we can capture a video from the camera. It lets you create a video capture object which is helpful 4 min read Python - Process images of a video using OpenCV Processing a video means, performing operations on the video frame by frame. Frames are nothing but just the particular instance of the video in a single point of time. We may have multiple frames even in a single second. Frames can be treated as similar to an image.So, whatever operations we can pe 4 min read Like