在矩阵中设置图像存储的色调

时间:2013-12-11 06:57:14

标签: android opencv hue

我正在尝试更改矩阵中图像存储的色调。我使用split()函数得到了一个色调通道,但我无法改变它的色调。我正在使用函数集(标量标量)来改变它的色调,但我没有看到图像有任何变化。

        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);

1 个答案:

答案 0 :(得分:0)

只需更改代码

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

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

hsv_channel.get(0)是单通道匹配,因此您的标量值应为单个。

编辑: -

哟可以看到OpenCV相机预览示例here

在Tutorial1Activity.java上,您可以看到一个方法

public Mat onCameraFrame(CvCameraViewFrame inputFrame)

在此方法上添加以下行

       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;