1

画像からのポイント一致を比較するc++アプリケーション(OpenSurf C ++)を作成しましたが、数千の「getUniqueMatches」から1つ、アプリケーションが「getUniqueMatches」内のあるポイントで壊れることがあります。私はこのログを持っています:

05/13/11 10:17:16: this->pointsA = 227
05/13/11 10:17:16: this->pointsB = 226
05/13/11 10:17:16: this->matches before = 0
05/13/11 10:17:16: 227 226 0 0.650000
05/13/11 10:17:16: Starting in getUniqueMatches

-- And here breaks, inside getUniqueMatches --

そしてこれはコードです:

inline bool findInVector(std::vector<int> v, int value) {
    int size = v.size();
    for(int i=0; i<size; i++) {
        if(v[i] == value) {
            return true;
        }
    }

    return false;
}

void getUniqueMatches(IpVec &ipts1, IpVec &ipts2, IpPairVec &matches, float ratio) {
    try {
        wLog(f("%d %d %d %f", ipts1.size(), ipts2.size(), matches.size(), ratio));

        float dist, d1, d2;
        Ipoint *match;

        matches.clear();

        std::vector<int> matched;

        wLog("Starting in getUniqueMatches");

        // Breaks after here

        int size = ipts1.size();
        int size2 =  ipts2.size();

        for (int i = 0; i < size; i++) {
            d1 = d2 = FLT_MAX;

            int foundJ = -1;

            for (unsigned int j = 0; j < size2; j++) {
                dist = ipts1[i] - ipts2[j];

                if (dist < d1 && !findInVector(matched, j)) {
                    d2 = d1;
                    d1 = dist;
                    match = &ipts2[j];
                    foundJ = j;
                } else if (dist < d2) {
                    d2 = dist;
                }
            }

            if (d1 / d2 < ratio) {
                ipts1[i].dx = match->x - ipts1[i].x;
                ipts1[i].dy = match->y - ipts1[i].y;

                matches.push_back(std::make_pair(ipts1[i], *match));
                matched.push_back(foundJ);
            }
        }
    } catch(std::exception ex) {
        wLog(f("Exception in getUniqueMatches: ", ex.what()));
        return;
    }
}

ここで休憩するのはほんの数回です。何が起こっているのかわかりません、何か問題がありますか?この関数を実行するとき、アプリケーションは1つのスレッドのみを使用します。ポイントを抽出する場合、10スレッドを使用します。

Centos5(VPS)で使用します。2 Gb RAm 20%hd使用g ++(パフォーマンスモード)を使用してコンパイル、IDEはNetbeansを使用。OpenCV、libcurl。

4

2 に答える 2

1

私は2つのことを疑っています:

  • g++ コンパイラの最適化。使用-O2以下。-O3それ以降は、特に浮動小数点演算に関して奇妙な動作を生成することがあります。

  • 最適化を減らしても問題が解決しない場合は、変更することをお勧めします

    if (d1 / d2 < ratio)

    if (d1 < double(ratio)*d2)

    ゼロによる除算を回避し(起こりそうにないことだと思います)、精度の高い結果を得るためです。

于 2011-05-28T12:32:32.100 に答える
0

変化する

if (d1 / d2 < ratio) {

為に

if(d2 > 0 && ...) {

問題はゼロ除算だったと思いますが、例外をスローしていませんでした。:(

于 2011-05-14T15:45:00.017 に答える