I am trying to detect range of Red color using C++ and OpenCV. I have converted my image from cv::COLOR_BGR2HSV colorspace already. Now I am trying to convert a single color from BGR to HSV colorspace using the code below:
cv::Mat3f red_lower(cv::Vec3f(54, 41, 203)); // BGR
cv::Mat3f red_upper(cv::Vec3f(123, 109, 255));// BGR
cv::Mat3f red_lower_hsv, red_upper_hsv;
LOG("red_lower: " << red_lower);
cv::cvtColor(red_lower, red_lower_hsv, cv::COLOR_BGR2HSV);
LOG("red_lower_hsv: " << red_lower_hsv);
LOG("red_upper: " << red_upper);
cv::cvtColor(red_upper, red_upper_hsv, cv::COLOR_BGR2HSV);
LOG("red_upper_hsv: " << red_upper_hsv);
// get mask
cv::inRange(image_hsv, red_lower_hsv, red_upper_hsv, OutputImage);
The output I get is:
red_lower: [54, 41, 203]
red_lower_hsv: [355.18518, 0.79802954, 203]
red_upper: [123, 109, 255]
red_upper_hsv: [354.24658, 0.57254905, 255]
The values are not correct and the image mask is not generated. I even tried with a simple image with just two red boxes.