I have installed opencv2.
pkg-config --modversion opencv
2.4.13.5
I am using below code,
#include <iostream>
#include <opencv2/opencv.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;
}
I compiled using, g++ image_writer.cpp
/tmp/ccPWmgA0.o: In function
main': image_writer.cpp:(.text+0x38): undefined reference to
cv::VideoCapture::VideoCapture(int)' image_writer.cpp:(.text+0x47): undefined reference tocv::VideoCapture::isOpened() const' image_writer.cpp:(.text+0xac): undefined reference to
cv::namedWindow(std::__cxx11::basic_string, std::allocator > const&, int)' image_writer.cpp:(.text+0xe9): undefined reference tocv::VideoCapture::read(cv::Mat&)' image_writer.cpp:(.text+0x105): undefined reference to
cv::_InputArray::_InputArray(cv::Mat const&)' image_writer.cpp:(.text+0x148): undefined reference tocv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' image_writer.cpp:(.text+0x170): undefined reference to
cv::waitKey(int)' image_writer.cpp:(.text+0x1cd): undefined reference tocv::VideoCapture::~VideoCapture()' image_writer.cpp:(.text+0x254): undefined reference to
cv::VideoCapture::~VideoCapture()' /tmp/ccPWmgA0.o: In functioncv::Mat::~Mat()': image_writer.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to
cv::fastFree(void*)' /tmp/ccPWmgA0.o: In functioncv::Mat::release()': image_writer.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to
cv::Mat::deallocate()' collect2: error: ld returned 1 exit status
After surfing I found, I have to include lib file
so, I did this. g++ image_writer.cpp -lopencv_videoio
/usr/bin/ld: cannot find -lopencv_videoio collect2: error: ld returned 1 exit status
I don't know how to fix this. please help me how to fix this. Any hint would be appreciable.
EDIT-1:
pkg-config --libs opencv
returns,
-L/usr/local/lib -lopencv_contrib -lopencv_stitching -lopencv_nonfree -lopencv_superres -lopencv_ocl -lopencv_ts -lopencv_videostab -lopencv_gpu -lopencv_photo -lopencv_objdetect -lopencv_legacy -lopencv_video -lopencv_ml -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtTest -lQtGui -lQtOpenGL -lIlmThread -lHalf -lIex -lIlmImf -lImath -ljasper -ltiff -lpng -ljpeg -lswscale-ffmpeg -lavutil-ffmpeg -lavformat-ffmpeg -lavcodec-ffmpeg -lv4l2 -lv4l1 -ldc1394 -lgstpbutils-0.10 -lgstriff-0.10 -lgstapp-0.10 -lgstvideo-0.10 -lxml2 -lglib-2.0 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lgstreamer-0.10 -lgstbase-0.10 -lGLU -lGL -lz -latomic -ltbb -lrt -lpthread -lm -ldl -lstdc++
pkg-config --libs opencv
. – Some programmer dude