6

対象物と参照物が混在する写真のサイズを計算したいです。

私がやりたいことは、このソフトウェアが達成することだと思います (このソフトウェアがどれほど正確かはわかりません) https://itunes.apple.com/us/app/photo-meter-picture-measuring/id579961082? mt=8

一般的にはフォトグラメトリと呼ばれ、活発な研究分野のようです。

画像からオブジェクトの高さを求めるにはどうすればよいでしょうか? https://physics.stackexchange.com/questions/151121/can-i-calculate-the-size-of-a-real-object-by-just-looking-at-the-picture-taken-b

しかし、私は見つけることができません

  • 参照オブジェクトを使用して写真内のオブジェクトを測定する基本的な方法は何ですか。
  • それを実装する方法または標準のオープンソース。

アップデート

  • 被写体までの距離とカメラからの参照が利用できません。
  • 基準とターゲットは (ほぼ) 同じ平面上にあります。
4

2 に答える 2

7

あなたの仮定により、参照とターゲットは(ほぼ)同じ平面上にあります。で説明されている方法「アルゴリズム 1: 平面測定」を適用できます。

アントニオ・クリミニシ "Single-View Metrology: Algorithms and Applications (Invited Paper)". 中:パターン認識。エド。リュック・ヴァン・グール著。巻。2449. コンピュータ サイエンスの講義ノート。スプリンガー ベルリン ハイデルベルグ、2002 年、224 ~ 239 ページ。

この方法を使用すると、同じ平面上にある 2 点間の距離を測定できます。

基本的

P=H*p (1)

ここpで、 は同次座標で表される画像内の点、Pは同次座標で表される 3D ワールド プレーン内の対応する点であり、ホモグラフィ行列H呼ばれる 3x3 行列であり、行列ベクトルの乗算です。*

    h11 h12 h13
H = h21 h22 h23
    h31 h32 h33

の測定単位pはピクセルなので、たとえばが行と列pの点である場合、として表されます。の測定単位は、メートルなどのワールド単位です。3D ワールド平面は平面であると想定できるため、同次ベクトルとして表されます。rc[r,c,1]PZ=0P[X,Y,1]

