OpenCV resize fails on large image with “error: (-215) ssize.area() > 0 in function cv::resize”












20















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



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


I had this error message coming up :

"cv2.error: C:opencv-3.0.0sourcemodulesimgprocsrcimgwarp.cpp:3208: error: (-215) ssize.area() > 0 in function cv::resize"



I'm certain there is image content in the image array because I can save them into small tiles in jpg format. When I try to resize just a small part of the image, there is no problem and I end up with correctly resized image. (Taking a rather big chunk (50000,50000,3) still won't work, but it will work on a (10000,10000,3) chunk)



I'm wondering what could cause this problem and how I can solve this?



Thanks










share|improve this question




















  • 4





    guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

    – Micka
    Aug 13 '15 at 19:23













  • Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

    – user3667217
    Aug 13 '15 at 19:59











  • I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

    – Micka
    Aug 13 '15 at 20:43











  • Where can I find this file in macos, I didn't find any file which has similar name ?

    – Iem-Prog
    Mar 25 '18 at 13:06
















20















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



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


I had this error message coming up :

"cv2.error: C:opencv-3.0.0sourcemodulesimgprocsrcimgwarp.cpp:3208: error: (-215) ssize.area() > 0 in function cv::resize"



I'm certain there is image content in the image array because I can save them into small tiles in jpg format. When I try to resize just a small part of the image, there is no problem and I end up with correctly resized image. (Taking a rather big chunk (50000,50000,3) still won't work, but it will work on a (10000,10000,3) chunk)



I'm wondering what could cause this problem and how I can solve this?



Thanks










share|improve this question




















  • 4





    guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

    – Micka
    Aug 13 '15 at 19:23













  • Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

    – user3667217
    Aug 13 '15 at 19:59











  • I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

    – Micka
    Aug 13 '15 at 20:43











  • Where can I find this file in macos, I didn't find any file which has similar name ?

    – Iem-Prog
    Mar 25 '18 at 13:06














20












20








20


3






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



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


I had this error message coming up :

"cv2.error: C:opencv-3.0.0sourcemodulesimgprocsrcimgwarp.cpp:3208: error: (-215) ssize.area() > 0 in function cv::resize"



I'm certain there is image content in the image array because I can save them into small tiles in jpg format. When I try to resize just a small part of the image, there is no problem and I end up with correctly resized image. (Taking a rather big chunk (50000,50000,3) still won't work, but it will work on a (10000,10000,3) chunk)



I'm wondering what could cause this problem and how I can solve this?



Thanks










share|improve this question
















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



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


I had this error message coming up :

"cv2.error: C:opencv-3.0.0sourcemodulesimgprocsrcimgwarp.cpp:3208: error: (-215) ssize.area() > 0 in function cv::resize"



I'm certain there is image content in the image array because I can save them into small tiles in jpg format. When I try to resize just a small part of the image, there is no problem and I end up with correctly resized image. (Taking a rather big chunk (50000,50000,3) still won't work, but it will work on a (10000,10000,3) chunk)



I'm wondering what could cause this problem and how I can solve this?



Thanks







image opencv python-3.x image-processing opencv3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 13 '15 at 19:10







user3667217

















asked Aug 13 '15 at 19:00









user3667217user3667217

1,4571924




1,4571924








  • 4





    guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

    – Micka
    Aug 13 '15 at 19:23













  • Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

    – user3667217
    Aug 13 '15 at 19:59











  • I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

    – Micka
    Aug 13 '15 at 20:43











  • Where can I find this file in macos, I didn't find any file which has similar name ?

    – Iem-Prog
    Mar 25 '18 at 13:06














  • 4





    guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

    – Micka
    Aug 13 '15 at 19:23













  • Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

    – user3667217
    Aug 13 '15 at 19:59











  • I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

    – Micka
    Aug 13 '15 at 20:43











  • Where can I find this file in macos, I didn't find any file which has similar name ?

    – Iem-Prog
    Mar 25 '18 at 13:06








4




4





guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

– Micka
Aug 13 '15 at 19:23







guess: integer range is +/- 2.147.483.647 while cols x rows ist 8.525.058.586 in your example.So PROBABLY there is an integer overflow within cv::resize. You could test this by testing image sizes around cols x rows == 2.147.483.647

– Micka
Aug 13 '15 at 19:23















Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

– user3667217
Aug 13 '15 at 19:59





Hey Micka, you're right !! It works on (46340,46340,3) but not (46341,46341,3). Does that mean changing int to int64 should solve the problem?

