###前提・実現したいこと
OpenCVでカメラからのとまれの一時停止標識を検出しようと思っています
VisualStudioに全く触ったことがなく、Linux上で開発していました。
初心者で分かりません。
###発生している問題・エラーメッセージ
63行目のtargets.size()で"18446743988082066159"という大きな値が出てきます。
この後のfor文で多く回ってしまうことでウィンドウが表示されないのだと思います。
###該当のソースコード
#include <iostream> // for standard I/O #include <string> // for strings #include <iomanip> // for controlling float print precision #include <sstream> // string to number conversion #include <stdlib.h> #include <vector> #include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar) #include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur #include <opencv2/highgui/highgui.hpp> // OpenCV window I/O #include <opencv2/objdetect/objdetect.hpp> #include <opencv2/videoio/videoio.hpp> #define _TRIANGLETESTMAIN using namespace cv; //using namespace std; static void showUsage(const char *cmd) { std::cerr << cmd << ": [-h] imageFilename trainFilename" << std::endl; std::cerr << " -n: do not open display windows" << std::endl; } int main(void) { Mat frame; VideoCapture cap(0); if (!cap.isOpened()) { std::cerr << "Cannot open camera." << std::endl; return 1; } namedWindow("Output", WINDOW_AUTOSIZE); CascadeClassifier clsf; try { clsf.load("001/cascade.xml"); } catch (Exception& e) { const char* err_msg = e.what(); std::cout << err_msg << std::endl; } if (clsf.empty()) { std::cerr << "cannot load cascade file" << std::endl; exit(-1); } std::vector<Rect> targets; while (1) { cap >> frame; clsf.detectMultiScale(frame, targets); if (clsf.empty()) { std::cerr << "cannot load cascade file" << std::endl; exit(-1); } else { std::cout << "read" << std::endl; } std::cout << targets.size() << std::endl; for (int i = 0; i < targets.size(); i++) { rectangle(frame, Rect(targets[i].x, targets[i].y, targets[i].width, targets[i].height), Scalar(255, 0, 0), 2); } imshow("Output", frame); char c = (char)waitKey(10); if (c == 'q') { break; } } endOfMovie: destroyWindow("Output"); return 0; }
###補足情報(言語/FW/ツール等のバージョンなど)
環境
CMakeでOpenCVインストールしました。
opencv3.2
visual studio2017
プロパティ
C/C++
追加のインクルードディレクトリ C:\opencv-3.2.0\build\install\include;
リンカー
追加のライブラリディレクトリ C:\opencv-3.2.0\build\install\x64\vc15\lib
追加依存ファイル 追加のライブラリディレクトリにあるものはすべて追加しました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/21 02:22
2017/06/21 03:08
2017/06/24 16:11
2017/06/24 20:45