1. 程式人生 > >opencv2.4.9輸出把影象轉換成灰色

opencv2.4.9輸出把影象轉換成灰色

#include <stdio.h>
#include “stdafx.h”
#include"cv.h"
#include<highgui.h>
using namespace cv;
int main()
{
Mat image=imread(“pic.jpg”,1);
if (!image.data)
{
printf(“No image data \n”);
return -1;
}
Mat gray_image;
cvtColor(image,gray_image,CV_BGR2GRAY);
imwrite(“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;

}

在這裡插入圖片描述