Search code examples
c++opencvimage-processinglarge-data

Can not load large image with opencv


I try to load an image with opencv that has the size 100.000 * 15.000 pixels and a file size of 4.305 kb. If i load this image with the following code:

   cv::Mat reallyBigImage = cv::imread("reallyBigImage.png");

i get the following error:

Error message

I have a pc with 32 gb ram and compile this program in 64 bit. This should be enough for an image of this size. Is it possible to load such an large image as whole to opencv?

Here is where my program breaks in assembler. The arrow indicates the specific location. This snippet is from the memcpy.asm.

    CopyUp:
    cmp     r8, 128
    jbe     XmmCopySmall

    bt      __favor, __FAVOR_ENFSTRG ; check for ENFSTRG (enhanced fast strings)
    jnc     XmmCopyUp               ; If Enhanced Fast String not available, use XMM

    ; use Enhanced Fast Strings
    ; but first align the destination dst to 16 byte alignment
    mov     rax, r11                ; return original destination pointer
    mov     r11, rdi                ; save rdi in r11
    mov     rdi, rcx                ; move destination pointer to rdi
    mov     rcx, r8                 ; move length to rcx
    mov     r8, rsi                 ; save rsi in r8
    mov     rsi, r10                ; move source pointer to rsi
    -->rep     movsb                   ; copy source to destination buffer
    mov     rsi, r8                 ; restore rsi
    mov     rdi, r11                ; restore rdi
    ret

Solution

  • Running some local tests, this can be reproduced with OpenCV 3.1, but not with 3.2 or 3.3. That suggests it was a bug (along with the fact that you're getting an access violation in the first place).

    Specifically issue #6317.

    This was fixed prior to release of OpenCV 3.2, which would match the above observations. Hence, the best option would be to upgrade your copy of OpenCV.