Load, Modify, and Save an Image
Goals:
In this tutorial you will learn how to:
Load an image using imread
Transform an image from RGB to Grayscale format by using cvtColor
Save your transformed image in a file on disk (using imwrite)
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
char* imageName = argv[1];
Mat image;
image = imread( imageName, 1 );
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
return -1;
}
Mat gray_image;
cvtColor( image, gray_image, CV_RGB2GRAY );
imwrite( "../../images/Gray_Image.jpg", gray_image );
namedWindow( imageName, CV_WINDOW_AUTOSIZE );
namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );
imshow( imageName, image );
imshow( "Gray image", gray_image );
waitKey(0);
return 0;
}

本文介绍了一个使用C++和OpenCV实现的简单程序,该程序可以加载图像、将其从RGB格式转换为灰度格式,并将转换后的图像保存到磁盘上。此外,程序还展示了如何使用OpenCV显示原始图像及其灰度版本。
1409

被折叠的 条评论
为什么被折叠?



