1

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).

Community
  • 1
  • 1
hjweide
  • 11,893
  • 9
  • 45
  • 49
  • Can you add a detailed tutorial on how you compiled OpenCV from source using cmake and visual studio 2010 ? Or atleast share a good reference which helped you. Mine always ends up in some errors. – Abid Rahman K Apr 16 '13 at 17:39
  • did you flag your functions/definitions as CV_EXPORTS ? – berak Apr 16 '13 at 18:20
  • @AbidRahmanK, I don't want to enter a discussion here, but my original build was some time ago, if I can find the link I will paste it. @berak, Yes, I did it exactly the same as all the other questions in the `.hpp` file, I think it was `CV_EXPORTS_W`, but I did add it. – hjweide Apr 16 '13 at 18:23

1 Answers1

1

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.

hjweide
  • 11,893
  • 9
  • 45
  • 49