0

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. Is there another way to do it?

Threshold result:

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:

Masking Image

HansHirse
  • 18,010
  • 10
  • 38
  • 67
  • You have the `frame_mask` & `frame_out` variables which contain the data for your masking image & mask respectively. So, a simple iteration over the variable's contents can help you to read the pixel values. For detailed info. on that you can visit [here](https://docs.opencv.org/4.0.0/db/da5/tutorial_how_to_scan_images.html). – Argon Jun 25 '19 at 05:09

1 Answers1

0

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
Mance Rayder
  • 353
  • 2
  • 10