「アルゴリズム 1: 平面測定」を少し変更します。は次のとおりです。

  1. 与えられた平面の画像から、画像から世界へのホモグラフィ行列 H を推定します。H の 9 つの要素は無次元であると仮定します。

  2. 画像で、参照オブジェクトに属する2 つのポイントp1=[r1,c1,1]を選択します。p2=[r2,c2,1]

  3. (1) を介して各イメージ ポイントをワールド平面に逆投影し、2 つのワールド ポイントP1とを取得しP2ます。行列とベクトルの乗算を実行し、結果のベクトルを 3 番目のコンポーネントで除算して、均一なベクトルを取得します。たとえば、P1=[X1,Y1,1]ですP1=[(c1*h_12 + h_11*r1 + h_13)/(c1*h_32 + h_31*r1 + h_33),(c1*h_22 + h_21*r1 + h_23)/(c1*h_32 + h_31*r1 + h_33),1]Hの 9 つの要素が無次元であると仮定します。つまりX1Y1、 、X2の測定単位Y2はピクセルです。

  4. とのR間の距離を計算します。つまり、は引き続きピクセルで表されます。ここで、とは参照オブジェクト上にあるので、それらの間の距離がメートル単位でわかっていることを意味します。P1P2R=sqrt(pow(X1-X2,2)+pow(Y1-Y2,2)RP1P2M

  5. sスケール係数を として計算します。s=M/Rの寸法sはメートル/ピクセルです。

  6. Hbyの各要素を乗算し、取得した新しい行列をs呼び出します。Gの要素はGメートル/ピクセルで表されます。

  7. ここで、イメージで 2 つのポイントp3を選択p4し、ターゲット オブジェクトに属します。

  8. とを取得するために、p3p4を逆投影します。と。再度、各ベクトルを 3 番目の要素で除算します。 、、、およびはメートル単位で表されます。GP3P4P3=G*p3P4=G*p4P3=[X3,Y3,1]P4=[X4,Y4,1]X3Y3X4Y4

  9. Dの間の目的のターゲット距離を計算します。メートルで表されるようになりました。P3P4D=sqrt(pow(X3-X4,2)+pow(Y3-Y4,2)D

上記の論文の付録では、計算方法Hや OpenCV の使用方法について説明していますcv::findHomography。基本的に、現実世界の点と画像の点の間に少なくとも 4 つの対応が必要です。

推定方法に関する別の情報源Hは、

JOHNSON、Micah K.; ファリッド、ハニー。単一の画像からの平面上のメトリック測定。部門コンピュータ。科学、ダートマス大学、技術。代表者 TR2006-579 , 2006.

測定の精度を推定する必要がある場合は、詳細を参照してください。

A.クリミニシ。単一および複数の未校正画像からの正確な視覚計測。優秀論文シリーズ。Springer-Verlag London Ltd.、2001 年 9 月。ISBN: 1852334681。

OpenCV を使用した C++ の例:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"


void to_homogeneous(const std::vector< cv::Point2f >& non_homogeneous, std::vector< cv::Point3f >& homogeneous )
{
    homogeneous.resize(non_homogeneous.size());
    for ( size_t i = 0; i < non_homogeneous.size(); i++ ) {
        homogeneous[i].x = non_homogeneous[i].x;
        homogeneous[i].y = non_homogeneous[i].y;
        homogeneous[i].z = 1.0;
    }
}

void from_homogeneous(const std::vector< cv::Point3f >& homogeneous, std::vector< cv::Point2f >& non_homogeneous )
{
    non_homogeneous.resize(homogeneous.size());
    for ( size_t i = 0; i < non_homogeneous.size(); i++ ) {
        non_homogeneous[i].x = homogeneous[i].x / homogeneous[i].z;
        non_homogeneous[i].y = homogeneous[i].y / homogeneous[i].z;
    }
}

void draw_cross(cv::Mat &img, const cv::Point center, float arm_length, const cv::Scalar &color, int thickness = 5 )
{
    cv::Point N(center - cv::Point(0, arm_length));
    cv::Point S(center + cv::Point(0, arm_length));
    cv::Point E(center + cv::Point(arm_length, 0));
    cv::Point W(center - cv::Point(arm_length, 0));
    cv::line(img, N, S, color, thickness);
    cv::line(img, E, W, color, thickness);
}

double measure_distance(const cv::Point2f& p1, const cv::Point2f& p2, const cv::Matx33f& GG)
{
    std::vector< cv::Point2f > ticks(2);
    ticks[0] = p1;
    ticks[1] = p2;
    std::vector< cv::Point3f > ticks_h;
    to_homogeneous(ticks, ticks_h);

    std::vector< cv::Point3f > world_ticks_h(2);
    for ( size_t i = 0; i < ticks_h.size(); i++ ) {
        world_ticks_h[i] = GG * ticks_h[i];
    }
    std::vector< cv::Point2f > world_ticks_back;
    from_homogeneous(world_ticks_h, world_ticks_back);

    return cv::norm(world_ticks_back[0] - world_ticks_back[1]);
}

int main(int, char**)
{
    cv::Mat img = cv::imread("single-view-metrology.JPG");
    std::vector< cv::Point2f > world_tenth_of_mm;
    std::vector< cv::Point2f > img_px;

    // Here I manually picked the pixels coordinates of the corners of the A4 sheet.
    cv::Point2f TL(711, 64);
    cv::Point2f BL(317, 1429);
    cv::Point2f TR(1970, 175);
    cv::Point2f BR(1863, 1561);

    // This is the standard size of the A4 sheet:
    const int A4_w_mm = 210;
    const int A4_h_mm = 297;
    const int scale = 10;

    // Here I create the correspondences between the world point and the
    // image points.
    img_px.push_back(TL);
    world_tenth_of_mm.push_back(cv::Point2f(0.0, 0.0));

    img_px.push_back(TR);
    world_tenth_of_mm.push_back(cv::Point2f(A4_w_mm * scale, 0.0));

    img_px.push_back(BL);
    world_tenth_of_mm.push_back(cv::Point2f(0.0, A4_h_mm * scale));

    img_px.push_back(BR);
    world_tenth_of_mm.push_back(cv::Point2f(A4_w_mm * scale, A4_h_mm * scale));

    // Here I estimate the homography that brings the world to the image.
    cv::Mat H = cv::findHomography(world_tenth_of_mm, img_px);

    // To back-project the image points into the world I need the inverse of the homography.
    cv::Mat G = H.inv();

    // I can rectify the image.
    cv::Mat warped;
    cv::warpPerspective(img, warped, G, cv::Size(2600, 2200 * 297 / 210));

    {
        // Here I manually picked the pixels coordinates of ticks '0' and '1' in the slide rule,
        // in the world the distance between them is 10mm.
        cv::Point2f tick_0(2017, 1159);
        cv::Point2f tick_1(1949, 1143);
        // I measure the distance and I write it on the image.
        std::ostringstream oss;
        oss << measure_distance(tick_0, tick_1, G) / scale;
        cv::line(img, tick_0, tick_1, CV_RGB(0, 255, 0));
        cv::putText(img, oss.str(), (tick_0 + tick_1) / 2, cv::FONT_HERSHEY_PLAIN, 3, CV_RGB(0, 255, 0), 3);
    }

    {
        // Here I manually picked the pixels coordinates of ticks '11' and '12' in the slide rule,
        // in the world the distance between them is 10mm.
        cv::Point2f tick_11(1277, 988);
        cv::Point2f tick_12(1211, 973);
        // I measure the distance and I write it on the image.
        std::ostringstream oss;
        oss << measure_distance(tick_11, tick_12, G) / scale;
        cv::line(img, tick_11, tick_12, CV_RGB(0, 255, 0));
        cv::putText(img, oss.str(), (tick_11 + tick_12) / 2, cv::FONT_HERSHEY_PLAIN, 3, CV_RGB(0, 255, 0), 3);
    }

    // I draw the points used in the estimate of the homography.
    draw_cross(img, TL, 40, CV_RGB(255, 0, 0));
    draw_cross(img, TR, 40, CV_RGB(255, 0, 0));
    draw_cross(img, BL, 40, CV_RGB(255, 0, 0));
    draw_cross(img, BR, 40, CV_RGB(255, 0, 0));

    cv::namedWindow( "Input image", cv::WINDOW_NORMAL );
    cv::imshow( "Input image", img );
    cv::imwrite("img.png", img);

    cv::namedWindow( "Rectified image", cv::WINDOW_NORMAL );
    cv::imshow( "Rectified image", warped );
    cv::imwrite("warped.png", warped);

    cv::waitKey(0);

    return 0;
}

入力画像。この場合、参照オブジェクトは A4 シートで、ターゲット オブジェクトは計算尺です。 ここに画像の説明を入力

測定値を含む入力画像。赤い十字は、ホモグラフィを推定するために使用されます。 ここに画像の説明を入力

修正された画像: ここに画像の説明を入力

于 2016-04-03T16:32:30.703 に答える
2

最も基本的な方法は、参照オブジェクトのピクセル寸法を単純に決定し、メトリック寸法を使用して mm / ピクセル係数を導き出すことです。次に、測定するオブジェクトのピクセル寸法にその係数を掛けます。これは、両方のオブジェクトがセンサーに平行な同じ平面内にある場合にのみ機能します。

それ以外の場合は、距離情報が必要です。どれだけ正確でなければならないかに応じて、それらを測定するか、いくつかの仮定を立てることができます。

このような測定を実装する方法は、要件によって異なります。

于 2016-02-22T16:36:48.943 に答える