我将rgb图像转换为hsv
我使用函数inRange()来检测图像中的红色
现在我想识别颜色而不是检测: - 我想将色调值与红色范围进行比较..如果它位于其中...打印红色 否则如果它在蓝色范围内说蓝色......那么
如果比较Mat hue,如果它在100到180之间
int main()
{
Mat image;
image = imread("C:/Users/Maram/Documents/Visual Studio 2013/Projects/firsttrialw310/x64/Debug/carcolor.png", CV_LOAD_IMAGE_COLOR);
if (!image.data)
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
// Create a new matrix to hold the HSV image
Mat HSV;
// convert RGB image to HSV
cvtColor(image, HSV, CV_RGB2HSV);
namedWindow("Display window", CV_WINDOW_AUTOSIZE);
imshow("Display window", image);
namedWindow("Result window", CV_WINDOW_AUTOSIZE);
imshow("Result window", HSV);
vector<Mat> hsv_planes;
split(HSV, hsv_planes);
Mat h = hsv_planes[0]; // H channel
Mat s = hsv_planes[1]; // S channel
Mat v = hsv_planes[2]; // V channel
namedWindow("hue", CV_WINDOW_AUTOSIZE);
imshow("hue", h);
namedWindow("saturation", CV_WINDOW_AUTOSIZE);
imshow("saturation", s);
namedWindow("value", CV_WINDOW_AUTOSIZE);
imshow("value", v);
//// red color range
Scalar hsv_l(100, 150, 150);
Scalar hsv_h(180, 255, 255);
Mat bw;
inRange(HSV, hsv_l, hsv_h, bw);
imshow("Specific Colour", bw);
////
//black cv::Scalar(0, 0, 0, 0), cv::Scalar(180, 255, 40, 0)
//white cv::Scalar(0, 0, 80, 0), cv::Scalar(180, 255, 255, 0)
waitKey(0);
return 0;
}