"Function not declared in this scope" 编译 openCV 代码时出错
"Function not declared in this scope" Error in compiling openCV code
我正在尝试编写一些使用openCV函数的代码。我首先从文档中提供的一些示例代码开始:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1]); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
当我尝试在EclipseCDT中构建它时,我得到的是:
**** Build of configuration Debug for project openCV1 ****
make all
Building target: openCV1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "openCV1" ./src/displayImage.o
./src/displayImage.o: In function `main':
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:25: undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:33: undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:36: undefined reference to `cv::waitKey(int)'
./src/displayImage.o: In function `~Mat':
/usr/local/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
./src/displayImage.o: In function `cv::Mat::operator=(cv::Mat const&)':
/usr/local/include/opencv2/core/mat.hpp:298: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
./src/displayImage.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
make: *** [openCV1] Error 1
**** Build Finished ****
当我使用g++(g++ -o displayImageInput displayImageInput.cpp
pkg配置opencv--cflags--libs)构建时,也可以使用相同的代码。
然后我更改了代码,使图像灰度,
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1]); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
Mat grey;
cvtColor(image, grey, CV_BGR2GRAY);
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", grey);
waitKey(); // Wait for a keystroke in the window
return 0;
}
当使用g++构建时,它给出了以下错误:
dispImgSobel.cpp: In function ‘int main(int, char**)’:
dispImgSobel.cpp:34:27: error: ‘CV_BGR2GRAY’ was not declared in this scope
dispImgSobel.cpp:34:38: error: ‘cvtColor’ was not declared in this scope
我需要两件事的帮助,如何让它在Eclipse中工作,第二,如何解决这个范围错误,针对这个和未来的用例。
-
第一个错误是链接器问题。您没有链接到opencv_core.a和opencv_highui.a
经验法则:对于包含的每个模块头,都需要链接相应的库。
-
第二个是编译器问题,您忘记了一个标头
#include <opencv2/imgproc/imgproc.hpp>
和,ofc。需要链接opencv_imgproc
确保pkg-config opencv --cflags --libs
输出中的所有内容都在链接器的搜索路径中。
还有一个用于Eclipse的pkg配置插件,它将允许您直接将上面的确切字符串放入,而不是手动添加输出的每一项。
相关文章:
- Mingw-64 在构建和安装后不会编译 openCV 代码
- OpenCV代码不会检测人脸的数量,也不会在脸周围放一个圆圈
- 将 OpenCV 2 中的ANN_MLP代码转换为 OpenCV 3 代码
- 使用Bicubic C 的调整大小函数的OPENCV代码流是什么?
- cv:内存位置的异常 - 运行 openCV 代码 Visual Studio 2013 & Visual Studio 2017 - Windows 7
- 使用 Emscripten 将 OpenCV 代码编译C++ Javascript
- 如何在Android中使用OpenCV C 代码
- 想要将此 Matlab 代码转换为 OpenCV 代码
- 如何在Ubuntu 16.04上的Anaconda环境中将OpenCV C 代码与Python代码集成在一起
- 无法解决 opencv 代码中的 malloc 错误
- opencv 代码中的错误:C++
- 任何人都可以向我解释此OPENCV代码的一部分
- 使用MATLAB通过MEX运行OPENCV代码在VisualStudio上可以使用
- 以下使用 OpenCV 代码的C++未编译
- 在c#应用程序中调用opencv c++代码
- Visual如何使用OPENCV(C 代码)访问IP摄像机?有没有一种方法可以使用OpenCV VLC访问?(Win
- 在Visual Studio 2012中运行我的OpenCV代码时无法找出'u202A'警告
- OpenCV C++代码在终端中运行良好,但在从Ubuntu 12.04运行时出错
- 将 c++ opencv 代码更改为 android 代码
- OpenCV代码将存储在列表中的描述符与新的图像描述符进行比较