make python binder return a list
Hello
I made a custom module in c++ in which I have a function that extract a sequence of images (aka a video with a uncommon format, not an image set) from a file. My function is declare as:
CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);
And instantiate as:
void read_myJFile(const cv::String &filename, cv::OutputArrayOfArrays img, const int &fmt)
{
CV_Assert(img.isMat() || img.isMatVector() || img.isUMatVector());
std::vector<cv::Mat> data;
std::vector<cv::Mat> dst;
// Here goes the code that fill data with the content of the file specified.
if(img.isMat()) // work as long data's size is lower than CV_MAX_CN.
cv::merge(datas,img);
img.create(data.size(),1,data.front().type());
img.assign(data);
}
The compilation work like a charm, how when I try to call it from python I receive that message:
OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'
I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat
Otherwise what should I do (write) for make the binder understand ?
Thanks in advance for any help
hi, nice you finally made it ! (and apologies for being some kind of brutal before, i'm sure , that was just bad luck, or a network hickup)
I don't want to be impolite but Insult me, and block my account for a mistake is it a bit a lot don't you think ? I taught I was just refreshing the page I did not realize that each time I press F5 my question was resubmit. However I would to get my other account because of the email I am using with this account is temporary, what can I do ? Nevertheless I am happy to work with you.
@js4267, i'm sure you did not intend to sent out 15 indentical posts, yet it happened. and you showed no intent to clean those up, immediately, so some red button pushed here.
(since this site is abused by spammers a lot, there's a moderation queue in place, re-sending it won't do any good, until one of the mods here gives you a green light)
please. let's get over this.you had a bad start, but your question is entirely valid (and even some kind of interesting !)
If I had figure that out obviously I would have remove all the duplicates I just need one post. Agree with you about the actual question, so there any Keyword or file that I can add in order to make the binder understand the expected type of the second argument of my function ?
Initially In order to prevent a duplication in memory I set the output vector of Mat by doing :
Where
data
is and internal vector of Mat and then I just do a for loop withimg.getMat(i) = data.at(i);
Seeing that it does not work I take a look to
cv::split
then I try to preallocate the memory of each image of image by doing:img.create(image_size,image_depth,i);
I was thinking that may by doing this the binder would understand that what I return is a list. But nothing change.btw, can you explain, why this is needed ? (which problem does it solve, exactly ?)
both python and opencv have a glob like function to traverse a diirectory / file list
:( I have several files that containt a video streams using a particular format (I am working with infrared images) I want to load those files (the function we are discussing about have this purpose) then make a processing and save each stream image per image in a directory. glob like function only list files and subdirectories, recursively or not depending of the arguments.
I just in python to preset a list and send it as second argument of the function without success. Basically what I am looking for is a kind behaviour of
cv::split
in python concerning the ability to return a list (or even a tuple) of arguments.Does the native modules (core, imgproc,...) function and classes procces by the binder ?
yes, it does.
you can see the generated code in
opencv/build/modules/python_bindings_generator/pyopencv_generated_funcs.h
, that's also, where the wrapper for your function will show up.maybe it's helpful, if you add the c++ function & the generated code for it to your question (it won't fit into a comment !) , also maybe your intended python usage of it ?