简体   繁体   中英

Adding my own function to OpenCV

I need to add a new method that computes connected components to OpenCV 2.4.4 to use in one of my own projects. I already have the code for the function from this question (Thanks to jason ), I navigated my way to the patch where I found both the code and the header.

What I did was to add a new file connectedcomponents.cpp in C:\\opencv\\modules\\imgproc\\src , in which I placed the code for this new function. Next, I went to C:\\opencv\\modules\\imgproc\\include\\opencv2\\imgproc and I added the appropriate export header to imgproc.hpp . Finally, I rebuilt the opencv_imgproc project in the OpenCV source code using Visual Studio 2010. Everything builds fine, and generates the opencv_imgproc244.dll , opencv_imgproc244.lib , and opencv_imgproc244.exp files for me.

Now, I copy these files (except for the .exp, where I can't find where it should go?) into my existing OpenCV directory and replace the old files. When I now try to build my own project, everything still builds fine, but I cannot access the new method from here. I include #include <opencv2/imgproc/imgproc.hpp> , and from here I can access all the other methods in the file, except for the new one that I want.

The fact that everything compiles but that the method is not exposed leads me to think there is some other file that I should have changed as well, however, due to lack of experience I do not know where or what this file could be.

Extra information: I am using Visual Studio 2010, OpenCV 2.4.4 and built OpenCV with CMake 2.8.10.2 I am aware that there are libaries such as cvBlobsLib that compute connected components, and I have successfully used these in my project. However, I want a faster and more recent solution (cvBlobsLib still uses the old IplImage).

So after looking at the problem with a fresh pair of eyes this morning, I immediately spotted my mistake. What I originally did was to add the new function's header code in

C:\\opencv\\modules\\imgproc\\include\\opencv2\\imgproc\\imgproc.hpp ,

but what I should've done is to also add it to

C:\\opencv\\build\\include\\opencv2\\imgproc\\imgproc.hpp ,

because this is the file that is included by any project that uses OpenCV. Everything works as planned now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM