描画
ビジョンシステムでは、通常ユーザーに何らかのフィードバックを提供する必要があります。画像上に直接表示するのは非常に直感的な方法です。10分クイックスタートのプログラムで色ブロックが見つかったときにこの領域を矩形の枠でマークしたのと同じように、これは非常に直感的です。

注意:
色にはグレースケール値(0-255)、または色値のタプル(r, g, b)を指定できます。デフォルトは白です。
colorキーワードは必ず**color=**という形で明示的に指定する必要があります。例えば:
image.draw_line((10,10,20,30), color=(255,0,0))
image.draw_rectangle(rect_tuple, color=(255,0,0))
直線を描く
- image.draw_line(line_tuple, color=White) 画像内に直線を描きます。
- line_tupleの形式は(x0, y0, x1, y1)で、(x0, y0)から(x1, y1)への直線を表します。
- 色にはグレースケール値(0-255)、または色値のタプル(r, g, b)を指定できます。デフォルトは白です
矩形を描く
- image.draw_rectangle(rect_tuple, color=White) 画像内に矩形の枠を描きます。
- rect_tupleの形式は(x, y, w, h)です。
円を描く
- image.draw_circle((x, y, radius), color=White) 画像内に円を描きます。
- x, yは円の中心の座標です
- radiusは円の半径です
十字を描く
- image.draw_cross((x, y), size=5, color=White) 画像内に十字を描きます
- x, yは座標です
- sizeは両辺の長さです
テキストを書き込む
- image.draw_string((x, y), text, color=White) 画像内に8x10ピクセルのテキストを書き込みます
- x, yは座標です。\n、\r、\r\nを使うと、カーソルが次の行に移動します。
- textは書き込む文字列です。
サンプル
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import csi, image, time
csi0 = csi.CSI()
csi0.reset() # カメラを初期化
csi0.pixformat(csi.RGB565) # フォーマットをRGB565に設定
csi0.framesize(csi.QQVGA)
csi0.snapshot(frames=10) # 10フレームスキップして、新しい設定を反映させる
while(True):
img = csi0.snapshot() # Take a picture and return the image.
img.draw_line((20, 30, 40, 50))
img.draw_line((80, 50, 100, 100), color=(255,0,0))
img.draw_rectangle((20, 30, 41, 51), color=(255,0,0))
img.draw_circle((50, 50, 30))
img.draw_cross((90, 60),size=10)
img.draw_string((10, 10), "hello world!")
