Program to output the coordinates of all white pixels in a binary mat?

asked 2018-09-16 16:17:11 -0500

Hello, this might be basic, but I can't find the simple answer anywhere. I have a mat ( see example code) going through an HSV filter to the color I want to detect, which is great, I get a highlighted binary (black and white) image of the region I want. Then, I want to create a new array or mat of the coordinates of each pixel that is lit white (or black) so I can calculate the average coordinate of each pixel. Here's my (relevant section of) code so far. What would be the next step?

        double resizeImageWidth = 640.0;
        double resizeImageHeight = 480.0;
        int resizeImageInterpolation = Imgproc.INTER_CUBIC;
        resizeImage(m, resizeImageWidth, resizeImageHeight, resizeImageInterpolation, resizeImageOutput);

        double[] hsvThresholdHue = {0.0, 61.587455090159565};
        double[] hsvThresholdSaturation = {116.95143884892086, 255.0};
        double[] hsvThresholdValue = {0.0, 255.0};
        hsvThreshold(resizeImageOutput, hsvThresholdHue, hsvThresholdSaturation, hsvThresholdValue, 
        hsvThresholdOutput);
edit retag flag offensive close merge delete

Comments

next step, (ofc...) is: browse DOCS and find: https://docs.opencv.org/master/javado...

berak gravatar imageberak ( 2018-09-16 17:35:59 -0500 )edit
1

I think you meant to link findNonZero. You can also get the answer you want directly, though you don't quite describe your problem well enough to tell if you want the average of each white area or all of them. (connectedComponentsWithStats, and moments, respectively).

Tetragramm gravatar imageTetragramm ( 2018-09-16 19:14:19 -0500 )edit