由于 RGB 存储为 BGR,在 HSV 的情况下也会发生同样的情况吗?
我正在制作一个项目,我从网络摄像头获取输入并将其转换为 HSV 颜色,以跟踪特定颜色的对象。
最佳答案
不,这是 HSV 模式。
阅读以下代码并在示例图像上运行。
int main()
{
// Load your Red colored image
cv::Mat frame = imread("test.png");
// Split each channel
cv::Mat rgbChannels[3];
cv::split(frame, rgbChannels);
cv::imshow("RGB", frame);
// Check value of your Red, Blue and Green Channel
double minVal, maxVal;
// Note: Blue is first channel
cv::minMaxLoc(rgbChannels[0], &minVal, &maxVal);
std::cout << "Blue: Min = " << minVal << ", Max = " << maxVal << std::endl;
cv::minMaxLoc(rgbChannels[1], &minVal, &maxVal);
std::cout << "Green: Min = " << minVal << ", Max = " << maxVal << std::endl;
cv::minMaxLoc(rgbChannels[2], &minVal, &maxVal);
std::cout << "Red: Min = " << minVal << ", Max = " << maxVal << std::endl;
std::cout << "*******************************" << std::endl;
cv::Mat hsv;
cv::Mat hsvChannels[3];
// Convert BGR image to HSV. Dont use CV_RGB2HSV.
cv::cvtColor(frame, hsv, CV_BGR2HSV);
// Split each channel
cv::split(hsv, hsvChannels);
// **Display HSV image: Note: When displaying opencv does not display image as Red image**
// This is because imshow will just take first channel which is hue and treat it as Blue, second channel as
// Green, and last channel as Red.
cv::imshow("HSV", hsv);
cv::minMaxLoc(hsvChannels[0], &minVal, &maxVal);
std::cout << "Hue: Min = " << minVal << ", Max = " << maxVal << std::endl;
cv::minMaxLoc(hsvChannels[1], &minVal, &maxVal);
std::cout << "Saturation: Min = " << minVal << ", Max = " << maxVal << std::endl;
cv::minMaxLoc(hsvChannels[2], &minVal, &maxVal);
std::cout << "Value: Min = " << minVal << ", Max = " << maxVal << std::endl;
waitKey(0);
return 0;
}
输出:-
Blue: Min = 36, Max = 36
Green: Min = 28, Max = 28
Red: Min = 237, Max = 237
*******************************
Hue: Min = 179, Max = 179
Saturation: Min = 225, Max = 225
Value: Min = 237, Max = 237
输出说明
使用此 tool ,RGB 值 (237, 28, 36) 映射到 HSV (358, 88.2, 92.9)。由于 HUE 的范围从 0 到 359,因此该值超过了仅允许 256 个值的 1 字节界限。 HUE 除以 2,范围从 opencv 中的 [0,179] 以使用更少的内存。色调值 358 除以 2 映射到 179,这是第一个 channel 。此外,饱和度和值只是标准化为 0-255。因此,如您所见,饱和度映射到第二个 channel ,值映射到第三个 channel 。
关于python - HSV 值是否作为 VSH 存储在 numpy 数组中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39185277/