Random non-zero pixels in cv.CreateImage after tostring() call. (Bug #1486)


Added by Daniele Paganelli over 13 years ago. Updated about 13 years ago.


Status:Done Start date:
Priority:Blocker Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:python bindings
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

The usually black images created with cv.CreateImage gets corrupted after a tostring() conversion: random white pixels appear and CountNonZero returns >0.

After iteration, the CountNonZero grows and grows.

I wrote a testcase to demonstrate this behavior. It would be nice if you could add it to the source tree.

All default python-bindings test cases are OK on my system.

I suspect this causes segmentation faults and memory corruptions in more complicated and iterated usages. I couldn't reproduce these segfaults in a test case, anyway it's quite obvious that if the image memory space gets corrupted, other parts of the memory may be damaged as well.

See attached file.


tostring.py - Test Case for tostring() image corruption in python bindings (2.1 kB) Daniele Paganelli, 2011-11-25 12:29 pm

test.jpg - Example damaged image (16.3 kB) Daniele Paganelli, 2011-12-21 12:20 pm


Associated revisions

Revision d1b5f437
Added by Vadim Pisarevsky about 13 years ago

adjust the header parser to support "public virtual" construction and make a tweak for multiple inheritance, fix potential memory problem with Python's IplImage.tostring() method (ticket #1486)

Revision 03bbee32
Added by Roman Donchenko over 11 years ago

Merge pull request #1486 from nzjrs:cv2-logpolar

History

Updated by Vadim Pisarevsky about 13 years ago

thanks for the test, I added it to our test system.
It can be the potential problem in tostring(), because in some cases it just increments the reference counter. I modified it to always return a separate copy (SVN, r7209).

However, there is bug in the test too. cv.CreateImage is not assumed to initialize the image with zeros. You must explicitly will it with zeros if needed:

image = cv.CreateImage(self.size, cv.IPL_DEPTH_8U, 1)
cv.Set(image, cv.Scalar(0,0,0,0))

after inserting cv.Set() after each cv.CreateImage() all the tests pass

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Updated by Andrey Kamaev about 13 years ago

  • Target version set to 2.4.0
  • Description changed from The usually black images created with cv.CreateImage gets corrupted after a t... to The usually black images created with @cv.CreateImage@ gets corrupted after a... More

Also available in: Atom PDF