IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
第二个参数的具体意思为:
– >0 Return a 3-channel color image
– =0 Return a grayscale image
– <0 Return the loaded image as is. Note that in the current implementation the alpha
channel, if any, is stripped from the output image. For example, a 4-channel RGBA
image is loaded as RGB if flags 0 .
所以在此代码中加入了先把rgb图转化成灰度图在继续复制和保存。
代码如下:
// 1.1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include"opencv243.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
IplImage* pImg; //声明IplImage指针
pImg = cvLoadImage( "C:\\Users\\sony\\Desktop\\Lena.jpg", 0);
//载入图像,强制转化为Gray
if( !pImg==0 )
{
IplImage* pImg2 = cvCreateImage(cvGetSize(pImg),pImg->depth,pImg->nChannels);
cvCopy(pImg, pImg2, NULL);
cvSaveImage("C:\\Users\\sony