質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

1回答

796閲覧

物体追跡のopencv,c++での実行

mikanken

総合スコア10

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

1クリップ

投稿2017/11/26 13:18

c++初心者なのですが、以下のコードを実行する際、コンパイル時に渡す引数はどのように書けばよろしいいのでしょうか?

opencv_multitracking.cpp:135:42: error: no matching constructor for
initialization of 'cv::MultiTracker'
...tracker = new cv::MultiTracker(tracker_algorithm);

opencv_multitracking.cpp:163:18: error: no matching member function for call to
'add'
if (tracker->add(Image, BBox))
~~~~~~~~~^~~
のエラーが出るのはコンパイル時の引数の設定の仕方がおかしいからなのでしょうか?

c++

1#include <opencv/cv.h> 2#include <opencv2/core.hpp> 3#include <opencv2/core/utility.hpp> 4#include <opencv2/tracking/tracker.hpp> 5#include <opencv2/highgui.hpp> 6 7static cv::Mat Image; 8static cv::Rect2d BBox; 9static std::string WindowName; 10static bool Paused; 11static bool SelectObject = false; 12static bool StartSelection = false; 13 14static const char* Keys = 15{ "{@tracker_algorithm | | tracker algorithm }" 16"{@video_name | | video name }" 17"{help h usage| |print this message }" 18}; 19 20static void Help(void) 21{ 22 std::cout << "\nThis example shows the functionality of \"Long-term optical tracking API\"" 23 "-- pause video [p] and draw a bounding box around the target to start the tracker\n" 24 "Call:\n" 25 "./tracker <tracker_algorithm> <video_name>\n" 26 << std::endl; 27 28 std::cout << "\n\nHot Keys: \n" 29 "\tq - quit the program\n" 30 "\tp - pause video\n"; 31} 32 33static void OnMouse(int event, int x, int y, int, void*) 34{ 35 if (!SelectObject) 36 { 37 switch (event) 38 { 39 case cv::EVENT_LBUTTONDOWN: 40 //set origin of the bounding box 41 StartSelection = true; 42 BBox.x = x; 43 BBox.y = y; 44 break; 45 case cv::EVENT_LBUTTONUP: 46 //sei with and height of the bounding box 47 BBox.width = std::abs(x - BBox.x); 48 BBox.height = std::abs(y - BBox.y); 49 Paused = false; 50 SelectObject = true; 51 break; 52 case cv::EVENT_MOUSEMOVE: 53 if (StartSelection) 54 { 55 //draw the bounding box 56 cv::Mat currentFrame; 57 Image.copyTo(currentFrame); 58 cv::rectangle(currentFrame, cv::Point(BBox.x, BBox.y), cv::Point(x, y), cv::Scalar(255, 0, 0), 2, 1); 59 cv::imshow(WindowName, currentFrame); 60 } 61 break; 62 } 63 } 64} 65 66bool CheckTrackerAlgType(cv::String& tracker_algorithm) 67{ 68 if (tracker_algorithm == "BOOSTING" || 69 tracker_algorithm == "MIL" || 70 tracker_algorithm == "TLD" || 71 tracker_algorithm == "MEDIANFLOW" || 72 tracker_algorithm == "KCF") 73 { 74 std::cout << "Tracker Algorithm Type: " << tracker_algorithm << std::endl; 75 } 76 else{ 77 CV_Error(cv::Error::StsError, "Unsupported algorithm type " + tracker_algorithm + " is specified."); 78 } 79 return true; 80} 81 82int main(int argc, char** argv) 83{ 84 cv::CommandLineParser parser(argc, argv, Keys); 85 86 cv::String tracker_algorithm = parser.get<cv::String>(0); 87 cv::String video_name = parser.get<cv::String>(1); 88 89 parser.about("OpenCV Tracker API Test"); 90 if (parser.has("help")) 91 { 92 parser.printMessage(); 93 return 0; 94 } 95 96 if (tracker_algorithm.empty() || video_name.empty() || !parser.check()) 97 { 98 parser.printErrors(); 99 return -1; 100 } 101 102 CheckTrackerAlgType(tracker_algorithm); 103 104 //open the capture 105 cv::VideoCapture cap; 106 cap.open(video_name); 107 108 if (!cap.isOpened()) 109 { 110 Help(); 111 std::cout << "***Could not initialize capturing...***\n"; 112 std::cout << "Current parameter's value: \n"; 113 parser.printMessage(); 114 return -1; 115 } 116 117 cv::Mat frame; 118 Paused = true; 119 WindowName = "Tracking API: " + tracker_algorithm; 120 cv::namedWindow(WindowName, 0); 121 cv::setMouseCallback(WindowName, OnMouse, 0); 122 123 //instantiates the specific Tracker 124 cv::Ptr<cv::Tracker> tracker = cv::Tracker::create(tracker_algorithm); 125 if (tracker == NULL) 126 { 127 std::cout << "***Error in the instantiation of the tracker...***\n"; 128 return -1; 129 } 130 131 std::cout << "\n\nHot Keys: \n" 132 "\tq - quit the program\n" 133 "\tp - pause video\n"; 134 135 //get the first frame 136 cap >> frame; 137 frame.copyTo(Image); 138 cv::imshow(WindowName, Image); 139 bool initialized = false; 140 while (true) 141 { 142 if (!Paused) 143 { 144 cap >> frame; 145 frame.copyTo(Image); 146 147 if (SelectObject && !initialized) 148 { 149 //initializes the tracker 150 if (tracker->init(Image, BBox)) 151 { 152 initialized = true; 153 } 154 } 155 else if (initialized) 156 { 157 //updates the tracker 158 if (tracker->update(frame, BBox)) 159 { 160 cv::rectangle(Image, BBox, cv::Scalar(0, 0, 255), 2, 1); 161 } 162 else{ 163 SelectObject = initialized = false; 164 } 165 } 166 imshow(WindowName, Image); 167 } 168 char c = static_cast<char>(cv::waitKey(2)); 169 if (c == 'q') 170 break; 171 if (c == 'p') 172 Paused = !Paused; 173 } 174 175 return 0; 176}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yohhoy

2017/11/27 01:53

ファイルopencv_multitracking.cppは自作ソースファイルでしょうか?質問中ソースコードとエラーメッセージの対応が全く取れない状態です。
t_obara

2017/11/27 04:49

コードに問題があるのでビルド(コンパイル)できないということです。エラーコードを素直に読んで、該当するコードをどのように修正すべきかをご判断するしかないと思います。あるいはどこかから拾ってきたコードであるならば、コンパイラのバージョンが異なっているとか、ビルド環境が異なっているなどが考えられます。
guest

回答1

0

エラーが出るのはコンパイル時の引数の設定の仕方がおかしいからなのでしょうか?

はい。

https://docs.opencv.org/3.3.0/d8/d77/classcv_1_1MultiTracker.html

よくリファレンスを読んで下さい。


それはそうと無関係なソースコードを貼らないでください。添付するべきはopencv_multitracking.cppの中身です。

投稿2017/11/28 01:44

yumetodo

総合スコア5850

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問