opencv_createsample: free(): invalid next size (normal):

asked 2018-06-08 04:38:10 -0500

federicoponzi gravatar image

updated 2018-06-08 04:53:34 -0500

Hello there,

Not sure how to get around this. I'm trying to use opencv_create sample, but seems like it tries to free an already fred pointer.

I'm using self-compiled opencv 4.0.0-pre (got this using opencv_version).

This is the complete output:

*** Error in `opencv_createsamples': free(): invalid next size (normal): 0x0000000000821460 ***
======= Backtrace: =========
======= Memory map: ========

Using GDB:

Program received signal SIGABRT, Aborted.
0x00007ffff2e2c428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
54  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff2e2c428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff2e2e02a in __GI_abort () at abort.c:89
#2  0x00007ffff2e6e7ea in __libc_message (do_abort=do_abort@entry=2, 
    fmt=fmt@entry=0x7ffff2f87ed8 "*** Error in `%s': %s: 0x%s ***\n")
    at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff2e7737a in malloc_printerr (ar_ptr=<optimized out>, 
    ptr=<optimized out>, str=0x7ffff2f88030 "free(): invalid next size (normal)", 
    action=3) at malloc.c:5006
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3867
#5  0x00007ffff2e7b53c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968
#6  0x00007ffff2e64d5d in __fopen_internal (filename=0x63e484 "neg/2014.jpg\r", 
    mode=0x7ffff75ac9c8 "rb", is32=1) at iofopen.c:90
#7  0x00007ffff72a086d in cv::findDecoder(cv::String const&) ()
   from /home/federico/.opencv/opencv/build/lib/
#8  0x00007ffff72a12a1 in cv::imread_(cv::String const&, int, int, cv::Mat*) ()
   from /home/federico/.opencv/opencv/build/lib/
#9  0x00007ffff72a2fb3 in cv::imread(cv::String const&, int) ()
   from /home/federico/.opencv/opencv/build/lib/
#10 0x000000000040448a in icvGetNextFromBackgroundData(CvBackgroundData*, CvBackgroundReader*) ()
#11 0x000000000040ba9c in cvCreateTestSamples(char const*, char const*, int, int, char---Type <return> to continue, or q <return> to quit---

The command I'm trying to run is: opencv_createsamples -img watch5050.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 1950(from: - so I'm using the dataset from the article)

Any suggestion on how to get around this?

edit retag flag offensive close merge delete


"neg/2014.jpg\r" <-- do you see the \r there ? unlikely, that it should be there.

apart from that, use a debug build, so you can dive into findDecoder() and such with gdb.

berak gravatar imageberak ( 2018-06-08 04:51:01 -0500 )edit

Hello and thanks for the comment! I also saw that, but there is no-where, neither in the bg.txt nor in the filename so I'm not sure why there is that char there.

federicoponzi gravatar imagefedericoponzi ( 2018-06-08 04:52:51 -0500 )edit

well it is there. no ?

and a usual text editor probably won't show it.

berak gravatar imageberak ( 2018-06-08 04:56:34 -0500 )edit

btw, that tutorial is shite. in the end he can't detect his watch properly, because the idea of using only 1 positive image, and generating more from it NEVER works in real life. (you still have only 1 image)

get a TON of real positives (~10k for propfessional results) , anything else is a plain waste of (anyone's) time.

you wouldn't believe, how many crap tutorials like that are out there, and how many folks fell into the same trap

berak gravatar imageberak ( 2018-06-08 05:13:53 -0500 )edit

hey berak! Thanks a lot for the last comment, I do really appreciate it. In fact, I've used some custom images and the tool is working fine. Still, this error is strange. I've checked the bg.txt file with vim and run :%s/\r// but couldn't find any match. For the filename, I've used ls -lab but didn't find anything. So yeah, it's strange, but since it's working on my own dataset I guess it's cool for me. Thanks a lot

federicoponzi gravatar imagefedericoponzi ( 2018-06-08 05:24:47 -0500 )edit

My guess, you must have an image path in your annotations file (the one needed for createsamples), that is incorrect, because I just tested the whole pipeline (opencv_annotation, opencv_createsamples, opencv_traincascade) and everythin runs just fine.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-06-08 05:50:39 -0500 )edit