未声明Opencv函数

时间:2015-12-04 06:16:49

标签: opencv3.0

我切换到新的opencv 3.0,因为它更新,功能更多,但我遇到了问题。 当我编译完全适用于2.4.8版本的旧代码时,它找不到一些函数:

error: ‘resize’ was not declared in this scope
error: ‘VideoCapture’ was not declared in this scope
error: ‘namedWindow’ was not declared in this scope
error: ‘cvtColor’ was not declared in this scope
error: ‘imshow’ was not declared in this scope
error: ‘Sobel’ was not declared in this scope

这里以一小段代码为例:

TEST.CPP:

#include <opencv/highgui.h>
#include <opencv/cv.h>

using namespace cv;

int main( int argc, char** argv ) 
{
    IplImage* imgX;
    IplImage* img = cvLoadImage( argv[1] );

    Sobel(img, imgX, CV_32F, 1, 0, 1);

    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Example1", imgX );    
    cvWaitKey(0);
    cvReleaseImage( &imgX );
    cvDestroyWindow("Example1");
}

CMakeList.txt:

cmake_minimum_required (VERSION 2.6)
project (Test)
find_package( OpenCV REQUIRED )
add_executable(Test test.cpp)
target_link_libraries( Test ${OpenCV_LIBS} )

并输出:

Scanning dependencies of target Test
[100%] Building CXX object CMakeFiles/Test.dir/test.cpp.o
/home/kairat/Dropbox/ComputerVision/Codes/test/test.cpp: In function ‘int main(int, char**)’:
/home/kairat/Dropbox/ComputerVision/Codes/test/test.cpp:11:34: error: ‘Sobel’ was not declared in this scope
  Sobel(img, imgX, CV_32F, 1, 0, 1);
                                  ^
CMakeFiles/Test.dir/build.make:54: recipe for target 'CMakeFiles/Test.dir/test.cpp.o' failed
make[2]: *** [CMakeFiles/Test.dir/test.cpp.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/Test.dir/all' failed
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2

在这种情况下我能做些什么?

1 个答案:

答案 0 :(得分:1)

索贝尔(img,imgX,CV_32F,1,0,1);这是sobel函数的c ++版本。

你应该使用c版本的sobel功能 即cvSobel(img,imgX,1,0,1);因为你正在处理C结构IPLimage。 注意:C版本的opencv函数通常以“cv”开头。

否则使用此功能将IPLimages转换为Mats Mat src = cvarrToMat(img)然后使用Sobel(src,srcX,CV_32F,1,0,1); 建议通过处理Mats来使用c ++函数,它具有更多的优点,如输出的自动内存分配/重新分配和自动释放内存。

相关问题