– user3667217
Aug 13 '15 at 19:59













I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

– Micka
Aug 13 '15 at 20:43





I dont know where inside of cv::resize the area is computed. I think you have to have a look at opencv resize source code...

– Micka
Aug 13 '15 at 20:43













Where can I find this file in macos, I didn't find any file which has similar name ?

– Iem-Prog
Mar 25 '18 at 13:06





Where can I find this file in macos, I didn't find any file which has similar name ?

– Iem-Prog
Mar 25 '18 at 13:06












10 Answers
10






active

oldest

votes


















19














So it turns out that the problem comes from one line in modulesimgprocsrcimgwarp.cpp:



CV_Assert( ssize.area() > 0 );


When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.



And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:



CV_Assert( dsize.area() > 0 );


So this has to be commented out as well.






share|improve this answer





















  • 6





    How do you change this line of code? Where is file located?

    – Zvonimir Peran
    Aug 31 '16 at 8:34






  • 1





    Yes this is great but where can we find the file

    – Hack-R
    Feb 9 '17 at 18:00






  • 2





    Was a solution to fix this line of code ever posted/found?

    – Laughing Horse
    Apr 11 '17 at 3:46











  • Please tell where is the respective file located.

    – Haris
    Apr 22 '17 at 19:23











  • Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

    – Ubdus Samad
    May 16 '17 at 11:27





















6














Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.



Now I have an extra step before attempting the resize operation, which is to do the assertion myself:



def getSizedFrame(width, height):
"""Function to return an image with the size I want"""
s, img = self.cam.read()

# Only process valid image frames
if s:
img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)
return s, img


Now I don't see the error.






share|improve this answer
























  • I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

    – Hack-R
    Feb 9 '17 at 18:01











  • This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

    – Jan Sila
    Oct 17 '17 at 14:01



















2














I know this is a very old thread but I had the same problem which was due spaces in the images names.



e.g.




Image name: "hello o.jpg"




weirdly, by removing the spaces the function worked just fine.




Image name: "hello_o.jpg"







