使用cvInRangeS(hsvframe,cvScalar(90, 40, 50)
和cvScalar(255, 90, 255),threshy)
,
如何获得每种颜色(紫色和黄色)的确切值范围?
答案 0 :(得分:1)
使用color picker web-site检查它们的色调值。
http://www.color-hex.com/color/eca314
http://www.color-hex.com/color/923ca7
请注意,您需要在(0-255)范围之间转换色调角度(0-360)。对两种颜色使用inranges函数并添加图像:
cvInRangeS(hsvframe,cvScalar(20, 0, 0), cvScalar(30, 255, 255),threshorange);
cvInRangeS(hsvframe,cvScalar(200, 0, 0), cvScalar(210, 255, 255),threshpurple);
cvOr(threshorange, threshpurple, threshy);
答案 1 :(得分:1)
你可能想试试这个:
Mat matSrcCopyForHSVColorDisplay, HSV_image_display;
//Make a copy of the original image
matSrcCopyForHSVColorDisplay = matSrc.clone();
//Convert RGB to HSV
cvtColor(matSrc, HSV_image_display, CV_BGR2HSV);
//To access each pixel in the images we are using this syntax:
//image.at(y,x)[c] where y is the row, x is the column
//and c is H, S or V (0, 1 or 2)
Vec3b p = HSV_image_display.at<Vec3b>(50, 10); //Vec3b - Array of 3 uchar numbers
//p[0] - H, p[1] - S, p[2] - V
printf(text, "H=%d, S=%d, V=%d", p[0], p[1], p[2]);
//putText(matSrcCopyForHSVColorDisplay, text, Font_Position,
//Font_Type, Font_Scale, Font_Colour, Font_Thickness);
//Display the text
putText(matSrcCopyForHSVColorDisplay, text, center,
FONT_HERSHEY_COMPLEX_SMALL, 2, cvScalar(255, 0, 0), 1, CV_AA);
//Refresh the image
imshow("HSV Value", matSrcCopyForHSVColorDisplay);
printf("H=%d, S=%d, V=%d\n", p[0], p[1], p[2]);