4,446
社区成员
发帖
与我相关
我的任务
分享
判断红色图片
IplImage* pImg_test = cvLoadImage("red7.jpg",1);;
int r, g, b;
int intRedCount = 0;
int intS = 0;
for(int x = 0; x < pImg_test->width; x++)
{
for(int y = 0; y < pImg_test->height; y++)
{
r = CV_IMAGE_ELEM(pImg_test, uchar, y, x * 3 + 2);
g = CV_IMAGE_ELEM(pImg_test, uchar, y, x * 3 + 1);
b = CV_IMAGE_ELEM(pImg_test, uchar, y, x * 3);
if ((r >= 210) && (130 > g ) && (g > 110) && (150 > b ) && (b > 130))
{
intRedCount++;
}
}
}
if (intRedCount >= 5)
{
AfxMessageBox("r==255,现在是红色信号灯\n");
}