Click here to Skip to main content
12,826,151 members (26,789 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 23 Feb 2014

How to Process Image & Write Video Using EmguCV

, 23 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Video write and process image frames. This project has been made in EmguCV 2.4.9 version and Microsoft Visual Studio 2010 platform.

Processing Images

The following function processes the frame. Process frame extracts some details like frame number, time index, total frames. This function shows the images sequences in picture box.

frame = _capture.QueryFrame(); 

Frame is converted into bitmap and assigned to picture box to display.

pictureBox1.Image = frame.ToBitmap(); 

Function sleeps for a specified time with division of frame rate.

Thread.Sleep((int)(1000.0 / FrameRate)); 

Frame 1 gets converted into byte array. That byte array gets converted into hex values of each frame. Then that hex values are stored into the array list for further process.

string s1 = BitConverter.ToString(library.ConvertImageToByte(frame)); //.Replace("-", "");
private void ProcessFrame(object sender, EventArgs arg)
    Framesno = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
    frame = _capture.QueryFrame();
    if (frame != null)
      pictureBox1.Image = frame.ToBitmap();
      if (cam == 0)
        Video_CNTRL.Value = (int)(Framesno);
        double time_index = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_MSEC);
        Time_Label.Text = "Time: " + TimeSpan.FromMilliseconds(time_index).ToString().Substring(0, 8);
        double framenumber = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
        Frame_lbl.Text = "Frame: " + framenumber.ToString();
        Thread.Sleep((int)(1000.0 / FrameRate));
        TotalFrames = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
     string s1 = BitConverter.ToString(library.ConvertImageToByte(frame));
 catch (Exception ex)

Writing Video

For writing video, VideoWriter class is used. Videowriter class has a constructor with the following parameters:

  • File Name: Name of the output video file.
  • FPS: FrameRate of the created video stream.
  • Frame Width: Width Size of the video frames.
  • Frame Height: Height Size of the video frames.
  • IsColor – If it is false, video is created with grayscale frames, if it is true, video is created with color frames. (The flag is currently supported on Windows only).

For some functions, refer to my previous articles and tip/tricks:

private void button12_Click(object sender, EventArgs e)
    if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        textBox7.Text = saveFileDialog1.FileName;
        VW = new VideoWriter(textBox7.Text, 30,320, 240, true);
          foreach (String h in hex)
          MessageBox.Show("Video Generated Successfully", "Success");
        catch (Exception ex){ }

Points of Interest

  • Learn how to write the video using image sequence




Sorry for my English. If you notice errors or can suggest a more correct version, please let me know.


  • 23rd February, 2014 - First release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Opulent Infotech
India India
I am Soham Gandhi from India. I studied BE in Information Technology at University of Pune. ( I have been learning OpenCV, Enjoying it.
My research interest in Image Processing, Artificial Intelligence, Security Systems, Security Metrics. I work on OpenCV, EmguCV, Visual Studio 2008/10, Java platform.

Home Page (Blog)

You Tube Channel

You may also be interested in...


Comments and Discussions

QuestionWhere is the library.ConvertImageToByte Pin
Nutnaree Kleawsirikul15-Mar-15 23:22
memberNutnaree Kleawsirikul15-Mar-15 23:22 
AnswerRe: Where is the library.ConvertImageToByte Pin
SOHAM_GANDHI15-Mar-15 23:50
professionalSOHAM_GANDHI15-Mar-15 23:50 
QuestionAbout compression Pin
Jean-Philippe Encausse7-Jun-14 2:05
memberJean-Philippe Encausse7-Jun-14 2:05 
AnswerRe: About compression Pin
SOHAM_GANDHI7-Jun-14 3:30
memberSOHAM_GANDHI7-Jun-14 3:30 
GeneralHelpfull Pin
CHARLIE9126-May-14 20:37
memberCHARLIE9126-May-14 20:37 
GeneralRe: Helpfull Pin
jose ali6-Jun-14 10:30
memberjose ali6-Jun-14 10:30 
AnswerRe: Helpfull Pin
SOHAM_GANDHI6-Jun-14 19:44
memberSOHAM_GANDHI6-Jun-14 19:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 23 Feb 2014
Article Copyright 2014 by SOHAM_GANDHI
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid