xennygrimmato / pyopencv

Automatically exported from code.google.com/p/pyopencv
0 stars 0 forks source link

PyOpencv demos fail on Mac OS X #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compiled and installed pyopencv
2. Tried to run all of the demos in the demo directory
3.

What is the expected output? What do you see instead?

The demos should run, but many crash instead.

What version of the product are you using? On what operating system?

Mac OSX Snow leopard on a 64-bit machine.

Please provide any additional information below.

I will summarize what happens with each of the python codes in the demo 
directory of svn:

----------
capture.py:
Opens up a windows, but then segfaults with the following message:

OpenCV Python capture video
Output #0, avi, to 'captured.avi':
    Stream #0.0: Video: mpeg4, yuv420p, q=2-31, 90k tbn, 30 tbc
picture size invalid (0x0)
    Last message repeated 2 times
[avi @ 0x10283b600]dimensions not set
zsh: segmentation fault  ./capture-cam.py

debugger doesn't give a whole lot of info - gdb just shows:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000020
0x0000000126548e00 in ff_isom_write_avcc ()

---------------------
./chessboard.py right01.jpg
Crashes due to assert failing:

OpenCV Error: Assertion failed ((corners.cols == 1 || corners.rows == 1) && 
corners.type() == CV_32FC2 && corners.isContinuous()) in drawChessboardCorners, 
file 
/opt/local/var/macports/build/_Users_abergou_Documents_Ports_graphics_opencv/wor
k/OpenCV-2.1.0/src/cv/cvcalibinit.cpp, line 1900
Traceback (most recent call last):
  File "./chessboard.py", line 15, in <module>
    drawChessboardCorners( im3, chessboard_dim, asMat(corners), found )
RuntimeError: 
/opt/local/var/macports/build/_Users_abergou_Documents_Ports_graphics_opencv/wor
k/OpenCV-2.1.0/src/cv/cvcalibinit.cpp:1900: error: (-215) (corners.cols == 1 || 
corners.rows == 1) && corners.type() == CV_32FC2 && corners.isContinuous() in 
function drawChessboardCorners

-----------------------
./contours.py
Crashes due to OverflowError

Traceback (most recent call last):
  File "./contours.py", line 72, in <module>
    createTrackbar( "levels+3", "contours", levels, 7, on_trackbar )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow

--------------------------
./convexhull.py
Works as expected!

--------------------------
./curvature.py
Not sure what expected output should be but seems to work and exits normally.

--------------------------
./distrans1.py
Crashes with overflow error

Traceback (most recent call last):
  File "./distrans1.py", line 67, in <module>
    createTrackbar( tbarname, wndname, edge_thresh, 255, on_trackbar )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow
---------------------------
./edge.py
Crashed with overflow error

OpenCV Python version of edge
Traceback (most recent call last):
  File "./edge.py", line 58, in <module>
    createTrackbar (trackbar_name, win_name, 1, 100, on_trackbar)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow
--------------------------------
./facedetect.py pedestrian.jpg

Works!!
--------------------------------
./find_obj.py
Seems to have a bug in the code itself:

Object Descriptors: 607

Image Descriptors: 829

Extraction time = 0.000332358ms

(Point2f(x=296.75613403320312, y=55.682113647460938), 
Point2f(x=128.128173828125, y=270.38516235351562))
Traceback (most recent call last):
  File "./find_obj.py", line 120, in <module>
    cv.line( correspond, cv.asPoint(inst_Point2f=pair[0]), cv.Point(int(pair[1].x), int(pair[1].y+object.rows)), colors[8] )
TypeError: convert() got an unexpected keyword argument 'inst_Point2f'
-----------------------------
./houghlines.py
Works!

----------------------------
./kmeans.py
Works!!

----------------------------
./laplace1.py

Opens camera - I see my camera light come on and then segfaults with message;

Cleaned up camera.
zsh: segmentation fault  ./laplace1.py

gdb doesn't say anything useful:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x00007fff80f86120 in objc_msgSend ()

---------------------------------
./laplace2.py
Segfault similar to above:
Traceback (most recent call last):
  File "./laplace2.py", line 30, in <module>
    createTrackbar( "Sigma", "Laplacian", sigma, 15 )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow
Cleaned up camera.
zsh: segmentation fault  ./laplace2.py

-------------------------------------
./logpolar.py
Works!!!

-------------------------------------
./peopledetect.py
Works!!!!

-------------------------------------
./polar_transforms.py
Segmantation fault after camera light comes on:

