Bossgaming099 / ctypes-opencv

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

Implement equivalence for structure data types #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
One thing I've been finding inconvenient recently is the fact that two
(apparently) identical ctypes data types don't compare as equivalent. 
Thus, the current wrapper has the behavior that
"cvSize(5,10)==cvSize(5,10)" is False, whereas even in C comparing the
structures generated by those two constructors would compare true.  A lot
of it comes from the fact that in ctypes, even c_int(5)==c_int(5) is false.

At best it's inconvenient as you have to check the fields, but at worst it
can slip by, such as when I did a simple check during a loop to see if
cvGetSize on the supplied image was different than the prior frame and
ended up incurring a lot more overhead than needed, as I thought every
frame was different.

The attached patch attempts to remedy this by providing equivalence for
structure types based on their underlying fields, using the wrapped value
(e.g., 5 for c_int(5)) when available or for pointers, the address being
pointed to.  It also permits comparisons to hold true when comparing to a
native Python tuple, as long as that tuple can construct an equivalent object.

Demos all continue to run, although since they couldn't currently depend on
equivalence, I suppose that's not surprising.

Original issue reported on code.google.com by db3l.em...@gmail.com on 23 Jan 2009 at 2:52

Attachments:

GoogleCodeExporter commented 8 years ago
Patched. Thanks.

Original comment by pmtri80@gmail.com on 23 Jan 2009 at 5:35