0

我正在使用 C++,并使用“g++”编译和链接到 OpenCV2。困扰我的一件事是所有旧的 cv 前缀函数仍然可用并且“污染”了我的应用程序。

是否可以使 OpenCV1 C cv 前缀函数在我的应用程序范围内不可用,而只保留 OpenCV2cv::命名空间函数?

注意:我有一段时间没有写 C,所以如果这是一个愚蠢的问题,请告诉我。

4

1 回答 1

0

It depends on what do you really need. If you just want to make this code:

CvArr *arr;
cvAvg(arr);
cvAcc(arr, arr);

"not working" - you can just add this:

#define cvAvg nothing_interesting_cvAvg
#define cvAcc nothing_interesting_cvAcc
//you can change nothing_interesting_... to anything, but you can't use the same text more than once
//you include files
//...
//after your include files
#undef cvAvg
#undef cvAcc

before including any OpenCV file. If you now try to compile code you will see:

error C3861: 'cvAvg': identifier not found

If you change you code to use nothing_interesting_cvAvg(arr); instead of cvAvg(arr);, it will compile fine, but linker will fail, because:

: error LNK2019: unresolved external symbol _nothing_interesting_cvAvg referenced in function _main

Note that this will work only for this 2 functions, so you will have to find all functions which you want to "disable" and write similar code manually.
Functions which use "deactivated" functions will work fine, because they are already compiled, linked, etc - you will just call them from some files without changing anything in this files.

于 2013-01-11T08:42:51.000 回答