I'm working on an opencv 4.5.2 on windows10, my code is supposed to recognize colors. I met a porblem while scanning a simple picture 20x20 which the colour is defintely red.
when I run the following snippet
#include<opencv2/opencv.hpp>
#include<iostream>
const std::string imgpath = "C:\\Users\\nicola\\Desktop\\c++\\qt\\FaceScanner\\FaceScanner\\images\\";
int main()
{
cv::Mat origin = cv::imread(imgpath+"square_red.jpg");
cv::Mat hsv;
cv::cvtColor(origin, hsv, cv::COLOR_BGR2HSV);
cv::Scalar color = cv::mean(hsv);
std::cout << "HSV: " << color[0] << " " << color[1] << " " << color[2] << "\n";
color = cv::mean(origin);
std::cout << "BGR: " << color[0] << " " << color[1] << " " << color[2] << "\n";
}
the output I'm getting is
HSV: 88.4 251.532 238.768
BGR: 8.96 3.52 238.768
The problem is that this 2 colors are different because hsv(88, 251, 238) is a kind of green while bgr(8, 3, 238) is the red I'm expecting. To process the color I need it in the hsv color space. Can anybody fiugre this out? thank you in advance.