Ask Your Question
0

Hi,I am trying to do histogram equalization using opencv java, but i keep getting Assertion failed (_src.type() == CV_8UC1) anyone can help?

asked 2016-01-01 01:39:05 -0600

Amer gravatar image

updated 2016-01-01 16:43:17 -0600

this is my code

 Mat doraImage= Imgcodecs.imread("C:/test/dora.jpg" , Imgcodecs.CV_LOAD_IMAGE_COLOR);

if(doraImage.channels() == 3) {
        doraImage.convertTo(doraImage, Imgproc.COLOR_BGR2YCrCb);
  else if(doraImage.channels() == 4) {
       doraImage.convertTo(doraImage, Imgproc.COLOR_BGR2YCrCb);
    }
    Imgproc.equalizeHist(doraImage, doraImage);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-01 16:48:59 -0600

berak gravatar image

updated 2016-01-02 02:21:22 -0600

convertTo changes the depth(channel type), not the channel count, also, if you used Imgcodecs.CV_LOAD_IMAGE_COLOR for loading, you're safe to assume, the image is CV_8UC3, so you can skip the 4 channel case.

what you need instead is cvtColor(), like:

Mat gray = new Mat();
cvtColor(doraImage, gray, Imgproc.COLOR_BGR2YCrCb);
Imgproc.equalizeHist(gray, gray);
// process gray image
// then, 
gray.release();
edit flag offensive delete link more

Comments

Thanks for answering, it worked :)

Amer gravatar imageAmer ( 2016-01-01 23:14:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-01 01:39:05 -0600

Seen: 1,491 times

Last updated: Jan 02 '16