Ask Your Question
0

pyramid_segmentation.py crashes with any different input image

asked 2012-11-01 15:30:40 -0600

Phlip gravatar image

I want to get pyramid_segmentation.py working - essentially because it has such a cool name. It works on the fruit image shipped with python-opencv (2.1.0-7). But when I stitch in the name of a PNG file, on both Ubuntu and Win7 I get this merriment:

 $ python pyramid_segmentation.py 
 OpenCV Error: Assertion failed ((icvPyrSegmentation8uC3R( src_data, src_step, dst_data, dst_step,  src_size, CV_GAUSSIAN_5x5, comp, storage, level, thresh1, thresh2 )) >= 0) in cvPyrSegmentation,  file /build/buildd/opencv-2.1.0/src/cv/cvpyrsegmentation.cpp, line 1872
 Traceback (most recent call last):
  File "pyramid_segmentation.py", line 41, in <module>
    PyrSegmentation(img0).run()
  File "pyramid_segmentation.py", line 34, in run
    self.on_segment()
  File "pyramid_segmentation.py", line 30, in on_segment
    self.level, self.thresh1+1, self.thresh2+1)
 cv.error: (icvPyrSegmentation8uC3R( src_data, src_step, dst_data, dst_step, src_size,  CV_GAUSSIAN_5x5, comp, storage, level, thresh1, thresh2 )) >= 0

Anyone know how to fix that?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-11-04 17:30:14 -0600

Dan Maynard gravatar image

I have done some work with this tool, and struggled with the same error. The key is to see what happens in pyramid segmentation - at each level in the pyramid the image becomes half the size, and the function does not cope if there are not an even number of pixels to reduce at each step.

Therefore you have to ensure before calling the function that the number of pixels in width and height can be divided by 2^n where n is your value for level parameter. If your image is large you might crop a few pixels off, if it is small you could resample to a different size or add a black border.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-01 15:30:40 -0600

Seen: 560 times

Last updated: Nov 04 '12