Ask Your Question
0

WebCam using error with opencv and c++

asked 2015-03-27 13:14:04 -0500

namiqaliyev gravatar image

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...)

edit retag flag offensive close merge delete

Comments

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

berak gravatar imageberak ( 2015-03-27 13:47:39 -0500 )edit

@jayshree, -- please do not post answer, if you do not have any.

berak gravatar imageberak ( 2016-10-07 11:01:05 -0500 )edit

sorry. I did not see your comment

jayshree gravatar imagejayshree ( 2016-10-07 12:06:38 -0500 )edit

Hi, give the path of the opencv library with -L flag.

Akhilesh gravatar imageAkhilesh ( 2016-12-23 04:07:13 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2016-08-01 05:38:02 -0500

Link following libraries and it should work g++ webcam.cpp -o objDetection -lopencv_core -lopencv_imgproc -lopencv_objdetect -lopencv_highgui

edit flag offensive delete link more

Comments

sorry, but this is incorrect.

for opencv3 you'll need -lopencv_videoio (for the webcam), also objdetect is only nessecary for cascade detection or similar.

berak gravatar imageberak ( 2016-08-01 05:40:21 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-03-27 13:14:04 -0500

Seen: 3,891 times

Last updated: Oct 07 '16