saviopalmieri / ctypes-opencv

Automatically exported from code.google.com/p/ctypes-opencv
0 stars 0 forks source link

Handling C-level cvWaitKey results > 255 #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I was going to ask if the cvWaitKey return type could be reverted to a pure
int, but then realized that the standard wrappers also seem to return it as
a string, so figured compatibility was good.  Although it'll break some of
the demos in Python 3 which use common patterns like 
    cvWaitKey(10) >= 0 
since you can't compare strings and numbers in Python 3.

Anyway - there is a small issue with the current wrapping though, in that
under Linux/Gtk, the result of the C level cvWaitKey has shift/event
information in the upper 16 bits. So the '%c' conversion will fail, as in:

>>> cv.WaitKey(20000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/site-packages/opencv/highgui.py", line
224, in cvWaitKey
    return z if z <= 0 else '%c' %z
OverflowError: unsigned byte integer is greater than maximum

In the default wrappers, they are working in C so they just silently
truncate the value by assigning it to a char.  I'd probably suggest that we
use (z & 0xFF) or something similar to protect the current wrapper.

-- David

Original issue reported on code.google.com by db3l....@gmail.com on 1 Jan 2009 at 8:07

GoogleCodeExporter commented 8 years ago
Oh, I didn't know that under Linux/Gtk, the return key value could exceed 8 
bits.
After seeing your comment, I checked with OpenCV's source code. It seems that 
under
Mac/Carbon, the return key value can exceed 8 bits, too.

I think it would be safe if we return an int instead, and let the users decide 
the
conversion. I don't mind breaking compatibility with the standard wrappers in 
this
case. It's just a better solution.

I'll update the code and the demos asap.

Minh-Tri

Original comment by pmtri80@gmail.com on 1 Jan 2009 at 8:36

GoogleCodeExporter commented 8 years ago
I've fixed the cvWaitKey() function. Now it returns an integer instead. All the 
demos
are patched accordingly.

Minh-Tri

Original comment by pmtri80@gmail.com on 1 Jan 2009 at 8:59