WebCam using error with opencv and c++
There is a c++ code for capturing from webcam. This is a code.
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char *argv[])
{
VideoCapture vid(0);
if(!vid.isOpened()){
cout<<"Camera could not load..."<<endl;
return -1;
}
namedWindow("webcam",CV_WINDOW_AUTOSIZE);
while(1){
Mat frame;
bool ctrl = vid.read(frame);
imshow("webcam",frame);
if(waitKey(0) == 27){
cout<<"The app is ended..."<<endl;
break;
}
}
return 0;
}
But when I try to compile it : g++ webcam.cpp -lopencv_core -lopencv_highgui
it raises an error
/tmp/ccApncrK.o: In function `main':
webcam.cpp:(.text+0x1a): undefined reference to `cv::VideoCapture::VideoCapture(int)'
webcam.cpp:(.text+0x26): undefined reference to `cv::VideoCapture::isOpened() const'
webcam.cpp:(.text+0xc3): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
webcam.cpp:(.text+0x195): undefined reference to `cv::VideoCapture::~VideoCapture()'
webcam.cpp:(.text+0x1f7): undefined reference to `cv::VideoCapture::~VideoCapture()'
collect2: error: ld returned 1 exit status
Can you help me, please. PS. (I am using Ubuntu...)
similar problem, as in your other question, the libs in opencv 2.4 and 3.0 differ. in this case you'll additionally need
-lopencv_videoio
@jayshree, -- please do not post answer, if you do not have any.
sorry. I did not see your comment
Hi, give the path of the opencv library with -L flag.