私はUbuntuの16.04 Original CodeOpenCV2コードリンケージエラー
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main (int argc, const char * argv[])
{
VideoCapture cap(CV_CAP_ANY);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if (!cap.isOpened())
return -1;
Mat img;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
while (true)
{
cap >> img;
if (!img.data)
continue;
vector<Rect> found, found_filtered;
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
size_t i, j;
for (i=0; i<found.size(); i++)
{
Rect r = found[i];
for (j=0; j<found.size(); j++)
if (j!=i && (r & found[j])==r)
break;
if (j==found.size())
found_filtered.push_back(r);
}
for (i=0; i<found_filtered.size(); i++)
{
Rect r = found_filtered[i];
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.06);
r.height = cvRound(r.height*0.9);
rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
}
imshow("video capture", img);
if (waitKey(20) >= 0)
break;
}
return 0;
}
にC++でOpenCVのとHOG特徴検出のために、この簡単なデモをコンパイルしようと、私は私が
g++ -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab hog.cpp
でコードをコンパイルしてみました次のエラーが発生する
/tmp/cctllC37.o: In function `main':
hog.cpp:(.text+0x38): undefined reference to `cv::VideoCapture::VideoCapture(int)'
hog.cpp:(.text+0x65): undefined reference to `cv::VideoCapture::set(int, double)'
hog.cpp:(.text+0x92): undefined reference to `cv::VideoCapture::set(int, double)'
hog.cpp:(.text+0xa1): undefined reference to `cv::VideoCapture::isOpened() const'
hog.cpp:(.text+0xdc): undefined reference to `cv::HOGDescriptor::getDefaultPeopleDetector()'
hog.cpp:(.text+0x10e): undefined reference to `cv::HOGDescriptor::setSVMDetector(cv::_InputArray const&)'
hog.cpp:(.text+0x15b): undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
hog.cpp:(.text+0x17e): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
hog.cpp:(.text+0x23b): undefined reference to `cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const'
hog.cpp:(.text+0x51e): undefined reference to `cv::rectangle(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
hog.cpp:(.text+0x545): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
hog.cpp:(.text+0x588): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
hog.cpp:(.text+0x5b0): undefined reference to `cv::waitKey(int)'
hog.cpp:(.text+0x637): undefined reference to `cv::VideoCapture::~VideoCapture()'
hog.cpp:(.text+0x71f): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cctllC37.o: In function `cv::Mat::~Mat()':
hog.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctllC37.o: In function `cv::Mat::release()':
hog.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
/tmp/cctllC37.o: In function `cv::HOGDescriptor::HOGDescriptor()':
hog.cpp:(.text._ZN2cv13HOGDescriptorC2Ev[_ZN2cv13HOGDescriptorC5Ev]+0xd): undefined reference to `vtable for cv::HOGDescriptor'
/tmp/cctllC37.o: In function `cv::HOGDescriptor::~HOGDescriptor()':
hog.cpp:(.text._ZN2cv13HOGDescriptorD2Ev[_ZN2cv13HOGDescriptorD5Ev]+0xd): undefined reference to `vtable for cv::HOGDescriptor'
/tmp/cctllC37.o: In function `cv::_InputArray::_InputArray<float>(std::vector<float, std::allocator<float> > const&)':
hog.cpp:(.text._ZN2cv11_InputArrayC2IfEERKSt6vectorIT_SaIS3_EE[_ZN2cv11_InputArrayC5IfEERKSt6vectorIT_SaIS3_EE]+0x11): undefined reference to `vtable for cv::_InputArray'
collect2: error: ld returned 1 exit status
私は別のCompi ler Flags、しかし何も動作していないようです。 デフォルトのUbuntu reproで見つけられるopenCVパッケージをすべてインストールしました。
をあなたはライブラリの順序は右だ100%か?もしそうでなければ、全ての '-l'フラグを' -Wl、 - start-group ... -Wl、 - end-group'セクションに入れます。 – user0042