Skip to content

Conversation

@pkok
Copy link

@pkok pkok commented Sep 9, 2014

When the sensor_msgs/Image is converted to its numpy ndarray
representation, it sometimes has the shape (n, m, 1). This gives an
error even though it is a sensor_msgs::image_encodings::MONO8.

The underlying algorithm only supports 2D arrays, and the images were
stored as 3D objects. Error:

TypeError: Conversion is only valid for arrays with 1 or 2
dimensions. Argument has 3 dimensions

Transforming the image with a reshape if and only if it has a dimension
of lenght 1 solves this problem.

When the sensor_msgs/Image is converted to its numpy `ndarray`
representation, it sometimes has the shape `(n, m, 1)`.  This gives an
error even though it is a `sensor_msgs::image_encodings::MONO8`.

The underlying algorithm only supports 2D arrays, and the images were
stored as 3D objects.  Error:

```
TypeError: Conversion is only valid for arrays with 1 or 2
dimensions. Argument has 3 dimensions
```

Transforming the image with a reshape if and only if it has a dimension
of lenght 1 solves this problem.
@Kaapeine
Copy link

Kaapeine commented Aug 12, 2022

@goldbattle Can I help with this somehow? I've never seen this issue on a Ubuntu 18.04 OpenCV 3.2 setup.

@goldbattle
Copy link
Collaborator

goldbattle commented Aug 12, 2022 via email

@Kaapeine
Copy link

@goldbattle I took a look at the PR and the image conversion takes place in an early version of ImageDatasetReader.py which uses the older cv_bridge function to convert image messages. imgmsg_to_cv() would return an OpenCV IplImage which is deprecated in favour of Mat.

All subsequent versions of ImageDatasetReader.py use the newer imgmsg_to_cv2(). Is the change this PR adds still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants