Showing posts with label Modify. Show all posts
Showing posts with label Modify. Show all posts

Thursday, November 7, 2019

[OpenCV Tutorial] $2 - Load, Modify, and Save an Image

Goals

In this tutorial you will learn how to:
  • Load an image using cv::imread
  • Transform an image from BGR to Grayscale format by using cv::cvtColor
  • Save your transformed image in a file on disk (using cv::imwrite )

Code

Here it is:
#include <opencv2/opencv.hpp>
#include "string"

using namespace cv;
int main( int argc, char** argv )
{
String imageName = "Color_Image.jpg";
Mat image;
image = imread( imageName, 1 );
Mat gray_image;
cvtColor( image, gray_image, COLOR_BGR2GRAY );
imwrite( "Gray_Image.jpg", gray_image );
namedWindow( "Gray image", WINDOW_AUTOSIZE );
imshow( imageName, image );
imshow( "Gray image", gray_image );
waitKey(0);
return 0;
}

Back to Top