How can i use OpenCV algorithms in my project as a source code?

asked 2016-10-28 10:39:05 -0600

Grifel79 gravatar image

I have a Visual Studio C++ project which uses OpenCV algorithms and some dll files are placed near .exe file in order to make OpenCV functionality working. What i want is to remove all dependencies in my project and use OpenCV as a source code. So it is not a question of changing dll to statically linked library (lib). I just want to put OpenCV cpp and h files in my project and use only the code i really need. I worry about cv::Mat if i still will be able to use it.

Thank you for advices how to perform this task. Maybe it would be useful also for some library users later. Any thoughts are welcome.

edit retag flag offensive close merge delete

Comments

unfortunately, with about 3000 files in the src code (and i'm not even counting any dependancies), your approach is no more feasible.

berak gravatar imageberak ( 2016-10-28 10:46:48 -0600 )edit

@berak but i can take the function i need, look at the dependencies and add these files to my project. As for core functionality, i could copy just files to deal with cv::Mat, and no need in output images with OpenCV. I understand that there are 3000 files, but i don't use all modules. I really cannot have dependencies in my project. I can rewrite some image processing algorithms, but i don't want to rewrite everything

Grifel79 gravatar imageGrifel79 ( 2016-10-28 10:54:29 -0600 )edit

oh, do you ?

so, if you need to read png image you add some files from imgcodecs, the 3rdparty libpng files and - wait it needs zlib ... ?

give up, lost case here.

berak gravatar imageberak ( 2016-10-28 10:57:48 -0600 )edit

" I can rewrite some image processing algorithms,"

-- why on earth are you using opencv, then ?

berak gravatar imageberak ( 2016-10-28 11:00:47 -0600 )edit
1

You can build OpenCV as a static lib, so there is no extra dll after compiling. Even if you use the source code of some functions a lot of code for data structures and other things is needed. In case of a static lib, the compiler will use only things you need for your code.

matman gravatar imagematman ( 2016-10-28 11:02:43 -0600 )edit

@berak Thanks for your attention, berak. I used OpenCV for kind of fast C++ prototyping. But at some point i need to remove it and it seems a little crazy for me too. But anyway i have to deal with it. I am free to use any open source code in the project. But no dependencies at all (dll or lib - any of this). Only put open source code to the project, edit it as i want. This is my task and i'm searching for the most simple and fast desicion how to perform it. That's why i thought about copying OpenCV sources. Maybe i can just store images in std::vector<vector<char>> STL container or even as a C style array. But if i manage to copy cv::Mat and leave only the OpenCV code i use it would be great.

Grifel79 gravatar imageGrifel79 ( 2016-10-28 11:08:08 -0600 )edit

unless you need opencv_contrib stuff, you can even build a single static lib (cmake -DBUILD_opencv_world=ON), so why go against the flow, and discard more than a dozen years of software engineering ?

berak gravatar imageberak ( 2016-10-28 11:09:11 -0600 )edit

" But if i manage to copy cv::Mat and remove the OpenCV code i don't use it would be great."

i'd like to disagree here. opencv is a high level, optimised matrix/vector library, your current approach removes any benefits (and reasons to use it in the 1st place)

berak gravatar imageberak ( 2016-10-28 11:12:54 -0600 )edit

@berak the target device is not a PC but some special mobile device processor with limited memory. So i cannot use any dependencies there, even .lib. Also the code will be converted to the C style code. But C is another story, as for now, i just have to remove OpenCV dependency. Convert C++ style code to C style code is not a very big deal. If there are another approach to get basic image processing algorithms code for the project, but not from OpenCV, i would be happy to know. I am just not familiar with it. As for me i always used OpenCV normally before this black day.

Grifel79 gravatar imageGrifel79 ( 2016-10-28 11:20:12 -0600 )edit

@Grifel97, don't get me wrong, - though i'm on the opposite side, i think, it's an interesting discussion !

maybe you can just reduce it to opencv_core & opencv_imgproc (and resp. dependancies)

berak gravatar imageberak ( 2016-10-28 11:21:57 -0600 )edit