SIFT記述子とFLANNマッチャーを使用して、2つの画像間の一致の最小距離を取得しています。最初のピクチャはクエリピクチャで、2番目のピクチャはデータセットからのものです。私はループを使って1枚ずつ2枚目の画像を読み込みたいが、最初の反復の直後に、プログラムは実行時に最初の反復の結果を表示した後にクラッシュし、2回目の反復には失敗する。私はopencv 2.4.13とvs2017を使用しています。私は多くのことを試してみたし、ここに私の問題と観測されている記述子の一致後にopencvプログラムがクラッシュする
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include <opencv2/legacy/legacy.hpp>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using namespace cv;
#define IMAGE_folder "D:\\Project\\dataset1" // change to your folder location
int main()
{
initModule_nonfree();
const int filename_len = 900;
char tempname1[filename_len];
sprintf_s(tempname1, filename_len, "%s\\%s", IMAGE_folder, "995.jpg");
Mat i1 = imread(tempname1);
Mat img1, img2;
cvtColor(i1, img1, COLOR_BGR2GRAY);
if (!i1.data)
{
printf("Cannot find the input image!\n");
system("pause");
return -1;
}
std::vector<KeyPoint> key_points1, key_points2;
Mat descriptors1, descriptors2;
SIFT sift;
sift(img1, Mat(), key_points1, descriptors1);
for (int i = 990; i < 1000; i++)
{
initModule_nonfree();
cout << i << endl;
char tempname2[filename_len];
sprintf_s(tempname2, filename_len, "%s\\%d.jpg", IMAGE_folder, i);
Mat i2 = imread(tempname2);
if (!i2.data)
{
printf("Cannot find the input image!\n");
system("pause");
return -1;
}
cvtColor(i2, img2, COLOR_BGR2GRAY);
sift(img2, Mat(), key_points2, descriptors2);
FlannBasedMatcher matcher;
vector<DMatch> matches;
matches.clear();
matcher.match(descriptors1, descriptors2, matches); //if I comment this line and the code below to show the distance, it can work
double max_dist = 0;
double min_dist = 100;
for (int j = 0; j < descriptors1.rows; j++)
{
double dist = matches[j].distance;
if (dist < min_dist)
min_dist = dist;
if (dist > max_dist)
max_dist = dist;
}
//matcher.clear(); //I've tried these four but still cannot help
//matches.clear();
//key_points1.clear();
//key_points2.clear();
printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);
cout << "Done!" << endl;
}
//waitKey(0);
return 0;
}
::私は反復を使用しているため
- それはないですが、以下は私のコードです。
matcher.match(descriptors1, descriptors2, matches);
だけを実行すると、実行後もクラッシュします。 - SURFディスクリプタまたはBruteForceMatcherでも動作していませんが、どちらも上記のコードで同じ問題があります。私はSURFを使ってopencvチュートリアルとは異なるコードを使用しましたが、結果を表示した後もクラッシュします。 Example code from opencv tutorial see here
- 私も
initModule_nonfree();
と答えましたが、依然として助けにはなりませんでした。 - 「完了!」と表示された後にプログラムがクラッシュします。次の反復には進まない。
matcher.match(descriptors1, descriptors2, matches);
とそれに関連するコードを削除すると、正常に動作します。したがって、問題は「一致」機能でなければなりません。
ありがとうございます!
-----------------------------更新---------------- -------------
私は含まれており、リンクされたライブラリは以下の通りである:
C:\プログラムファイル(x86の)\ OpenCVの\構築\は Cが含ま:\プログラムファイルを(x)\ opencv \ build \ include \ opencv C:¥Program Files(x86)¥opencv¥build¥include¥opencv2
C:¥Program Files(x86)¥opencv¥build¥x64¥vc12¥staticlib C:¥Program Files(x86)¥opencv¥build¥x64¥vc12¥lib
opencv_objdetect2413.lib opencv_ts2413.lib opencv_video2413.lib opencv_nonfree2413.lib opencv_ocl2413.lib opencv_photo2413.lib opencv_stitching2413.lib opencv_superres2413.lib opencv_videostab2413.lib opencv_calib3d2413.lib opencv_contrib2413.lib opencv_core2413.lib opencv_imgproc2413.libオープンopencv_highgui2413.lib opencv_gpu2413.lib opencv_flann2413.lib opencv_features2d2413.lib cv_legacy2413.lib opencv_ml2413.lib
私は設定に問題がないかもしれないと思います...私はx86の下でリリースモードで使っています!
含めるとリンクされたライブラリを表示 – Miki
私の質問に感謝! – Wendy
vc12(Visual Studio 2013)でビルドして、64ビットライブラリにリンクしています。明らかにこれは動作しません – Miki