金子邦彦研究室人工知能Windows で動く人工知能関係 Pythonアプリケーション,オープンソースソフトウエア)ArtyZiff35/3D_Reconstruction_From_Stereo_Images のインストールとステレオ画像からの3次元モデルの生成(ステレオ画像,深度マップ,色付き3次元点群)(Python を使用)(Windows 上)

ArtyZiff35/3D_Reconstruction_From_Stereo_Images のインストールとステレオ画像からの3次元モデルの生成(ステレオ画像,深度マップ,色付き3次元点群)(Python を使用)(Windows 上)

ArtyZiff35/3D_Reconstruction_From_Stereo_Images をインストールする. これは,ステレオ画像についての画像補正,ステレオマッチング,視差マップ (disparity map),深度マップ (depth map),カラーの3次元点群の生成を行う.

関連する外部ページ

GitHub のページ: https://github.com/ArtyZiff35/3D_Reconstruction_From_Stereo_Images

1. 前準備

Git のインストール(Windows 上)

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Python の公式ページ: https://www.python.org/

2. ArtyZiff35/3D_Reconstruction_From_Stereo_Images のインストール

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. pip更新と,ArtyZiff35/3D_Reconstruction_From_Stereo_Images のインストール

    ※ 「 python -m pip install ...」は,Python パッケージをインストールするためのコマンド.

    python -m pip install -U --ignore-installed pip
    pip install -U matplotlib seaborn plyfile open3d
    cd %HOMEPATH%
    rmdir /s /q 3D_Reconstruction_From_Stereo_Images
    git clone --recursive https://github.com/ArtyZiff35/3D_Reconstruction_From_Stereo_Images
    cd 3D_Reconstruction_From_Stereo_Images
    
  3. ソースコード src\RealDepth.py の書き換え(2か所)

    cd %HOMEPATH%
    cd 3D_Reconstruction_From_Stereo_Images
    notepad src\RealDepth.py
    

    [image]

    [image]
  4. ソースコード src\master.py の書き換え(1か所)

    [image]
  5. src\master.py を実行することにより動作確認

    実行の前に,ディレクトリの作成,所定のディレクトリに所定の画像を置くなどの作業を行っている.

    cd %HOMEPATH%
    cd 3D_Reconstruction_From_Stereo_Images
    mkdir remap
    mkdir remap\remapped
    mkdir remap\remapped\left
    mkdir remap\remapped\right
    copy sampleRectified\left\_bike_l.png remap\remapped\left
    copy sampleRectified\right\_bike_r.png remap\remapped\right
    mkdir diparity
    mkdir disparity\heatmap
    mkdir ply
    src\master.py
    
  6. 実行の結果,エラーメッセージが出ないことを確認

    [image]
  7. 3次元モデルが表示される.

    マウスで回転などができる.

    [image]

    [image]
  8. 次のコマンドで,使用したステレオ画像を表示

    remap\remapped\left\_bike_l.png 
    remap\remapped\right\_bike_r.png
    

    [image]

    [image]
  9. 次のコマンドで,視差マップ (disparity map) を表示

    disparity\heatmap\bike.png
    

    [image]

別の画像で試してみる.

以下書きかけ

  1. src\left, src\right 下に png 形式の画像を準備

    cd %HOMEPATH%
    cd 3D_Reconstruction_From_Stereo_Images
    cd src
    mkdir remap
    mkdir remap\remapped
    mkdir remap\remapped\left
    mkdir remap\remapped\right
    cd remap\remapped
    cd left
    curl -O https://raw.githubusercontent.com/opencv/opencv/master/samples/data/aloeL.jpg
    cd ..
    cd right
    curl -O https://raw.githubusercontent.com/opencv/opencv/master/samples/data/aloeR.jpg
    
  2. png に変換
  3. disparity map

    cd %HOMEPATH%
    cd 3D_Reconstruction_From_Stereo_Images
    cd src
    mkdir disparity
    mkdir disparity\heatmap
    mkdir ply
    
    次の Python プログラムを実行

    import FastDP as fdm
    path_l = 'remap/remapped/left/aloeL.jpg'
    path_r = 'remap/remapped/right/aloeR.jpg'
    name = 'aloe'
    disparity = fdm.generate_disparity_map(left_path=path_l, right_path=path_r, name=name, downsample_n=0)
    exit()
    
  4. disparity\heatmap\aloe.png
    
  5. depth map

    import FastDP as fdm
    import RealDepth as rd
    
    path_l = 'remap/remapped/left/aloeL.jpg'
    path_r = 'remap/remapped/right/aloeR.jpg'
    name = 'aloe'
    disparity = fdm.generate_disparity_map(left_path=path_l, right_path=path_r, name=name, downsample_n=0)
    
    model3D_matrix = rd.generate_depth_map(disparity, 'disparity/heatmap/aloe.png')
    rd.convert_to_ply(disparity=disparity, model_3d=model3D_matrix, name=name, image_path='disparity/heatmap/aloe.png', cmp_range=70)
    rd.visualize_model('ply/' + str(name) + '.ply')