Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image is wrongly formed #25

Closed
jdddog opened this issue Aug 23, 2014 · 15 comments
Closed

Image is wrongly formed #25

jdddog opened this issue Aug 23, 2014 · 15 comments

Comments

@jdddog
Copy link

jdddog commented Aug 23, 2014

When I subscribe to the softkinetic camera's image topic I try to copy the image message with OpenCV and get an error (see below). This same code works for normal webcams.

cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(image_msg, sensor_msgs::image_encodings::BGR8);

I get this error:

terminate called after throwing an instance of 'cv_bridge::Exception'
what(): Image is wrongly formed: step < width * byte_depth * num_channels or 0 != 1280 * 1 * 3

Any ideas?

@corot
Copy link
Contributor

corot commented Aug 23, 2014

Yes, I saw the problem. I'll PR the fix soon. Meantime, you can patch your code. Add the missing image.step on line 155, like:

    image.width = w;///2;
    image.height = h;///2;
    image.step = w*3;

This should fix the problem, but tell me if not.

@jdddog
Copy link
Author

jdddog commented Aug 23, 2014

Awesome thanks :D

@jdddog
Copy link
Author

jdddog commented Aug 23, 2014

By the way, is the rgb_data image topic rectified? And if not, what do I need to do to rectify it?

@corot
Copy link
Contributor

corot commented Aug 23, 2014

Nope, afaik. But another softkinetic user send me this version of the code including calibration.

https://www.dropbox.com/s/m19y4yvgyr98lju/softkineticDemo.zip?dl=0

You need to change 'file:///home/haduong/calib/senz3d.yaml' (line 659).
You can calibrate the senz3d by yourself or use my calibration file. (http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration)

Please report any feedback about using it, so we can incorporate your experiences on the "official code"

@jdddog
Copy link
Author

jdddog commented Aug 25, 2014

Sweet thanks - that's so helpful! Would they mind if I pushed their code to my fork? Or do they already have one? (So other people collaborating with me can easily access it)

@corot
Copy link
Contributor

corot commented Aug 25, 2014

I assume it's not a problem. That's mostly an experiment to use the senz3d
as a laser scan. Feel free to do whatever, and contribute to the original
repo!

2014-08-25 8:51 GMT+02:00 Jamie Diprose notifications@github.com:

Sweet thanks - that's so helpful! Would they mind if I pushed their code
to my fork? Or do they already have one? (So other people collaborating
with me can easily access it)


Reply to this email directly or view it on GitHub
#25 (comment).

jdddog added a commit to jdddog/softkinetic that referenced this issue Aug 25, 2014
@jdddog
Copy link
Author

jdddog commented Aug 26, 2014

Cool thanks :) Is your calibration file for a Creative Senze3D, or another Softkinetic product? And where is it?

@jdddog
Copy link
Author

jdddog commented Aug 26, 2014

Actually dw, I found it in the workspace

@gavanderhoorn
Copy link
Contributor

@jdddog: just to be clear: the code posted by @corot does not rectify the image itself, it 'just' adds the necessary CameraInfo publisher to the driver node, so that image_proc/rectify can do the work.

@jdddog
Copy link
Author

jdddog commented Aug 31, 2014

Thanks, I was wondering how the actual rectification was done :)

If I want to project an image point (u,v) into the world that doesn't have a corresponding point in the point cloud, assuming I know the points depth, do I need to work from the rectified image or is rgb_data fine?

I notice that corot doesn't seem to rectify the image when mapping the image to points in the point cloud (correct me if I'm wrong), (from line 206 here: https://github.com/corot/softkinetic/blob/indigo-devel/softkinetic_camera/src/softkinetic_start.cpp). So I assume that I can just use rgb_data...

I was thinking of using the equation:
x = DEPTH * (u - cx) / fx
y = DEPTH * (v - cy) / fy
z = DEPTH

@gavanderhoorn
Copy link
Contributor

@jdddog: this is starting to turn into a forum thread. I think it'd be better if you created a question on ROS answers.

@jdddog
Copy link
Author

jdddog commented Aug 31, 2014

Haha ok, I've created a question :)

@corot
Copy link
Contributor

corot commented Oct 3, 2014

Also solved on indigo

@corot corot closed this as completed Oct 3, 2014
@ghost
Copy link

ghost commented Feb 7, 2018

Is this still a problem on ROS Kinetic with the cv_bridge::CvImage function toImageMsg()? I had this show up today when I'm trying to convert a .jpg file into the ROS pipeline through an intermediate cv::imread. If it's useful, I could paste snippets of my code here.

@kalyco
Copy link

kalyco commented Nov 14, 2019

Yes, I saw the problem. I'll PR the fix soon. Meantime, you can patch your code. Add the missing image.step on line 155, like:

    image.width = w;///2;
    image.height = h;///2;
    image.step = w*3;

This should fix the problem, but tell me if not.

This seems to cause the following issue
Image is wrongly formed: height * step != size or 240 * 1272 != 203520
, for example. Before changing step to width my issue was displaying Image is wrongly formed: step < width * byte_depth * num_channels or 848 != 424 * 1 * 3
A potential alternative fix could be to set width from 424 to 282, but that's a 34% decrease..

For context I am trying to convert a depth image of encoding 16UC1 to BGR8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants