gpt4 book ai didi

python - HSV 值是否作为 VSH 存储在 numpy 数组中?

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:03 25 4
gpt4 key购买 nike

由于 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;
}

Red Image

输出:-

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,因此该值跨越 1 字节界限,仅允许 256 个值。在 opencv 中 HUE 除以 2 范围从 [0,179] 以使用更少的内存。色调值 358 除以 2 映射到第一个 channel 179。此外,饱和度和值只是标准化为 0-255 的比例。因此,正如您所见,饱和度映射到第二个 channel ,值映射到第三个 channel 。

关于python - HSV 值是否作为 VSH 存储在 numpy 数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39185277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com