Question

I am trying to change the hue of image store in matrix. I got a hue channel using split() function but i am not able to change its hue. I am using the function set(Scalar scalar) to change its hue, but i don't see any change in image.

        Mat eyeball_HSV = new Mat();
        Mat dest = new Mat();       
        Mat eye = new Mat();

        eye = mRgba.submat(eye_template);

        List<Mat> hsv_channel = new ArrayList<Mat>();

           Imgproc.cvtColor(eye, eyeball_HSV, Imgproc.COLOR_RGB2HSV, 0);

          // get HSV channel 
        //hsv_channel[0] is hue
        //hsv_channel[1] is saturation
        //hsv_channel[2] is visibility
        Core.split(eyeball_HSV, hsv_channel);

        try
        {
             hsv_channel.get(0).setTo(new Scalar(145,25,45));
             Log.v(TAG, "Got the Channel!");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            Log.v(TAG, "Didn't get any channel");
        }

        Imgproc.cvtColor(eyeball_HSV, dest, Imgproc.COLOR_HSV2RGB);
        Imgproc.cvtColor(dest, eye, Imgproc.COLOR_RGB2RGBA);
Was it helpful?

Solution

Just change the code

hsv_channel.get(0).setTo(new Scalar(145,25,45));

to

hsv_channel.get(0).setTo(new Scalar(145)); // whatever your value

hsv_channel.get(0) is single channel Mat so your Scalar value should be with single.

Edit:-

Yo can see the OpenCV camera preview example here

On Tutorial1Activity.java you can see a method

public Mat onCameraFrame(CvCameraViewFrame inputFrame)

Add these lines on this method

       src = inputFrame.rgba();  
       Imgproc.cvtColor(src, hsv,Imgproc.COLOR_RGB2HSV );     
       Core.split(hsv, hsv_channel);
      // Imgproc.equalizeHist(hsv_channel.get(0), hsv_channel.get(0));
       hsv_channel.get(0).setTo(new Scalar(64));
       Core.merge(hsv_channel, hsv);
       Imgproc.cvtColor(hsv, src,Imgproc.COLOR_HSV2RGB );     
       //return hsv_channel.get(0);
       return src;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top