Lua API:framediff#

説明#

framediff データ構造は、CMUcam3 で撮影した2つの異なるフレーム間の差分に関する情報を保持します。内部的には、これらのフレームは「current」と「previous」のテンプレートに保持されます。これら2つのテンプレート間の比較は、framediff_scanline_startframediff_scanlineframediff_scanline_finish を使用して行われます。

#

この例は、CMUcam3 とフレーム差分を使った実装を示しています。ループして、ある写真が前の写真と異なるまで写真を撮り続け、異なった時点で save_picture を呼び出してその写真をディスクに保存します。

-- get a new framediff, and initialize it
fdiff = framediff_new(16, 16);
fdiff:set_total_x(pixbuf_get_width());
fdiff:set_total_y(pixbuf_get_height());
fdiff:set_threshold(10);
img = image_new(pixbuf_get_width(), 1); -- need an image object for the framediff'ing

take_picture();
fdiff:set_load_frame(true);

-- take the first picture
if (framediff_scanline_start(fdiff) > 0) then
    while pixbuf_read_rows(img, 1) > 0 do
        framediff_scanline(img, fdiff);
    end
    framediff_scanline_finish(fdiff);
end

fdiff:set_load_frame(false);

-- now keep taking pictures until a picture is different than its predecessor
repeat
    take_picture();
    if (framediff_scanline_start(fdiff) > 0) then
        while pixbuf_read_rows(img, 1) > 0 do
            framediff_scanline(img, fdiff);
        end
        framediff_scanline_finish(fdiff);
    else
        print("Error!");
    end

    fdiff:swap_templates(); -- put current template in previous template spot
until fdiff:get_num_pixels() > fdiff:get_threshold()

-- we got an image that was different! Save it to disk, and send it to the Camscripter
save_picture("Diff.ppm"):
print_picture();

コンストラクタ#

Lua API:関数framediff_new を参照

メソッド#

  • dispose

  • get_coi

  • get_load_frame

  • get_num_pixels

  • get_template_height

  • get_template_width

  • get_threshold

  • get_total_x

  • get_total_y

  • set_coi

  • set_load_frame

  • set_total_x

  • set_total_y

  • set_threshold

  • swap_templates

dispose#

fdiff:dispose()

パラメータ:

なし

戻り値:

なし

Luaガベージコレクタがそのメモリを破棄するのを待つ代わりに、このframediffデータ構造に関連付けられたメモリを明示的に破棄する方法を提供します。警告: framediffに対してdisposeを呼び出した後にそのframediffを使用すると、エラーが発生する可能性が高いため、そうしないことを強くお勧めします。

get_coi#

fdiff:get_coi()

パラメータ:

なし

戻り値:

この framediff 構造体の対象チャンネル。

この構造の対象チャンネルを取得します。取り得る戻り値については、Lua API:定数 の対象チャンネル定数を参照してください。

get_load_frame#

fdiff:get_load_frame()

パラメータ:

なし

戻り値:

新しいフレームを読み込むかどうか

このframediffオブジェクトのload_frameの値を取得します。load_frameは、現在と前のテンプレートの差分を行う前に、CMUcam3から新しいフレームを読み込む必要があるかどうかを決定します。

get_num_pixels#

fdiff:get_num_pixels()

パラメータ:

なし

戻り値:

現在のテンプレートと前のテンプレートの間の差分のピクセル数

framediff_scanline_startframediff_scanlineframediff_scanline_finish を使用した後、このメソッドを呼び出して、現在のテンプレートと前のテンプレートの間で見つかった差分ピクセルの数を取得します。

get_template_height#

fdiff:get_template_height()

パラメータ:

なし

戻り値:

テンプレートの高さ

差分されているテンプレートの高さを取得します。

get_template_width#

fdiff:get_template_width()

パラメータ:

なし

戻り値:

テンプレートの幅

差分されているテンプレートの幅を取得します。

get_total_x#

fdiff:get_total_x()

パラメータ:

なし

戻り値:

解析される総幅

合計幅を取得します。通常は pixbuf_get_width と同等です

get_total_y#

fdiff:get_total_y()

パラメータ:

なし

戻り値:

解析される総高さ

合計幅を取得します。通常は pixbuf_get_height と同等です

set_coi#

fdiff:set_coi(integer channel_of_interest)

パラメータ:

channel_of_interest フレーム差分の新しい対象チャンネル

戻り値:

なし

フレーム差分の対象チャンネルを設定します。パラメータ channel_of_interest は、Lua API:定数の対象チャンネル定数のいずれかでなければなりません。

set_load_frame#

fdiff:set_load_frame(boolean newValue)

パラメータ:

newValue 新しい値

戻り値:

なし

次のフレーム差分のラウンドで新しいフレームを読み込む必要があるかどうかを制御します。これがtrueの場合、新しい写真が撮影され、フレーム差分用の現在のテンプレートとして保存されます。

set_total_x#

fdiff:set_total_x(integer total_x)

パラメータ:

total_x total_x の新しい値

戻り値:

なし

framediff パケットの total_x を設定します。

set_total_y#

fdiff:set_total_y(integer total_y)

パラメータ:

total_y total_y の新しい値

戻り値:

なし

framediff パケットの total_y を設定します。

set_threshold#

fdiff:set_threshold(integer threshold)

パラメータ:

threshold 新しいしきい値

戻り値:

なし

あるフレームが別のフレームと「異なる」とみなされるかどうかを決定する、ピクセル差分数によるしきい値を設定します。

swap_templates#

fdiff:swap_templates

パラメータ:

なし

戻り値:

なし

この framediff 構造体の現在のテンプレートと前のテンプレートを入れ替えます。この関数は current_template を previous_template に、その逆も行います。