Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guide to process a video

Tags:

c++

opencv

I'm just started to process images from the video instead of still image. What is the proper way of doing it?

  1. Do we usually process every frame of image?
    • means, if I want to change the RGB to HSV colour space etc. what do people usually do here?

Need some guide here since I've no experience in video processing.

Thanks all.

EDIT: Does anyone know why there is a significant lag between the video processed in opencv compared to original video even though it's just converting from RGB to HSV?

like image 671
Mzk Avatar asked May 14 '26 08:05

Mzk


1 Answers

Video processing is always done frame by frame. e.g. if you want to convert RGB video to HSV, you will do the following procedure:

  1. Open A Video File.
  2. Read a color frame (RGB frame).
  3. Convert the frame from RGB to HSV color space.
  4. Do whatever you want with the converted frame.
  5. Go to step 2.

UPDATE:

C++ sample code for Converting RGB video to HSV:

#include<iostream>
#include<string>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

using namespace std;

int main()
{
   cv::VideoCapture capture;
   cv::Mat RGB, HSV;

   string videoPath = "C:/video.avi";

   if(!capture.open(videoPath))
   {
     cout<<"Video Not Found"<<endl;
     return;
   }

    while(true)
    {
       capture>>RGB;  //Read a frame from the video

       if(RGB.empty()) //Check if the frame has been read correctly or not
       {
          cout<<"Capture Finished"<<endl;
          break;
       }

       cv::cvtColor(RGB,HSV,CV_BGR2HSV);

       cv::imshow("HSV Image",HSV);
       cv::waitKey(10);
    }

    capture.release();
    return 0;
}

The color conversion function may require preallocating the memory for HSV. Read the documentation Here.

like image 137
sgarizvi Avatar answered May 16 '26 21:05

sgarizvi