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

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

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

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Q&A

1回答

3214閲覧

(緊急)opencv 強制終了する。

hidekiM

総合スコア10

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

0グッド

0クリップ

投稿2016/01/21 06:43

下のサンプルコードで行ったところ、二次元座標所得の際に強制終了が発生しました。
以前にも色々試行錯誤をしているのですが、うまくいきません。

これは文字設定などによる条件の違いでしょうか。
もしそうであれば、詳しく教えてください。

コード元は「VC++勉強部屋」の三角測量での三次元復です。

#define NOMINMAX

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <windows.h>
#include <iostream>
#include <stdlib.h>

#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/video/video.hpp>

#pragma comment(lib,"opencv_video2411d.lib")
#pragma comment (lib,"opencv_nonfree2411d.lib")
using namespace cv;
using namespace std;

int main(int argc, char argv[])
{

vector<Point3f> points3D; points3D.push_back(Point3f(-100, -100, -100)); points3D.push_back(Point3f(100, -100, -100)); points3D.push_back(Point3f(100, -100, 100)); points3D.push_back(Point3f(-100, -100, 100)); points3D.push_back(Point3f(-100, 100, -100)); points3D.push_back(Point3f(100, 100, -100)); points3D.push_back(Point3f(100, 100, 100)); points3D.push_back(Point3f(-100, 100, 100)); float hbi = 150; float distance = 800; Mat cameraMatrix = (Mat_<float>(3, 3) << 320, 0, 160, 0, 320, 120, 0, 0, 1); Mat distCoeffs = (Mat_<float>(5, 1) << 0, 0, 0, 0, 0); Mat rvec = (Mat_<float>(3, 1) << 0, 0, 0); Mat tvecL = (Mat_<float>(3, 1) << hbi, 0, distance); Mat tvecR = (Mat_<float>(3, 1) << -hbi, 0, distance); vector<Point2f>imagePointsL; projectPoints(points3D, rvec, tvecL, cameraMatrix, distCoeffs, imagePointsL); cout << "imagePointsL" << endl; cout << imagePointsL << endl << endl; Mat dst_imageL = Mat(Size(320, 240), CV_8UC3, Scalar::all(255)); for (int i = 0; i < 8; i++) circle(dst_imageL, imagePointsL[i], 2, Scalar::all(0), -1); for (int i = 0; i < 4; i++) { line(dst_imageL, imagePointsL[i], imagePointsL[(i + 1) % 4], Scalar::all(0)); line(dst_imageL, imagePointsL[i + 4], imagePointsL[((i + 1) % 4) + 4], Scalar::all(0)); line(dst_imageL, imagePointsL[i], imagePointsL[i + 4], Scalar::all(0)); } namedWindow("L画像(基準長=300)"); imshow("L画像(基準長=300)", dst_imageL);; //----------------------------------------- vector<Point2f>imagePointsR; projectPoints(points3D, rvec, tvecR, cameraMatrix, distCoeffs, imagePointsR); cout << "imagePointsR" << endl; cout << imagePointsR << endl << endl; //Mat dst_imageR = Mat(Size(320, 240), CV_8UC3, Scalar::all(255)); //for (int i = 0; i < 8; i++) // circle(dst_imageR, imagePointsR[i], 2, Scalar::all(0), -1); //for (int i = 0; i < 4; i++) //{ // line(dst_imageR, imagePointsR[i], imagePointsR[(i + 1) % 4], Scalar::all(0)); // line(dst_imageR, imagePointsR[i + 4], imagePointsR[((i + 1) % 4) + 4], Scalar::all(0)); // line(dst_imageR, imagePointsR[i], imagePointsR[i + 4], Scalar::all(0)); //} //namedWindow("R画像(基準長=300)"); //imshow("R画像(基準長=300)", dst_imageR); //----------------------------------------- Mat projectMatrixL = (Mat_<float>(3, 4) << 320, 0, 160, hbi * 320, 0, 320, 120, 0, 0, 0, 1, 0); Mat projectMatrixR = (Mat_<float>(3, 4) << 320, 0, 160, -hbi * 320, 0, 320, 120, 0, 0, 0, 1, 0); Mat points4D; vector<Point3f> points3D_result; cout << "座標位置(X,Y,Z)" << endl; for (int i = 0; i < 8; i++) { triangulatePoints(projectMatrixL, projectMatrixR, Mat(imagePointsL[i]), Mat(imagePointsR[i]), points4D); convertPointsFromHomogeneous(points4D.reshape(4, 1), points3D_result); cout << points3D_result << endl; } waitKey(); destroyAllWindows(); return 0;

}

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

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

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

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

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

guest

回答1

0

こんにちは。

MSVC 2013+OpenCV 2.4.9の組み合わせでやってみました。
リンクエラーがでたので、OpenCVのライブラリを片っ端からリンクしたら、動作しました。
ワイヤーフレームの六面体が1つ表示されましたよ。

開発環境の設定を何かミスられているのかも知れません。

投稿2016/01/21 10:08

Chironian

総合スコア23272

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問