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

IplImage row alignment #1

Open
jtbates opened this issue Sep 28, 2012 · 4 comments
Open

IplImage row alignment #1

jtbates opened this issue Sep 28, 2012 · 4 comments

Comments

@jtbates
Copy link

jtbates commented Sep 28, 2012

The libopencv routines assume that IplImage data is contiguous, but the rows are padded to be 4 or 8 byte aligned (although I've only observed 4 byte alignment).

http://opencv.willowgarage.com/documentation/c/core_basic_structures.html#align

As an example, this works:

t7> require 'opencv'
t7> require 'image'
t7> imgL=opencv.imgL()
t7> imgR=opencv.imgR()
t7> sc=opencv.StereoCorrespondenceGC(imgL,imgR)
t7> image.display(sc)

But this does not:

t7> sc_m1=opencv.StereoCorrespondenceGC(imgL[{{},{},{1,639}}],imgR[{{},{},{1,639}}])
t7> image.display(sc_m1)
@clementfarabet
Copy link
Collaborator

The interface was coded a bit too hastily :-). In C, there's an API function called THTensor_getContiguous(), which creates a contiguous tensor from any tensor. In Lua, that function is just called :contiguous(). These should always be used/called when creating interfaces to other libs.

@jtbates
Copy link
Author

jtbates commented Sep 29, 2012

I'm not sure how they would help in this case. For example, in the function

static IplImage * libopencv_(Main_torchimg2opencv_8U)(THTensor *source) {

the copy is done like this

TH_TENSOR_APPLY(real, tslice,
      *destp = (uchar)(*tslice_data * 255.0);
      // step through ipl
      destp = destp + dest->nChannels;
      );

Whether tslice is contiguous or not isn't the problem. It's that we're treating the raw data from IplImage as if widthStep == width.

I think this could be solved by dropping the macro and writing the inner loops, by padding tslice, or if you're feeling particularly evil by referencing the macro's loop variable inside the code we send it.

@soumith
Copy link

soumith commented Feb 7, 2013

I believe this was from a while ago, but fixed the bug in my branch and issued a pull request. Issue can be closed after pulled.
#3

@arthitag
Copy link

Hi,
I want to convert a real * variable to an IplImage *variable. Can you tell me how to do it?
thanks

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