画像の特徴点

前準備

Python 3.12 のインストール

以下のいずれかの方法で Python 3.12 をインストールする。

方法1:winget によるインストール

Python がインストール済みの場合、この手順は不要である。管理者権限コマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。

winget install -e --id Python.Python.3.12 --scope machine --silent --accept-source-agreements --accept-package-agreements --override "/quiet InstallAllUsers=1 PrependPath=1 AssociateFiles=1 InstallLauncherAllUsers=1"

--scope machine を指定することで、システム全体(全ユーザー向け)にインストールされる。このオプションの実行には管理者権限が必要である。インストール完了後、コマンドプロンプトを再起動すると PATH が自動的に設定される。

方法2:インストーラーによるインストール

  1. Python 公式サイト(https://www.python.org/downloads/)にアクセスし、「Download Python 3.x.x」ボタンから Windows 用インストーラーをダウンロードする。
  2. ダウンロードしたインストーラーを実行する。
  3. 初期画面の下部に表示される「Add python.exe to PATH」に必ずチェックを入れてから「Customize installation」を選択する。このチェックを入れ忘れると、コマンドプロンプトから python コマンドを実行できない。
  4. 「Install Python 3.xx for all users」にチェックを入れ、「Install」をクリックする。

インストールの確認

コマンドプロンプトで以下を実行する。

python --version

バージョン番号(例:Python 3.12.x)が表示されればインストール成功である。「'python' は、内部コマンドまたは外部コマンドとして認識されていません。」と表示される場合は、インストールが正常に完了していない。

ImageMagick のインストール

curl のインストール

VLFeat のインストール

ここで説明のためにサンプルとして使用する画像

curl コマンドを用いてダウンロードできる.あるいは Web ブラウザでもダウンロードできる.

curl -L https://github.com/opencv/opencv/blob/master/samples/data/fruits.jpg?raw=true -o fruits.jpg

VLFeat のコマンド(sift コマンド, aib コマンド, mser コマンドなど)

SIFT 実行と結果表示(VLFeat,Python を使用)

  1. SIFT の実行

    VLFeat の sift コマンド,ImageMagick の convert コマンドを使用. 次を実行することにより,ファイル fruits.sift ができる.

    curl -L https://github.com/opencv/opencv/blob/master/samples/data/fruits.jpg?raw=true -o fruits.jpg
    convert fruits.jpg fruits.pgm
    sift fruits.pgm
    
  2. 結果の表示
    Python プログラムの実行

    【サイト内の関連ページ】 Python のまとめ: 別ページ »

    Python プログラム

    import os
    import cv2
    import pandas as pd
    import numpy as np
    bgr = cv2.imread("fruits.jpg")
    a = pd.read_table("fruits.sift", sep=' ', header=None)
    for i, row in a.iterrows():
    #    print(i, row[0], row[1])
        c = cv2.circle(bgr, (int(row[0]), int(row[1])), 3, (0, 0, 255), -1)
    
    cv2.imshow("", bgr)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

SIFT の結果表示(Octave を使用)

今度は fruits.jpg と fruits.sift を Octave を用いて表示.

S = dlmread("fruits.sift", " ", 1, 0);
[rgb, map, alpha] = imread("fruits.jpg");
mono = rgb2gray( rgb );
colormap( gray(256) );
hold
imshow(mono);
plot(S(:,1), S(:,2), '@');

MSER 実行と結果表示(VLFeat,Python を使用)

  1. MSER の実行

    VLFeat の sift コマンド,ImageMagick の convert コマンドを使用. 次を実行することにより,ファイル fruits.frame ができる.

    curl -L https://github.com/opencv/opencv/blob/master/samples/data/fruits.jpg?raw=true -o fruits.jpg
    convert fruits.jpg fruits.pgm
    mser fruits.pgm
    
  2. 結果の表示
    Python プログラムの実行

    【サイト内の関連ページ】 Python のまとめ: 別ページ »

    Python プログラム

    import os
    import cv2
    import pandas as pd
    import numpy as np
    bgr = cv2.imread("fruits.jpg")
    a = pd.read_table("fruits.frame", sep=' ', header=None)
    for i, row in a.iterrows():
    #    print(i, row[0], row[1])
        c = cv2.circle(bgr, (int(row[0]), int(row[1])), 3, (0, 0, 255), -1)
    
    cv2.imshow("", bgr)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

MSER の結果表示(Octave を使用)

今度は fruits.jpg と fruits.frame を Octave を用いて表示.

S = dlmread( "fruits.frame", " ", 1, 0 );
[rgb, map, alpha] = imread("fruits.jpg");
mono = rgb2gray( rgb );
colormap( gray(256) );
hold
imshow(mono);
plot(S(:,1), S(:,2), '@');