share|improve this answer































    1














    For me the following work-around worked:




    • split the array up into smaller sub arrays

    • resize the sub arrays

    • merge the sub arrays again


    Here the code:



    def split_up_resize(arr, res):
    """
    function which resizes large array (direct resize yields error (addedtypo))
    """

    # compute destination resolution for subarrays
    res_1 = (res[0], res[1]/2)
    res_2 = (res[0], res[1] - res[1]/2)

    # get sub-arrays
    arr_1 = arr[0 : len(arr)/2]
    arr_2 = arr[len(arr)/2 :]

    # resize sub arrays
    arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
    arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)

    # init resized array
    arr = np.zeros((res[1], res[0]))

    # merge resized sub arrays
    arr[0 : len(arr)/2] = arr_1
    arr[len(arr)/2 :] = arr_2

    return arr





    share|improve this answer


























    • It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

      – Iem-Prog
      Mar 25 '18 at 13:26



















    1














    This type of error also takes place because the resize is unable to get the image in simple
    the directory of the image may be wrong.In my case I left the forward slash during providing the location of file and this error took place after I put the slash problem was solved.






    share|improve this answer































      0














      Turns out I had a .csv file at the end of the folder from which I was reading all the images.
      Once I deleted that it worked alright



      Make sure that it's all images and that you don't have any other type of file






      share|improve this answer































        0














        In my case I did a wrong modification in the image.



        I was able to find the problem checking the image shape.



        print img.shape





        share|improve this answer































          0














          Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.






          share|improve this answer































            0














            I am having OpenCV version 3.4.3 on MacOS.
            I was getting the same error as above.



            I changed my code from



            frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)   


            to



            frame = cv2.resize(frame, None, fx=0.5, fy=0.5)    


            Now its working fine for me.






            share|improve this answer































              0














              I was working with 3 files: The python script, the image, and the trained model.



              Everything worked when I moved these 3 files into their own folder instead of in the directory with the other python scripts.






              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31996367%2fopencv-resize-fails-on-large-image-with-error-215-ssize-area-0-in-funct%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                10 Answers
                10






                active

                oldest

                votes








                10 Answers
                10






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                19














                So it turns out that the problem comes from one line in modulesimgprocsrcimgwarp.cpp:



                CV_Assert( ssize.area() > 0 );


                When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.



                And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:



                CV_Assert( dsize.area() > 0 );


                So this has to be commented out as well.






                share|improve this answer





















                • 6





                  How do you change this line of code? Where is file located?

                  – Zvonimir Peran
                  Aug 31 '16 at 8:34






                • 1





                  Yes this is great but where can we find the file

                  – Hack-R
                  Feb 9 '17 at 18:00






                • 2





                  Was a solution to fix this line of code ever posted/found?

                  – Laughing Horse
                  Apr 11 '17 at 3:46











                • Please tell where is the respective file located.

                  – Haris
                  Apr 22 '17 at 19:23











                • Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                  – Ubdus Samad
                  May 16 '17 at 11:27


















                19














                So it turns out that the problem comes from one line in modulesimgprocsrcimgwarp.cpp:



                CV_Assert( ssize.area() > 0 );


                When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.



                And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:



                CV_Assert( dsize.area() > 0 );


                So this has to be commented out as well.






                share|improve this answer





















                • 6





                  How do you change this line of code? Where is file located?

                  – Zvonimir Peran
                  Aug 31 '16 at 8:34






                • 1





                  Yes this is great but where can we find the file

                  – Hack-R
                  Feb 9 '17 at 18:00






                • 2





                  Was a solution to fix this line of code ever posted/found?

                  – Laughing Horse
                  Apr 11 '17 at 3:46











                • Please tell where is the respective file located.

                  – Haris
                  Apr 22 '17 at 19:23











                • Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                  – Ubdus Samad
                  May 16 '17 at 11:27
















                19












                19








                19







                So it turns out that the problem comes from one line in modulesimgprocsrcimgwarp.cpp:



                CV_Assert( ssize.area() > 0 );


                When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.



                And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:



                CV_Assert( dsize.area() > 0 );


                So this has to be commented out as well.






                share|improve this answer















                So it turns out that the problem comes from one line in modulesimgprocsrcimgwarp.cpp:



                CV_Assert( ssize.area() > 0 );


                When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.



                And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:



                CV_Assert( dsize.area() > 0 );


                So this has to be commented out as well.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 14 '17 at 5:09

























                answered Aug 16 '15 at 7:21









                user3667217user3667217

                1,4571924




                1,4571924








                • 6





                  How do you change this line of code? Where is file located?

                  – Zvonimir Peran
                  Aug 31 '16 at 8:34






                • 1





                  Yes this is great but where can we find the file

                  – Hack-R
                  Feb 9 '17 at 18:00






                • 2





                  Was a solution to fix this line of code ever posted/found?

                  – Laughing Horse
                  Apr 11 '17 at 3:46











                • Please tell where is the respective file located.

                  – Haris
                  Apr 22 '17 at 19:23











                • Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                  – Ubdus Samad
                  May 16 '17 at 11:27
















                • 6





                  How do you change this line of code? Where is file located?

                  – Zvonimir Peran
                  Aug 31 '16 at 8:34






                • 1





                  Yes this is great but where can we find the file

                  – Hack-R
                  Feb 9 '17 at 18:00






                • 2





                  Was a solution to fix this line of code ever posted/found?

                  – Laughing Horse
                  Apr 11 '17 at 3:46











                • Please tell where is the respective file located.

                  – Haris
                  Apr 22 '17 at 19:23











                • Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                  – Ubdus Samad
                  May 16 '17 at 11:27










                6




                6





                How do you change this line of code? Where is file located?

                – Zvonimir Peran
                Aug 31 '16 at 8:34





                How do you change this line of code? Where is file located?

                – Zvonimir Peran
                Aug 31 '16 at 8:34




                1




                1





                Yes this is great but where can we find the file

                – Hack-R
                Feb 9 '17 at 18:00





                Yes this is great but where can we find the file

                – Hack-R
                Feb 9 '17 at 18:00




                2




                2





                Was a solution to fix this line of code ever posted/found?

                – Laughing Horse
                Apr 11 '17 at 3:46





                Was a solution to fix this line of code ever posted/found?

                – Laughing Horse
                Apr 11 '17 at 3:46













                Please tell where is the respective file located.

                – Haris
                Apr 22 '17 at 19:23





                Please tell where is the respective file located.

                – Haris
                Apr 22 '17 at 19:23













                Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                – Ubdus Samad
                May 16 '17 at 11:27







                Just search 'imgwrap.cpp' in the main directory '/' and you'll find the file!

                – Ubdus Samad
                May 16 '17 at 11:27















                6














                Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.



                Now I have an extra step before attempting the resize operation, which is to do the assertion myself:



                def getSizedFrame(width, height):
                """Function to return an image with the size I want"""
                s, img = self.cam.read()

                # Only process valid image frames
                if s:
                img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)
                return s, img


                Now I don't see the error.






                share|improve this answer
























                • I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                  – Hack-R
                  Feb 9 '17 at 18:01











                • This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                  – Jan Sila
                  Oct 17 '17 at 14:01
















                6














                Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.



                Now I have an extra step before attempting the resize operation, which is to do the assertion myself:



                def getSizedFrame(width, height):
                """Function to return an image with the size I want"""
                s, img = self.cam.read()

                # Only process valid image frames
                if s:
                img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)
                return s, img


                Now I don't see the error.






                share|improve this answer
























                • I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                  – Hack-R
                  Feb 9 '17 at 18:01











                • This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                  – Jan Sila
                  Oct 17 '17 at 14:01














                6












                6








                6







                Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.



                Now I have an extra step before attempting the resize operation, which is to do the assertion myself:



                def getSizedFrame(width, height):
                """Function to return an image with the size I want"""
                s, img = self.cam.read()

                # Only process valid image frames
                if s:
                img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)
                return s, img


                Now I don't see the error.






                share|improve this answer













                Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.



                Now I have an extra step before attempting the resize operation, which is to do the assertion myself:



                def getSizedFrame(width, height):
                """Function to return an image with the size I want"""
                s, img = self.cam.read()

                # Only process valid image frames
                if s:
                img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)
                return s, img


                Now I don't see the error.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 9 '16 at 7:22









                Kelton.TembyKelton.Temby

                404511




                404511













                • I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                  – Hack-R
                  Feb 9 '17 at 18:01











                • This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                  – Jan Sila
                  Oct 17 '17 at 14:01



















                • I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                  – Hack-R
                  Feb 9 '17 at 18:01











                • This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                  – Jan Sila
                  Oct 17 '17 at 14:01

















                I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                – Hack-R
                Feb 9 '17 at 18:01





                I don't think this is the general case. This error does occur with valid images because of the OpenCV bug.

                – Hack-R
                Feb 9 '17 at 18:01













                This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                – Jan Sila
                Oct 17 '17 at 14:01





                This is the first hit on Google and this should be upvoted!! Check your imgs before starting commenting out the openCV code, I had exactly same problem while parsing dozens of images in preprocessing.

                – Jan Sila
                Oct 17 '17 at 14:01











                2














                I know this is a very old thread but I had the same problem which was due spaces in the images names.



                e.g.




                Image name: "hello o.jpg"




                weirdly, by removing the spaces the function worked just fine.




                Image name: "hello_o.jpg"







                share|improve this answer




























                  2














                  I know this is a very old thread but I had the same problem which was due spaces in the images names.



                  e.g.




                  Image name: "hello o.jpg"




                  weirdly, by removing the spaces the function worked just fine.




                  Image name: "hello_o.jpg"







                  share|improve this answer


























                    2












                    2








                    2







                    I know this is a very old thread but I had the same problem which was due spaces in the images names.



                    e.g.




                    Image name: "hello o.jpg"




                    weirdly, by removing the spaces the function worked just fine.




                    Image name: "hello_o.jpg"







                    share|improve this answer













                    I know this is a very old thread but I had the same problem which was due spaces in the images names.



                    e.g.




                    Image name: "hello o.jpg"




                    weirdly, by removing the spaces the function worked just fine.




                    Image name: "hello_o.jpg"








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 30 '17 at 10:50









                    WandererWanderer

                    338519




                    338519























                        1














                        For me the following work-around worked:




                        • split the array up into smaller sub arrays

                        • resize the sub arrays

                        • merge the sub arrays again


                        Here the code:



                        def split_up_resize(arr, res):
                        """
                        function which resizes large array (direct resize yields error (addedtypo))
                        """

                        # compute destination resolution for subarrays
                        res_1 = (res[0], res[1]/2)
                        res_2 = (res[0], res[1] - res[1]/2)

                        # get sub-arrays
                        arr_1 = arr[0 : len(arr)/2]
                        arr_2 = arr[len(arr)/2 :]

                        # resize sub arrays
                        arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
                        arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)

                        # init resized array
                        arr = np.zeros((res[1], res[0]))

                        # merge resized sub arrays
                        arr[0 : len(arr)/2] = arr_1
                        arr[len(arr)/2 :] = arr_2

                        return arr





                        share|improve this answer


























                        • It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                          – Iem-Prog
                          Mar 25 '18 at 13:26
















                        1














                        For me the following work-around worked:




                        • split the array up into smaller sub arrays

                        • resize the sub arrays

                        • merge the sub arrays again


                        Here the code:



                        def split_up_resize(arr, res):
                        """
                        function which resizes large array (direct resize yields error (addedtypo))
                        """

                        # compute destination resolution for subarrays
                        res_1 = (res[0], res[1]/2)
                        res_2 = (res[0], res[1] - res[1]/2)

                        # get sub-arrays
                        arr_1 = arr[0 : len(arr)/2]
                        arr_2 = arr[len(arr)/2 :]

                        # resize sub arrays
                        arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
                        arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)

                        # init resized array
                        arr = np.zeros((res[1], res[0]))

                        # merge resized sub arrays
                        arr[0 : len(arr)/2] = arr_1
                        arr[len(arr)/2 :] = arr_2

                        return arr





                        share|improve this answer


























                        • It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                          – Iem-Prog
                          Mar 25 '18 at 13:26














                        1












                        1








                        1







                        For me the following work-around worked:




                        • split the array up into smaller sub arrays

                        • resize the sub arrays

                        • merge the sub arrays again


                        Here the code:



                        def split_up_resize(arr, res):
                        """
                        function which resizes large array (direct resize yields error (addedtypo))
                        """

                        # compute destination resolution for subarrays
                        res_1 = (res[0], res[1]/2)
                        res_2 = (res[0], res[1] - res[1]/2)

                        # get sub-arrays
                        arr_1 = arr[0 : len(arr)/2]
                        arr_2 = arr[len(arr)/2 :]

                        # resize sub arrays
                        arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
                        arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)

                        # init resized array
                        arr = np.zeros((res[1], res[0]))

                        # merge resized sub arrays
                        arr[0 : len(arr)/2] = arr_1
                        arr[len(arr)/2 :] = arr_2

                        return arr





                        share|improve this answer















                        For me the following work-around worked:




                        • split the array up into smaller sub arrays

                        • resize the sub arrays

                        • merge the sub arrays again


                        Here the code:



                        def split_up_resize(arr, res):
                        """
                        function which resizes large array (direct resize yields error (addedtypo))
                        """

                        # compute destination resolution for subarrays
                        res_1 = (res[0], res[1]/2)
                        res_2 = (res[0], res[1] - res[1]/2)

                        # get sub-arrays
                        arr_1 = arr[0 : len(arr)/2]
                        arr_2 = arr[len(arr)/2 :]

                        # resize sub arrays
                        arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
                        arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)

                        # init resized array
                        arr = np.zeros((res[1], res[0]))

                        # merge resized sub arrays
                        arr[0 : len(arr)/2] = arr_1
                        arr[len(arr)/2 :] = arr_2

                        return arr






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 13 '17 at 15:29









                        Community

                        11




                        11










                        answered Mar 10 '17 at 7:28









                        Oli BlumOli Blum

                        1,1571122




                        1,1571122













                        • It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                          – Iem-Prog
                          Mar 25 '18 at 13:26



















                        • It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                          – Iem-Prog
                          Mar 25 '18 at 13:26

















                        It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                        – Iem-Prog
                        Mar 25 '18 at 13:26





                        It didn't work for me, I'm getting the same error! "error: (-215) ssize.area() > 0 in function resize". Note: I had to modify ur code since indexing value must be an integer. "Use // instead of / ".

                        – Iem-Prog
                        Mar 25 '18 at 13:26











                        1














                        This type of error also takes place because the resize is unable to get the image in simple
                        the directory of the image may be wrong.In my case I left the forward slash during providing the location of file and this error took place after I put the slash problem was solved.






                        share|improve this answer




























                          1














                          This type of error also takes place because the resize is unable to get the image in simple
                          the directory of the image may be wrong.In my case I left the forward slash during providing the location of file and this error took place after I put the slash problem was solved.






                          share|improve this answer


























                            1












                            1








                            1







                            This type of error also takes place because the resize is unable to get the image in simple
                            the directory of the image may be wrong.In my case I left the forward slash during providing the location of file and this error took place after I put the slash problem was solved.






                            share|improve this answer













                            This type of error also takes place because the resize is unable to get the image in simple
                            the directory of the image may be wrong.In my case I left the forward slash during providing the location of file and this error took place after I put the slash problem was solved.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 10 at 17:07









                            darkemperorVKOdarkemperorVKO

                            111




                            111























                                0














                                Turns out I had a .csv file at the end of the folder from which I was reading all the images.
                                Once I deleted that it worked alright



                                Make sure that it's all images and that you don't have any other type of file






                                share|improve this answer




























                                  0














                                  Turns out I had a .csv file at the end of the folder from which I was reading all the images.
                                  Once I deleted that it worked alright



                                  Make sure that it's all images and that you don't have any other type of file






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    Turns out I had a .csv file at the end of the folder from which I was reading all the images.
                                    Once I deleted that it worked alright



                                    Make sure that it's all images and that you don't have any other type of file






                                    share|improve this answer













                                    Turns out I had a .csv file at the end of the folder from which I was reading all the images.
                                    Once I deleted that it worked alright



                                    Make sure that it's all images and that you don't have any other type of file







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 6 '18 at 9:31









                                    empoleonrocksempoleonrocks

                                    21




                                    21























                                        0














                                        In my case I did a wrong modification in the image.



                                        I was able to find the problem checking the image shape.



                                        print img.shape





                                        share|improve this answer




























                                          0














                                          In my case I did a wrong modification in the image.



                                          I was able to find the problem checking the image shape.



                                          print img.shape





                                          share|improve this answer


























                                            0












                                            0








                                            0







                                            In my case I did a wrong modification in the image.



                                            I was able to find the problem checking the image shape.



                                            print img.shape





                                            share|improve this answer













                                            In my case I did a wrong modification in the image.



                                            I was able to find the problem checking the image shape.



                                            print img.shape






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Jun 28 '18 at 14:34









                                            ThomioThomio

                                            711714




                                            711714























                                                0














                                                Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.






                                                share|improve this answer




























                                                  0














                                                  Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.






                                                  share|improve this answer


























                                                    0












                                                    0








                                                    0







                                                    Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.






                                                    share|improve this answer













                                                    Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Dec 10 '18 at 1:18









                                                    AttilaAttila

                                                    11




                                                    11























                                                        0














                                                        I am having OpenCV version 3.4.3 on MacOS.
                                                        I was getting the same error as above.



                                                        I changed my code from



                                                        frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)   


                                                        to



                                                        frame = cv2.resize(frame, None, fx=0.5, fy=0.5)    


                                                        Now its working fine for me.






                                                        share|improve this answer




























                                                          0














                                                          I am having OpenCV version 3.4.3 on MacOS.
                                                          I was getting the same error as above.



                                                          I changed my code from



                                                          frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)   


                                                          to



                                                          frame = cv2.resize(frame, None, fx=0.5, fy=0.5)    


                                                          Now its working fine for me.






                                                          share|improve this answer


























                                                            0












                                                            0








                                                            0







                                                            I am having OpenCV version 3.4.3 on MacOS.
                                                            I was getting the same error as above.



                                                            I changed my code from



                                                            frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)   


                                                            to



                                                            frame = cv2.resize(frame, None, fx=0.5, fy=0.5)    


                                                            Now its working fine for me.






                                                            share|improve this answer













                                                            I am having OpenCV version 3.4.3 on MacOS.
                                                            I was getting the same error as above.



                                                            I changed my code from



                                                            frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)   


                                                            to



                                                            frame = cv2.resize(frame, None, fx=0.5, fy=0.5)    


                                                            Now its working fine for me.







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Jan 2 at 23:34









                                                            BiranchiBiranchi

                                                            9,00720104139




                                                            9,00720104139























                                                                0














                                                                I was working with 3 files: The python script, the image, and the trained model.



                                                                Everything worked when I moved these 3 files into their own folder instead of in the directory with the other python scripts.






                                                                share|improve this answer




























                                                                  0














                                                                  I was working with 3 files: The python script, the image, and the trained model.



                                                                  Everything worked when I moved these 3 files into their own folder instead of in the directory with the other python scripts.






                                                                  share|improve this answer


























                                                                    0












                                                                    0








                                                                    0







                                                                    I was working with 3 files: The python script, the image, and the trained model.



                                                                    Everything worked when I moved these 3 files into their own folder instead of in the directory with the other python scripts.






                                                                    share|improve this answer













                                                                    I was working with 3 files: The python script, the image, and the trained model.



                                                                    Everything worked when I moved these 3 files into their own folder instead of in the directory with the other python scripts.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Feb 22 at 0:06









                                                                    Shane RooneyShane Rooney

                                                                    1




                                                                    1






























                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31996367%2fopencv-resize-fails-on-large-image-with-error-215-ssize-area-0-in-funct%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        Monofisismo

                                                                        Angular Downloading a file using contenturl with Basic Authentication

                                                                        Olmecas