Cleaned up camera.
zsh: segmentation fault  ./polar_transforms.py
-------------------------------------
./pyramid_segmentation.py
Brings up window then immediately crashes with message:

Traceback (most recent call last):
  File "./pyramid_segmentation.py", line 40, in <module>
    sthreshold1 = createTrackbar("Threshold1", "Segmentation", threshold1, 255, ON_SEGMENT)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow
--------------------------------------
./squares.py

Crashes with message:
Traceback (most recent call last):
  File "./squares.py", line 123, in <module>
    createTrackbar( "canny thresh", wndname, thresh, 1000, on_trackbar )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyopencv/highgui.py", line 171, in createTrackbar
    result, z = _ext._createTrackbar(trackbar_name, window_name, _CT.addressof(value), count, on_change, userdata=userdata)
OverflowError: bad numeric conversion: positive overflow
--------------------------------------
./watershed.py

Initially brings up two windows - one with fruits picture and the other black. 
When I hit w to execute the watershed algorithm it crashes with:
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in 
drawContours, file 
/opt/local/var/macports/build/_Users_abergou_Documents_Ports_graphics_opencv/wor
k/OpenCV-2.1.0/src/cv/cvcontours.cpp, line 1578
Traceback (most recent call last):
  File "./watershed.py", line 88, in <module>
    drawContours( markers, contours, idx, comp_count+1, CV_FILLED, 8, hierarchy, 0 )
RuntimeError: 
/opt/local/var/macports/build/_Users_abergou_Documents_Ports_graphics_opencv/wor
k/OpenCV-2.1.0/src/cv/cvcontours.cpp:1578: error: (-215) 0 <= contourIdx && 
contourIdx < (int)last in function drawContours

Original issue reported on code.google.com by aber...@gmail.com on 20 Aug 2010 at 6:54

GoogleCodeExporter commented 9 years ago
I went through the error again in detail, I summarize my progress below:

- I confirm that with the exception of find_obj.py all of the above seem to 
work under Ubuntu 64-bit. 
- I've attached a small patch for find_obj.py to get it to work with the latest 
svn version of pyopencv
- With the mac there appear to be a few issues:

1. createTrackbar appears to be broken - this seems to be the main culprit in 
the above not working.
2. VideoCapture is broken on the mac.  retrieveframe (which >> is a synonym 
for) always returns False and the mat argument is always empty.  I'm not sure 
though why capture.py segfaults.
3. capturing video from a file does seem to work.
4. with the patch to find-obj I do get some strange garbage pixels below the 
upper bostoncini box that does not appear there in the C++ version of the code

I have confirmed that my installation of OpenCV is ok and that the C++ examples 
that come with the OpenCV distribution work.

Original comment by aber...@gmail.com on 24 Aug 2010 at 4:34

GoogleCodeExporter commented 9 years ago
Forgot to attach the new version of find_obj.py.  Here it is.

Original comment by aber...@gmail.com on 24 Aug 2010 at 4:35

Attachments:

GoogleCodeExporter commented 9 years ago
Issue 4 above with the strange garbage pixels also happens with Ubuntu so it 
might be that some array is not zero-d out.

It appears that the Mac OS X and the Ubuntu version differ in that 
createTrackbar and VideoCapture do not work.  Could this somehow be an 
endiannes issue?

Original comment by aber...@gmail.com on 24 Aug 2010 at 5:04

GoogleCodeExporter commented 9 years ago
Many thanks, Daniel. I will include the new version of find_obj.py once I have 
tested it on my Windows box and my Ubuntu box.

VideoCapture on my Ubuntu is not working either. On Windows, I have to delete 
OpenCV's ffmpeg shared library to get VideoCapture to work. I suspect the bug 
has something to do with OpenCV's ffmpeg version rather than from an endianness 
issue, but I have not got time to figure out. Does VideoCapture work when you 
run one of the C++ examples on Ubuntu?

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 24 Aug 2010 at 5:33

GoogleCodeExporter commented 9 years ago
Hi, abergou. Sorry I miscalled you as Daniel. :)

I have tested your new version of find_obj.py and it is working well. I have 
included it in the demo package. I have also fixed the garbage pixels by 
initializing the 'correspond' image with zeros.

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 24 Aug 2010 at 5:41

GoogleCodeExporter commented 9 years ago
Thanks for fixing those two issues.

As far as VideoCapture:  i can open  a file under both Linux and Mac without 
problems with pyopencv.  Using VideoCapture with a webcam doesn't work with it. 
  Under Mac the same webcam works fine with the c, c++, and python bindings.  I 
