I`m trying to translate the code from OpenCV to EmguCV, but I do not go.
I want to detect red pixel in the image.
Please help.
Code: Select all
uchar* pixel_src;
uchar* pixel_dest;
height = frameCV->height;
width = frameCV->width;
for (i=0;i<height;i++){
for(j=0;j<width;j++){
pixel_src= &CV_IMAGE_ELEM(frameCV ,uchar,i,j*3);
pixel_dest= &CV_IMAGE_ELEM(frame_red,uchar,i,j*3);
double blue_point=(double)pixel_src[0];
double green_point=(double)pixel_src[1];
double red_point=(double)pixel_src[2];
//the ratio of red to green
double tmp1=red_point/(green_point+0.001);
//the ratio of red to blue
double tmp2=red_point/(blue_point+0.001);
if ((tmp1>parameter1)&&(tmp2>parameter2)&&(red_point>parameter3)) {
//detect red color
pixel_dest[0]=pixel_src[0];
pixel_dest[1]=pixel_src[1];
pixel_dest[2]=pixel_src[2];
}
else{
//color black
pixel_dest[0]=0;
pixel_dest[1]=0;
pixel_dest[2]=0;
}
}