📄 18-2.cpp
字号:
// ************************* 程序 18-2 ****************************
/*** 程序功能:
辨别黄绿色图像
// ***************************************************************/
//
/*
#include "cv.h"
#include "highgui.h"
int main ()
{
IplImage *img = 0;
img = cvLoadImage ( "test.jpg", 1 );
IplImage *image = reinterpret_cast<IplImage*> ( img ); //强制转换
int nl = image->height; //计算每个像素的高
int nc = image->width *image->nChannels;
int step = image->widthStep; // because of alignment //计算每个像素的宽度
// 因为imageData是signed char*,故要做强制转换
unsigned char * data = reinterpret_cast<unsigned char*> ( image->imageData );
for ( int i = 0; i < nl; i++ )
{
for ( int j = 0; j < nc; j += image->nChannels )
{
// 每个像素三通道
if ( data[j + 1] > data[j] && data[j + 1] > data[j + 2] )
// 对于绿色通道值大于其他两个通道的点,置白
{
data[j] = 0xFF; // 255
data[j + 1] = 0xFF;
data[j + 2] = 0xFF;
}
}
data += step; // 转至下一行
}
cvNamedWindow ( "dst", 1 );
cvShowImage ( "dst", image );
cvWaitKey ( 0 );
return 0;
}
//*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -