pot*_*mer 14 c++ ubuntu opencv cmake
我刚按照说明在我的ubuntu计算机上安装opencv 3(我已经在不同的linux设备上使用opencv 3安装和运行程序),但是,当我尝试从我的旧计算机运行我的一个测试程序时我收到以下错误:
CMakeFiles/VideoTest.dir/VideoTest.cpp.o: In function `main':
VideoTest.cpp:(.text+0x6f): undefined reference to `cv::VideoWriter::fourcc(char,char,char, char)'
VideoTest.cpp:(.text+0xc3): undefined reference to `cv::VideoWriter::open(cv::String const&, int, double, cv::Size_<int>, bool)'
VideoTest.cpp:(.text+0x103): undefined reference to `cv::namedWindow(cv::String const&, int)'
VideoTest.cpp:(.text+0x146): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
VideoTest.cpp:(.text+0x1b1): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
CMakeFiles/VideoTest.dir/VideoTest.cpp.o: In function `cv::String::String(char const*)':
VideoTest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x3b): undefined reference to `cv::String::allocate(unsigned int)'
CMakeFiles/VideoTest.dir/VideoTest.cpp.o: In function `cv::String::~String()':
VideoTest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0xd): undefined reference to `cv::String::deallocate()'
collect2: ld returned 1 exit status
make[2]: *** [VideoTest] Error 1
make[1]: *** [CMakeFiles/VideoTest.dir/all] Error 2
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)
知道发生了什么事吗?我对opencv比较陌生.这是我的测试代码供参考:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[]){
VideoCapture vCap(0);
VideoWriter vWrite;
vWrite.open("test.avi", vWrite.fourcc('M','J','P','G'), 20, Size(640, 480), true);
while (1) {
namedWindow("VideoFeed", WINDOW_AUTOSIZE);
Mat frame;
vCap.read(frame);
vWrite.write(frame);
imshow("VideoFeed", frame);
char c = waitKey(50);
if (c == 27) {
break;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
编辑:我的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(VideoTest)
find_package(OpenCV REQUIRED)
add_executable(VideoTest VideoTest.cpp)
target_link_libraries(VideoTest ${OpenCV_LIBS})
Run Code Online (Sandbox Code Playgroud)
ber*_*rak 26
VideoCapture和VideoWriter被移动到3.0中的videoio模块,所以你必须另外
#include "opencv2/videoio.hpp"
Run Code Online (Sandbox Code Playgroud)
另外,您似乎没有链接到任何所需的opencv库,它们是:
opencv_core, opencv_videoio, opencv_highgui
Run Code Online (Sandbox Code Playgroud)
好吧,我终于弄清楚发生了什么.当我将目录移动到我的新系统时,CMakeFiles文件夹内部的东西变得棘手了.删除项目.cpp文件和CMakeLists.txt文件以外的所有文件/目录,然后运行"cmake".再次"制造"似乎解决了这个问题.
| 归档时间: |
|
| 查看次数: |
50452 次 |
| 最近记录: |