Closed GoogleCodeExporter closed 9 years ago
Thanks, ruoyu0088. The bug is confirmed.
The current issue is that MatND only supports contiguous arrays stored in the
little-endian format (i.e. the stride increases from the left most dimension to
the right most dimension). This means the provided ndarray must also be
contiguous and stored in the little-endian format. By specifying "m.shape = 4,
5", you specify that the array is contiguous _but_ the arrangement of the items
are not in the little-endian format. However, the current conversion code only
checks for contiguity and not for the little-endian format, hence the bug. When
I have time, I will add code to raise an error when this case happens.
Cheers,
Minh-Tri
Original comment by pmtri80@gmail.com
on 9 Jun 2010 at 9:51
Oh, wait. Please ignore my previous message. I think I'm wrong. :)
Minh-Tri
Original comment by pmtri80@gmail.com
on 9 Jun 2010 at 9:54
Hi ruoyu0088,
After digging PyOpenCV's code and OpenCV's code, I found what had gone wrong.
The problem is, OpenCV's code is inconsistent in choosing between the
little-endian format and the big-endian format to represent a CvMatND.
- At cxmat.hpp:3707, when a Mat is converted into a MatND, the big-endian
format is used.
- At cxarray.cpp:249, when a CvMatND is created from an array, the
little-endian format is used.
Right now, PyOpenCV assumes that OpenCV uses the big-endian format to arrange
the array elements. Thus, if you create a Mat instance 'mat' and then use
'cv.MatND(mat)' to obtain an equivalent MatND instance, it should work.
However, if you create an ndarray and then use 'cv.asMatND()' to obtain a MatND
view, it would not work.
I'm a bit too busy this month. But I will try to nail this issue down as soon
as I can.
Cheers,
Minh-Tri
Original comment by pmtri80@gmail.com
on 9 Jun 2010 at 10:36
FYI, I have fixed the bug in the main trunk. However, the current version in
the main trunk is a transition version. There are a few changes that make some
functions incompatible with previous versions. But these changes are necessary
for the future.
Minh-Tri
Original comment by pmtri80@gmail.com
on 16 Jul 2010 at 2:34
Original issue reported on code.google.com by
ruoyu0...@gmail.com
on 9 Jun 2010 at 9:21