lua---opencv
lua---opencv copied to clipboard
IplImage row alignment
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)
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.
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.
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. https://github.com/marcoscoffier/lua---opencv/pull/3
Hi, I want to convert a real * variable to an IplImage *variable. Can you tell me how to do it? thanks