Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why doesn't the inRange() function detect this little red colored blob in this 50px Mat?

I created the following 50px by 50px image in Adobe PS, and the red circle has an HSV value of H=5, S=90, V=100, where the HSV scale in PS is H=0-360, S=0-100, V=0-100. The HSV scale in OpenCV is H=0-180, S=0-100, V=0-100, so in OpenCV terms, the HSV value of the red circle in the image is H= 5/2 =2.5, S= (90/100)*255 =229.5, V= (80/100)*255 =204.

The range I have given to the inRange() function in the following code snippet is H=0-10, S=50-255, V=40-255.

I stored the in my sdcard by the name of rgbaFrame.jpg.

enter image description here

Please refer to the code below. rgbaFrame Mat converted to HSV Mat resulted in the following image named hsvImage.jpg.

enter image description here

But then when the inRange method was executed, the resulting Mat was maskedImage.jpg:

enter image description here

public void doProcessing(View view) {
        Mat rgbaFrame = Highgui.imread("/mnt/sdcard/DCIM/rgbaFrame.jpg");

        Mat hsvImage = new Mat();
        Imgproc.cvtColor(rgbaFrame, hsvImage, Imgproc.COLOR_RGB2HSV);
        Highgui.imwrite("/mnt/sdcard/DCIM/hsvImage.jpg", hsvImage);// check

        Mat maskedImage = new Mat();
        /**Color Tested: In PS: H=5, S=90, V=80 | In OpenCV: H=5/2=2.5, S=90/100*255=229.5, V=80/100*255=204 (OPENCV SCALE: h=0-180, s=0-255, v=0-255) */
        Core.inRange(hsvImage, new Scalar(0, 50, 40), new Scalar(10, 255, 255), maskedImage);
        Highgui.imwrite("/mnt/sdcard/DCIM/maskedImage.jpg", maskedImage);// check

    }

Note: The code given is a part of an SSCCE I wrote. If you think I should post the complete SSCCE, please let me know.

Why doesn't the inRange() function detect this little red colored blob in this 50px Mat?

I created the following 50px by 50px image in Adobe PS, and the red circle has an HSV value of H=5, S=90, V=100V=80, where the HSV scale in PS is H=0-360, S=0-100, V=0-100. The HSV scale in OpenCV is H=0-180, S=0-100, V=0-100, so in OpenCV terms, the HSV value of the red circle in the image is H= 5/2 =2.5, S= (90/100)*255 =229.5, V= (80/100)*255 =204.

The range I have given to the inRange() function in the following code snippet is H=0-10, S=50-255, V=40-255.

I stored the in my sdcard by the name of rgbaFrame.jpg.

enter image description here

Please refer to the code below. rgbaFrame Mat converted to HSV Mat resulted in the following image named hsvImage.jpg.

enter image description here

But then when the inRange method was executed, the resulting Mat was maskedImage.jpg. (So obvicously I got an Exception here):

enter image description here

public void doProcessing(View view) {
        Mat rgbaFrame = Highgui.imread("/mnt/sdcard/DCIM/rgbaFrame.jpg");

        Mat hsvImage = new Mat();
        Imgproc.cvtColor(rgbaFrame, hsvImage, Imgproc.COLOR_RGB2HSV);
        Highgui.imwrite("/mnt/sdcard/DCIM/hsvImage.jpg", hsvImage);// check

        Mat maskedImage = new Mat();
        /**Color Tested: In PS: H=5, S=90, V=80 | In OpenCV: H=5/2=2.5, S=90/100*255=229.5, V=80/100*255=204 (OPENCV SCALE: h=0-180, s=0-255, v=0-255) */
        Core.inRange(hsvImage, new Scalar(0, 50, 40), new Scalar(10, 255, 255), maskedImage);
        Highgui.imwrite("/mnt/sdcard/DCIM/maskedImage.jpg", maskedImage);// check

    }

Note: The code given is a part of an SSCCE I wrote. If you think I should post the complete SSCCE, please let me know.