opencv error: undefined reference to `cv::VideoCapture::VideoCapture()'
-
I try to use opencv3.2 with qt5.7,but I always get those erros:
/home/hunter/cameraTt/main.cpp:17: error: undefined reference tocv::VideoCapture::open(int)' /home/hunter/cameraTt/main.cpp:18: error: undefined reference to
cv::VideoCapture::isOpened() const'
/home/hunter/cameraTt/main.cpp:20: error: undefined reference tocv::VideoCapture::get(int) const' /home/hunter/cameraTt/main.cpp:22: error: undefined reference to
cv::VideoCapture::operator>>(cv::Mat&)'
/home/hunter/cameraTt/main.cpp:24: error: undefined reference to `cv::VideoWriter::VideoWriter()'
....
.proINCLUDEPATH += /usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_shape.so \
/usr/local/lib/libopencv_videoio.so \
main.cpp
#include "mainwindow.h"
#include <QApplication>
//#include<cv.h>
#include<QTimer>
#include<QPixmap>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
//using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();cv::VideoCapture m_cap; m_cap.open(0); assert(m_cap.isOpened()); int rate = m_cap.get(CV_CAP_PROP_FPS); cv::Mat frame; m_cap>>frame; cv::VideoWriter videowriter; videowriter.open("test.wmv",CV_FOURCC('W','M','V','2'),30,cv::Size(frame.cols,frame.rows)); assert(videowriter.isOpened()); char keycode; while ((keycode = cvWaitKey(30))) { if (keycode == 27) { break; } if (!m_cap.grab()) { break; } m_cap>>frame; videowriter<<frame; } videowriter.release(); return a.exec();
}
-
HI @_hunter,
LIBS += /usr/local/lib/libopencv_shape.so
/usr/local/lib/libopencv_videoio.soPlease change the linker lines to this,
LIBS += -L/usr/local/lib -lopencv_shape -lopencv_videoio
and try again.
If it does not work, please prove the linker command line from the compile log.
Regards
-
@aha_1980 said in opencv error: undefined reference to `cv::VideoCapture::VideoCapture()':
compile log
sorry,i do not know the location of compile log.I did what you sugget and here are the new errors:
:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
/usr/local/lib/libopencv_core.so.3.2:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status -
@SuganyaSP Did you do what @aha_1980 suggested?
-
@SuganyaSP i am working on ubuntu18 with qt 4.5.2 opencv4
solved this problem withINCLUDEPATH += /usr/local/include/opencv4
LIBS += $(shell pkg-config opencv --libs)
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_shape -lopencv_videoio -lopencv_imgproc
then make a "rebuid"