couldn't try it yet under Linux.  By the way:  under both Mac and Linux I don't 
think opencv comes with it's own ffmpeg but instead uses the one installed on 
the system.

Any idea what the problem might be with the track bar?

Thanks very much:

Attila

Thanks:
Attila   

Original comment by aber...@gmail.com on 24 Aug 2010 at 5:56

GoogleCodeExporter commented 9 years ago
Thanks for the update, Attila. So the VideoCapture problem I am facing must 
come from my own system. I am not too sure about the track bar problem yet 
because the track bar is working on both my Windows box and my 32-bit Ubuntu 
box. I will test it on my 64-bit Ubuntu box when I get to my office today.

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 24 Aug 2010 at 6:07

GoogleCodeExporter commented 9 years ago
I have a fix for createTrackbar:  the problem actually can affect linux as 
well, not only Mac OS X and is related to a 32-bit vs. 64-bit issue.  

The problem occurs in highgui_ext.main.cpp and is due to the int * being cast 
to an unsigned int.  To be 64-bit compatible the cast should be to a unsigned 
long.  Attached is a patch file to highgui_ext.main.cpp, which I've verified 
fixes createTaskbar under Mac OS X (and should also fix it under 64-bit linux - 
though it does happen to work there most of the time due to the address space 
being different).

Original comment by aber...@gmail.com on 25 Aug 2010 at 3:26

Attachments:

GoogleCodeExporter commented 9 years ago
Update on this issue:

With the patch in comment 8, all examples work under mac os x with the webcam 
is not used.

Accessing the webcam through VideoCapture still fails - not sure why this 
happens.

Original comment by aber...@gmail.com on 25 Aug 2010 at 3:35

GoogleCodeExporter commented 9 years ago
Many thanks, Attila. I've updated your patch for the createTrackbar issue. 
Also, instead of casting the pointer to 'unsigned long', I cast it to 
'Py_intptr_t', which is of the same size as 'void *' for every platform.

I will try to analyse the issue with accessing the webcam through VideoCapture 
later today on my 64-bit Ubuntu platform.

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 25 Aug 2010 at 6:44

GoogleCodeExporter commented 9 years ago
Hi Attila,

I've tested accessing my Logitech webcam through VideoCapture on my 64-bit 
Ubuntu platform. It works.

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 25 Aug 2010 at 12:31

GoogleCodeExporter commented 9 years ago
Hi Minh-Tri,

Thanks for testing it.  I went back and it turns out that this is not a bug in 
pyopencv - it is in fact a known bug in the OpenCV C++ bindings for the mac.  
It does not affect the c and (defult) python bindings strangely enough.  In any 
case it is corrected in the svn version of OpenCV.

So I can officially say that pyopencv now works on the mac (as well as opencv 
itself allows it to).  So this issue can be closed (and you can update your FAQ 
to say that it also has been tested under Mac OS X 10.6.

Thanks for all the work - these bindings are going to be super useful.  I hope 
they get adopted as the default.

Attila

PS.  Not sure if you've looked at Opencv SVN, but it looks like a lot of stuff 
is getting added to it!

Original comment by aber...@gmail.com on 25 Aug 2010 at 3:55

GoogleCodeExporter commented 9 years ago
Hi Attila,

Thank you for your time in testing and fixing PyOpenCV on Mac and on Ubuntu as 
well. Your help is greatly appreciated.

Meanwhile, I will try to fix the 'ldconfig' issue and other minor matters 
before announcing a release.

I haven't got time to look at OpenCV SVN. But I believe OpenCV 2.1.1 will be 
released soon. In the past, it only took me a few days to migrate PyOpenCV from 
OpenCV 2.0 to OpenCV 2.1. I just want to wait for a sufficiently stable 
version/snapshot of OpenCV before doing the migration.

Cheers,
Minh-Tri

Original comment by pmtri80@gmail.com on 25 Aug 2010 at 7:34

GoogleCodeExporter commented 9 years ago
Glad to help out!

I'll also take a look at the ldconfig issue, but am going to be busy for the 
next few days.

As an aside for anyone who comes across this thread - the patch found at 
https://code.ros.org/trac/opencv/changeset/3018#file2 fixes the issue with 
camera capture using the c++ interface.  Once opencv is recompiled with this 
patch in place all the demos work under mac os x as well.

Original comment by aber...@gmail.com on 25 Aug 2010 at 7:55