我正在尝试更改矩阵中图像存储的色相。我使用split()函数获得了一个色相通道,但无法更改其色相。我正在使用功能集(Scalar scalar)更改其色相,但是图像上没有任何变化。

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

最佳答案

只需更改代码

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)是单通道Mat,因此您的Scalar值应为single。

编辑:-

您可以看到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;

10-07 23:57