Lua API:framediff#
說明#
framediff 資料結構保存了關於使用 CMUcam3 所拍攝的兩個不同畫格之間差異的資訊。在內部,這些畫格保存在「current」與「previous」範本中。這兩個範本之間的比較是使用 framediff_scanline_start、framediff_scanline 及 framediff_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
方法#
disposeget_coiget_load_frameget_num_pixelsget_template_heightget_template_widthget_thresholdget_total_xget_total_yset_coiset_load_frameset_total_xset_total_yset_thresholdswap_templates
dispose#
fdiff:dispose()
- 參數:
無
- 回傳值:
無
提供一種明確釋放與此 framediff 資料結構相關聯之記憶體的方法,而不必等待 Lua 垃圾回收器釋放該記憶體。警告: 在對 framediff 呼叫 dispose 之後再使用它,很可能會導致錯誤,強烈建議您不要這麼做。
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_start、framediff_scanline 與 framediff_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_xtotal_x 的新值- 回傳值:
無
為 framediff 封包設定 total_x。
set_total_y#
fdiff:set_total_y(integer total_y)
- 參數:
total_ytotal_y 的新值- 回傳值:
無
為 framediff 封包設定 total_y。
set_threshold#
fdiff:set_threshold(integer threshold)
- 參數:
threshold新的閾值- 回傳值:
無
設定閾值(以像素差異的數量計),用以決定一個畫格是否被視為與另一個畫格「不同」。
swap_templates#
fdiff:swap_templates
- 參數:
無
- 回傳值:
無
交換此 framediff 結構中的目前範本與先前範本。此函式會將 current_template 放入 previous_template,反之亦然。