0

I want to remove the shadows from the input image. Based from what I found, I need to set the V value of HSV to 200. But this code is not working for me in opencv android studio. Please help me understand what I'm doing wrong here.

 public Mat fixIntensity(Mat inputImage) {
        Mat hsvImg;
        Imgproc.cvtColor(inputImage, hsvImg, Imgproc.COLOR_RGB2HSV);
        Mat channel[3];

        Core.split(hsvImg, channel);
        channel[2] = Mat(hsvImg.rows, hsvImg.cols, CV_8UC1, 200);//Set V
        //Merge channels
        Core.merge(channel, 3, hsvImg);
        Mat rgbImg;
        Imgproc.cvtColor(hsvImg, rgbImg, CV_HSV2BGR);

        return rgbImg;
}
  • The HSV values I'm used to working with go from 0.0 to 1.0. Where does the documentation say to use 200? – markspace May 17 '17 at 16:26
  • It says in here that the channel V should be set to 200. https://github.com/LowWeiLin/OpenCV_ImageBackgroundRemoval/blob/master/OpenCV_ImageBackgroundRemoval/main.cpp – dobyvatel75 May 17 '17 at 16:45
  • What do you exactly mean by _this code is not working for me_ ? – Rick M. May 17 '17 at 17:04
  • What I mean is that I can't really set a value for V – dobyvatel75 May 17 '17 at 17:15
  • Have you tried - `List channels = new ArrayList(3); Core.split(hsvImg, channels); channels.add(2, new Mat(hsvImg.rows(), hsvImg.cols(), CV_8UC1, 200);` – Rick M. May 17 '17 at 18:28
  • I tried that just now but your code is only correct until `channel.add(2, new Mat(hsvImg.rows(), hsvImg.cols(), CvType.CV_8UC1));` and it still can't assign the value 200. – dobyvatel75 May 17 '17 at 19:25
  • 1
    Sorry, I didn't try the code. Why don't make a new single channel mat and set all the values to 200 and then call the `channel...`. Use `setTo` to do so. – Rick M. May 17 '17 at 21:36
  • [setTo](http://docs.opencv.org/java/2.4.2/org/opencv/core/Mat.html#setTo(org.opencv.core.Scalar)) -- i.e. split, `channel[2].setTo(200)` and merge should be all that's necesary. – Dan Mašek May 17 '17 at 21:47
  • I tried them both but it still doesn't work. I really can't understand what's wrong. :( – dobyvatel75 May 18 '17 at 18:16

0 Answers0