change source and recompile
Hi
I'd like to change the opencv source a bit and recompile (I'd like access to the hough transform 'accumulator' image, which I see in the modules/imgproc/hough.cpp source but isn't exposed).
So what I did was make a copy of the function cv::HoughLines in hough.cpp , called it cv::HoughLinesWithAccumulator and made the corresponding definition in the imgproc.hpp file, then did a cmake which seemed to go ok (although there is some sort of download step, which I hope isn't somehow avoiding my changed code).
Hoping for a miracle (actually hoping for automatic wrapper-creation) I tried calling cv2.HoughLinesWithAccumulator instead of the working cv2.HoughLines call from my python code (which is where I've been using opencv for abt 1 yr) and as expected no such function exists in the opencv module.
So I'm downloading a C++ IDE and will try to call my new func from there; if that works, then I'll try to figure out how the python wrappers get made, and add my new function there.
Does this sound reasonable, are there some pitfalls and/or easier ways?
take a look here
did you prefix your new method declaration with a proper CV_EXPORTS_W ?
and yes, you will have to rebuild the opencv libs (and re-install cv2.pyd) to make it happen, though i doubt, that you need a c++ ide for this.
Thanks for your help first off, so far no dice: I had a declaration in include/opencv2/imgproc.hpp, monkeying the declaration that was already there for houghlines, for my version which i called houghlineswithaccumulator (in meantime keeping same arguments)
I read the link, thx I'm not sure how to resintall cv2.pyd , I tried find -name cv2.pyd and locate cv2.pyd but didn't find it. The C++ ide was just to check whether i can first of all call my new function from C++, next step pyt
the usual steps are:
then start python, import cv2, and do a
help(cv2.HoughLinesWithAccumulator)
to see, if it got in.whoops it looks like i shoudlve realized from your answer that i needed to copy the newly generated cv2.so to /usr/lib/python2.7/dist-package . Having done so I can now call my newly minted function, great! Now I will try changing arguments etc to actually get the output i need.
Just saw your above answer, yes that wouldve taken care of it. Thanks again for help, it looks like i am in right direction for the time being
a few birthing pains. I tried adding an output array to my function
along with the corresponding declaration in the .hpp header. This suffices to break my opencv install - i get the following ImportError: /usr/lib/python2.7/dist-packages/cv2.so: undefined symbol: _ZN2cv25HoughLinesWithAccumulatorERKNS_11_InputArrayERKNS_12_OutputArrayEddidddd
I don't think its related to allocating an array for the accumulator , i tried a few things such as Mat accumulator; accumulator.copyTo(_accumulator) or _accumulator = _image but no dice
make sure, your declaration and definition match exactly. seems, you compiled something different, than you showed to the python wrapper
"I don't think its related to allocating an array for the accumulator" - don't think so , too. if you do something wrong there, it will either lead to an empty Mat returned, or a runtime crash, not a linker error as above.
I can't seem to figure it - I added exactly one argument to the .cpp function and same to the .hpp, in the same place, with same type - .hpp entry below , in /opencv_src/modules/imgproc/include/opencv2/imgproc.hpp (and not in the .../include/opencv2/imgproc/imgproc.hpp which it looks like is not the right one):
ok, seems as tho the cv2.so wasn't getting regenerated after the cmake, make -j2 , and make install. So I wiped out the build directory and am trying again .
Now I get a working cv2.so (which i have to copy by hand into /usr/lib/python2.7/dist-packages , make install doesn't seem to do this). But I don't seem to have access to the extra output argument : when i try
the first line is ok while the second gives a 'too many values to unpack' so i guess my OutputArray is not getting picked up by the gen2 and/or hdr_parser scripts. I'll see if I can find output of those guys somewhere.
another small step forward (i think) - now i get an error 139 in python indicating bad memory access - so I'll try something besides the test I was attempting namely
which was an attempt to get the input image back as output image. I'll try