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:
- First we create two Image Boxes, and one Button in the Windows Form.
- 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
- Now we are going to code. First we need to include the classes to be used. We write at the top of the code:
- Then, we need to declare the following instance variables:
private Capture capture;
private bool captureInProgress
- 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;
- 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();
if (capture != null)
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!