Ask Your Question
3

How to resize an extremely large image

asked 2015-08-13 16:25:36 -0600

ChaoyuanYeh gravatar image

updated 2017-09-13 11:49:10 -0600

Hi, I'm using Python 3.4.3 and OpenCV 3.0.0. While I'm trying to resize a very large RGB image (107162,79553,3) using the following code:

import cv2
image = cv2.resize(image, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)

I got the error message "cv2.error: C:\opencv-3.0.0\source\modules\imgproc\src\imgwarp.cpp:3208: error: (-215) ssize.area() > 0 in function cv::resize" I did some further testing and realized this is an integer overflow problem because the code would work on image of the size (46340,46340,3) but not (46341,46341,3).I understand I can perform bloc processing but I'm still interested in knowing if there is a direct solution to this problem.

My naive thought is that if I can identify where exactly this int that gave me the trouble is, I can then go in and change it to int64. So my questions are : 1) Is this approach plausible? 2) If so, exactly what should I change to solve this? If not, how can I solve this problem?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-08-14 02:30:40 -0600

LBerger gravatar image

I have try your code in C++ with opencv 3.0-dev and I have found same problem.

Mat bigg( 107162,79553,CV_8UC3),small;
resize(bigg, small,Size2d(107162/2,79553/2),0, 0,INTER_AREA);

Problem is size.area() is negative. What I have done (that''s not very nice at all) I have changed size value before size.area (for example 700,700 for size) and after size.area restore good value and after I have got a result in Mat small. So if you try to compile opencv from source you can comment this line. May be it would solve your problem

It looks like a bug may be you can report a ticket here

edit flag offensive delete link more

Comments

That sounds like a solution to me. I know exactly what I need to resize so I think I can probably just comment this out. I'll see if this will work. Thanks !

ChaoyuanYeh gravatar imageChaoyuanYeh ( 2015-08-14 03:48:20 -0600 )edit
2

I think you should report this as a bug, because this integer overflow should be dealt with :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-14 04:19:01 -0600 )edit
1

After I commented out the line and rebuilt openCV, it did solve my problem. and Yes, I have followed LBerger's suggestion and reported a ticket.

ChaoyuanYeh gravatar imageChaoyuanYeh ( 2015-08-14 11:56:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-08-13 16:25:36 -0600

Seen: 7,753 times

Last updated: Aug 14 '15