In this tutorial you will learn how to:
Here it is:
We begin by:
Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations:
cvtColor( image, gray_image, CV_BGR2GRAY );
As you can see, :cvt_color:`cvtColor <>` takes as arguments:
So now we have our new gray_image and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to :imread:`imread <>`: :imwrite:`imwrite <>`
imwrite( "../../images/Gray_Image.jpg", gray_image );
Which will save our gray_image as Gray_Image.jpg in the folder images located two levels up of my current location.
Finally, let's check out the images. We create two windows and use them to show the original image as well as the new one:
namedWindow( imageName, CV_WINDOW_AUTOSIZE ); namedWindow( "Gray image", CV_WINDOW_AUTOSIZE ); imshow( imageName, image ); imshow( "Gray image", gray_image );
Add the waitKey(0) function call for the program to wait forever for an user key press.
When you run your program you should get something like this:
And if you check in your folder (in my case images), you should have a newly .jpg file named Gray_Image.jpg:
Congratulations, you are done with this tutorial!