Skip to content

PyMat.get_data type conversion error #5

@dgeddy

Description

@dgeddy

Hi,

when trying to retrieve the data from a depth map via PyMat.get_data(), the return data type is derived incorrectly. I've traced it down to these lines in pyzed/core.pyx:

391:        if self.mat.getDataType() == MAT_TYPE_8U_C1 or MAT_TYPE_8U_C2 or MAT_TYPE_8U_C3 or MAT_TYPE_8U_C4:
392:            size = self.mat.getHeight()*self.mat.getWidth()*self.mat.getChannels()
393:            dtype = np.uint8
394:        elif self.mat.getDataType() == MAT_TYPE_32F_C1 or MAT_TYPE_32F_C2 or MAT_TYPE_32F_C3 or MAT_TYPE_32F_C4:
395:            size = self.mat.getHeight()*self.mat.getWidth()*self.mat.getChannels()*sizeof(float)
396:            dtype = np.float32

The comparison on line 391 always evaluate to True (the same holds for line 394, but that one is never executed). As a result, the size and type are calculated incorrectly for floating point data.

I suppose that was was really meant, is something like this:

391:        if self.mat.getDataType() in (MAT_TYPE_8U_C1, MAT_TYPE_8U_C2, MAT_TYPE_8U_C3, MAT_TYPE_8U_C4):
            ...
394:        elif self.mat.getDataType() in (MAT_TYPE_32F_C1, MAT_TYPE_32F_C2, MAT_TYPE_32F_C3, MAT_TYPE_32F_C4):
            ...

With this fix, I can retrieve the floating point depth map data correctly.

Best regards,
Eddy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions