您的位置:首页 > 其它

改变图像的部分通道值(图像指针操作)

2010-07-13 16:45 260 查看
// 3_11.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cv.h>
#include <cvcam.h>
#include <cxcore.h>
#include <highgui.h>

#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"highgui.lib")

void Saturate_SV(IplImage *pSourceImage)
{
assert(pSourceImage != NULL);

for (int nHeight= 0; nHeight < pSourceImage->height; nHeight++ )
{
uchar *ptr = (uchar*)(pSourceImage->imageData + nHeight *pSourceImage->widthStep);
for (int nRow = 0; nRow < pSourceImage->width; nRow++)
{
ptr[nRow*3 +0] = 155;
ptr[nRow*3 +1] = 155;
}
}

}

int main(int argc, char* argv[])
{
IplImage *pSourceImage = cvLoadImage(argv[1]);
assert(pSourceImage != NULL);

IplImage *pDestImage = cvCloneImage(pSourceImage);
assert(pDestImage);

Saturate_SV(pDestImage);

cvNamedWindow("Show_Src");
cvNamedWindow("Show_Dst");

cvShowImage("Show_Src",pSourceImage);
cvShowImage("Show_Dst",pDestImage);

cvWaitKey();

cvReleaseImage(&pSourceImage);
cvReleaseImage(&pDestImage);
cvDestroyAllWindows();

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: