Hi guys, I’ve been away some weeks but now I’m back.

In this entry, we are going to apply a Color Conversion (from RGB to Grayscale). Before you start working on this Tutorial, you should have looked at this entry in order to configure Visual Studio.

Once the environment has been configured, we can start:

  1. First we create two Image Boxes, and one Button in the Windows Form.
  2. We name the button as btnStart and the two Image Boxes as following: the one on the left will be frameCamera and the one on the right will be frameGrayscale
  3. Now we are going to code. First we need to include the classes to be used. We write at the top of the code:

    using Emgu.CV;
    using Emgu.CV.Structure;
    using Emgu.Util;

  4. Then, we need to declare the following instance variables:

    private Capture capture;
    private bool captureInProgress

  5. Now we implement a method called convertFrameToGray:

    Mat imageCaptured = capture.QueryFrame();
    frameCamera.Image = imageCaptured;

    Image<Gray, Byte> imageGrayscale = imageCaptured.ToImage<Gray, Byte>();
    frameGrayscale.Image = imageGrayscale;

  6. At last, implement the functionality of the Start button. You can do this by double clicking the button and implement the following code in the callback function:

    if (capture == null)
    capture = new Capture();
    catch(NullReferenceException excpt)
    if (capture != null)
    if (captureInProgress)
    btnStart.Text = “Start”;
    Application.Idle -= processFrame;
    btnStart.Text = “Pause”;
    Application.Idle += processFrame;
    captureInProgress = !captureInProgress;

Now we can run our application. The original captured image, displayed in the left side and in color, is now displayed on grayscale at the right side of the application.

Thank you very much for looking at this tutorial. As you can see, they are quite simple but will allow you to get familiar with the development of Windows Forms and some basic functionality of the OpenCV library.

The next tutorial will show you how to work with some inRange filtering!