简体   繁体   English

如何从阈值结果中获取颜色值?

[英]How to get a color value from threshold result?

I have made a threshold in the image. 我在图像中设置了一个阈值。 Then I want to get the value of the image (black and white). 然后我想得到图像的值(黑色和白色)。 I've tried using frame_hsv.at<Vec3b>(x, y) but it can't. 我尝试过使用frame_hsv.at<Vec3b>(x, y)但它不能。 Is there another way to do it? 还有另一种方法吗?

Threshold result: 门槛结果:

门槛结果

I did a threshold to detect objects based on color. 我做了一个阈值来检测基于颜色的对象。

My code : 我的代码:

Mat frame, frame_HSV, frame_gr, frame_wh, frame_out, img_final, 
frame_mask;
const double PI = 3.14159265;

int main(int argc, char* argv[])
{
    frame = imread("dasar/vlcsnap-error067.png");
    cvtColor(frame, frame_HSV, COLOR_BGR2HSV);

    inRange(frame_HSV, Scalar(44, 65, 97), Scalar(90, 196, 239), frame_gr);
    Mat el_dilate = getStructuringElement(MORPH_ELLIPSE, Size(10, 10));
    dilate(frame_gr, frame_gr, el_dilate);

    inRange(frame_HSV, Scalar(5, 0, 192), Scalar(70, 73, 255), frame_wh);

    frame_wh.copyTo(frame_out, frame_gr);
    frame.copyTo(frame_mask, frame_gr);

    imshow("GREEN (MASK)", frame_gr);
    imshow("WHITE (OBJECT)", frame_wh);
    imshow("MASK + OBJECT", frame_out);
    imshow("ORIGINAL", frame);
    imshow("MASK + ORIGINAL", frame_mask);
    waitKey(0);
}

If possible, I also want to read the color values in the masking image (black and color). 如果可能,我还想读取遮罩图像中的颜色值(黑色和彩色)。

Masking image: 掩蔽图像:

掩盖图像

You can do: 你可以做:

cvtColor(frame, frame_HSV, COLOR_BGR2HSV);
...
Vec3b hsv = frame_HSV.at<Vec3b>(x, y);
int H = hsv.val[0]; //hue
int S = hsv.val[1]; //saturation
int V = hsv.val[2]; //value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM