【发布时间】:2017-01-21 18:45:07
【问题描述】:
我正在尝试在 HSV 颜色空间中分割绿色。我有这张树的图像,我只想留下树的上部。
这是我开始的图像,我获得的蒙版只是一张全黑的图像 这是我当前的代码:
Mat input = imread(image_location);
imshow("input img",input); waitKey(0);
//convert image to HSV
Mat input_hsv;
cvtColor(input,input_hsv,COLOR_BGR2HSV);
vector<Mat>channels;
split(input_hsv, channels);
Mat H = channels[0];
Mat S = channels[1];
Mat V = channels[2];
Mat mask2;
inRange(input_hsv, Scalar(70, 0, 0), Scalar(143, 255, 255), mask2);
imshow("mask2", mask2);waitKey(0);
通常 HSV 中的绿色范围为 +/- 70 到 140。 但它似乎根本不起作用。有人可以帮忙吗?
【问题讨论】:
-
尝试将RGB转换为HSV的公式编码为绿色
-
@JeruLuke 我不明白这有什么帮助。我现在刚刚在线完成了从 RGB 到 HSV 的转换。绿色的色调从 70 到 140,我允许饱和度和 S 分量为任意值。你介意解释一下你的意思吗?
-
*饱和度和 V 分量
标签: c++ image opencv image-processing