如何检测 RGB 颜色中的白色?
我的意思是如何更改代码中的颜色或者我应该在代码中更改什么?
此代码检测红色:
#include"math.h"
#include"conio.h"
#include"cv.h"
#include"highgui.h"
#include"stdio.h"
int main() {
int i,j,k;
int height,width,step,channels;
int stepr, channelsr;
int temp=0;
uchar *data,*datar;
i=j=k=0;
IplImage *frame=cvLoadImage("red.jpg",1);
IplImage *result=cvCreateImage( cvGetSize(frame), 8, 1 );
if(frame==NULL ) {
puts("unable to load the frame");exit(0);
}
printf("frame loaded");
cvNamedWindow("original",CV_WINDOW_AUTOSIZE);
cvNamedWindow("Result",CV_WINDOW_AUTOSIZE);
height = frame->height;
width = frame->width;
step =frame->widthStep;
channels = frame->nChannels;
data = (uchar *)frame->imageData;
stepr=result->widthStep;
channelsr=result->nChannels;
datar = (uchar *)result->imageData;
for(i=0;i < (height);i++) for(j=0;j <(width);j++)
if(((data[i*step+j*channels+2]) > (29+data[i*step+j*channels])) &&
((data[i*step+j*channels+2]) > (29+data[i*step+j*channels+1])))
datar[i*stepr+j*channelsr]=255;
else
datar[i*stepr+j*channelsr]=0;
cvShowImage("original",frame);
cvShowImage("Result",result);
cvSaveImage("result.jpg",result);
cvWaitKey(0);
cvDestroyWindow("original");
cvDestroyWindow("Result");
return 0;
}