ridx = k;
}
}
cout<
float bin_val = cvQueryHistValue_1D(g_hist,i);
int intensity = cvRound(bin_val*hist_height/gmax_value);
cvRectangle(hist_image,cvPoint(i*scale,2*hist_height),cvPoint((i+1)*scale - 1, 2*hist_height - intensity),CV_RGB(0,255,0));
float k = i*255.f/hist_size;
if (gmax
gmax = bin_val;
gidx = k;
}
}
cout<
float bin_val = cvQueryHistValue_1D(b_hist,i);
int intensity = cvRound(bin_val*hist_height/bmax_value);
cvRectangle(hist_image,cvPoint(i*scale,3*hist_height),cvPoint((i+1)*scale - 1, 3*hist_height - intensity),CV_RGB(0,0,255));
float k = i*255.f/hist_size;
if (bmax
bmax = bin_val;
bidx = k;
}
}
cout<
//颜色判断及匹配
float velue[] = {ridx,gidx,bidx};
float dmin = 100000; //保存最小的距离
int colorIdx = 0;
for(int i=0 ; i
float d = sqrt(pow(colorVelue[i][0]-velue[0],2)+pow(colorVelue[i][1]-velue[1],2)+pow(colorVelue[i][2]-velue[2],2));
if (dmin > d)
{
dmin = d;
colorIdx = i;
}
}
cout<<"colorIdx:"<
abs(ridx-gidx)<30&&abs(ridx-bidx)<30&&(gidx-bidx)<30)
{
type = 12;
}
else
type = colorIdx;
//cvDestroyWindow("hsv");
cvReleaseImage(&R);
cvReleaseImage(&G);
cvReleaseImage(&B);
cvReleaseImage(&hist_image);
cvReleaseHist(&r_hist);
cvReleaseHist(&g_hist);
cvReleaseHist(&b_hist);
return type;
}
int main(int argc, _TCHAR* argv[])
{
cvNamedWindow( "color recognition", 1 );//建立视频窗口
IplImage* src = cvLoadImage("D:\\tu\\U17328_20091230235830314-2.jpg");
//读图像//
image = cvCreateImage( cvGetSize(src), 8, 3 );
//cvCopy(src,image);
cvResize(src,image);
cvShowImage( "color recognition", image );//显示视频和直方图
cvWaitKey(1000);
cvSetMouseCallback( "color recognition", on_mouse ); // 设置鼠标回调函数
////车牌区域选择函数//
for ( int i=0;i<4;i++ )
{
if ( mark )
{
cout<<"区域坐标:"<<"x:"<
cvWaitKey(1000);
cvRectangle( image,cvPoint(r.x,r.y ),cvPoint( r.x+r.width,r.y+r.height ),cvScalar(255,0,255) ,2, 8, 0);
cvShowImage( "color recognition", image );
}
cvShowImage( "color recognition", image );
cout<<"selection is ok"<
//颜色匹配识别//
int j;
j = Color_difference_RGB(src,r); //返回颜色类型
cout<<"j:"<
{
case -1:
cout<<"please select ROI first!"<
case 0:
cout<<"the colorof thiscar is:黑"<
case 1:
cout<<"the colorof thiscar is:白"<
case 2:
cout<<"the colorof thiscar is:红"<
case 3:
cout<<"the colorof thiscar is:红"<
case 4:
cout<<"the colorof thiscar is:绿"<
case 5:
cout<<"the colorof thiscar is:绿"<
case 6:
cout<<"the colorof thiscar is:蓝"<
case 7:
cout<<"the colorof thiscar is:蓝"<
case 8:
cout<<"the colorof thiscar is:黄"<
case 9:
cout<<"the colorof thiscar is:黄"<
case 10:
cout<<"the colorof thiscar is:棕"<
case 11 :
cout<<"the colorof thiscar is:灰"<
default:
cout<<"the colorof thiscar is:其他"<
cvWaitKey(0);
cvReleaseImage(&image);
cvReleaseImage(&src);
cvDestroyWindow("color recognition");
return 0;
}