OpenCV on Android crash if resolution of image for laplace is too small

asked 2019-01-14 07:59:25 -0500

subzero101010 gravatar image

updated 2019-01-15 11:08:04 -0500

Hello!

I am working on a blur detection with OpenCV for Android and used following code found here which seemed to work correctly:

http://answers.opencv.org/question/11...

Now, my problem is that it crashs, if the resolution of the image is too small. In the sample code the transformed image gets resized to 2000*2000, but only if it is bigger than that.

It happens here:

Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);

I have tested it serveral times and no crash with big images!

No crash image resolution: 1048 * 1048

Crash with resolution: 511*532

Does anybody now why this happens? It seems that there is a minimum image resolution size needed, but I can not find any info in the OpenCV documentation or in the internet.

UPDATE: Maybe someone can provide me a link to the C++ implementation of the laplacian funciton...can't find the code...should be open source?

Here a some working resolutions:

1713 x 1217; 537 x 562; 1089 x 563; 527 x 563; 522 x 542;

Not working resolutions:

511 x 532; 1662 x 562; 1661 x 562; 1662 x 563;

Test results! Maybe somebody sees a logic behind it:

1659 x 562: works

1660 x 562: works

1661 x 562: Application crash

1662 x 562: Application crash

1663 x 562: Application crash

1664 x 562: works

1665 x 562: works

1666 x 562: works

1667 x 562: works

1668 x 562: works

1669 x 562: works

I have a photo app where my users can crop images in different ratios like 4:3, 16:9 etc. Different ratios means different resulting image resolutions. The resolution is not only dependent by the ratio, but also by the zoom factor. The ratio is always the same, no matter how much the users zoomed in or out. The resolution is dependet on the zoom. The above resolutions represent the maximum resolution for the ratios I use for my app e.g. 1660x562 = 1:2.95 ratio. The cropped image with a ratio of 1:2.95 could have a resolution of 580x281(zoomed in) or a bigger one like 2320x1024. I then need to resize that image so I take the maxium supported size of 1660x562. I just adjusted the resolution until it did not crash. So instead of 1661x562 I took 1660x562 and it worked. I have 12 different resolutions/ratios for my app and 4 of them crashed. I just adjusted the resolution one pixel +/- until it worked. I still do not know what the problem is, but it works now.

Thanks!

edit retag flag offensive close merge delete

Comments

i bet it works with 512x512 (even size) (ignore, that was just a bad guess)

and what does "crash" mean exactly, here ?

berak gravatar imageberak ( 2019-01-14 08:12:28 -0500 )edit
1

The exact resolution is:
height: = 511; width: = 532;

But I have also big images with "not even" resolution and it works, like 1713 x 1217.

My Android app crashes completly and restarts. I could debug it until here:

//javadoc: Laplacian(src, dst, ddepth)
public static void Laplacian(Mat src, Mat dst, int ddepth)
{

    Laplacian_4(src.nativeObj, dst.nativeObj, ddepth);

    return;
}

Can't debug further..

If i change the resolution of the image manually to 1048x1048 it works. If I do it with images like 5000x5000 it works, 2000x2000 works, 1000x1000 works. Usually I would expect out of memory for high resolution images, but does not happen.

subzero101010 gravatar imagesubzero101010 ( 2019-01-14 08:20:26 -0500 )edit

can anyone reproduce this ?

(not me, not from c++, python or java, even)

berak gravatar imageberak ( 2019-01-15 10:11:21 -0500 )edit