[英]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. 我需要添加一种新方法来计算与OpenCV 2.4.4相连的组件,以便在自己的项目中使用。 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. 我已经有了这个问题的函数代码(感谢jason ),我导航到了找到代码和标头的补丁 。
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. 我要做的是在C:\\opencv\\modules\\imgproc\\src
中添加一个新文件connectedcomponents.cpp
,在其中放置了此新功能的代码。 Next, I went to C:\\opencv\\modules\\imgproc\\include\\opencv2\\imgproc
and I added the appropriate export header to imgproc.hpp
. 接下来,我转到C:\\opencv\\modules\\imgproc\\include\\opencv2\\imgproc
,并将适当的导出标头添加到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. 最后,我使用Visual Studio 2010在OpenCV源代码中重建了opencv_imgproc
项目。一切都构建良好,并为我生成了opencv_imgproc244.dll
, opencv_imgproc244.lib
和opencv_imgproc244.exp
文件。
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. 现在,我将这些文件(.exp除外,找不到我应该去的地方?)复制到现有的OpenCV目录中,并替换旧文件。 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. 我包括#include <opencv2/imgproc/imgproc.hpp>
,从这里我可以访问文件中的所有其他方法,除了我想要的新方法。
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. 额外信息:我使用的是Visual Studio 2010,OpenCV 2.4.4,并使用CMake 2.8.10.2构建了OpenCV。我知道有些库(例如cvBlobsLib)可以计算连接的组件,并且已经在我的项目中成功使用了这些库。 However, I want a faster and more recent solution (cvBlobsLib still uses the old IplImage). 但是,我需要一个更快,更新的解决方案(cvBlobsLib仍使用旧的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
, 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
, C:\\opencv\\build\\include\\opencv2\\imgproc\\imgproc.hpp
,
because this is the file that is included by any project that uses OpenCV. 因为这是使用OpenCV的任何项目所包含的文件。 Everything works as planned now. 现在一切都按计划进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.