Skip to content

物体検出 ​

インスタンスの宣言 ​

物体検出(ObjectDetection) ブロックを作業領域に追加すると、Python コードには次のようなインスタンスの宣言が自動的に挿入されます:

python
object_detection = ObjectDetection(0)
# 複数のインスタンスがある場合
object_detection_1 = ObjectDetection(1)

パラメーター ​

名前区分説明範囲・種類デフォルト値
indexドロップダウンオプションインスタンス番号(0 から始まる)0 以上の整数0

カメラを設定 ​

物体検出に使うカメラを設定します。

device

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプションカメラ機器の名前システムのカメラのラベル-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.device('')

物体モデルを読み込む ​

学習済みの物体モデルを読み込みます。「物体検出」モジュールの機能を使うには、この操作が必ず必要です。

load_model

パラメーター ​

名前区分説明範囲・種類デフォルト値
waitチェックボックス読み込みの完了を待つかどうかTRUE / FALSETRUE

Python ​

python
object_detection = ObjectDetection(0)

object_detection.load_model(wait=True)

物体の最大数を設定 ​

検出できる物体の最大の数を設定します。物体の数の範囲は 0 ~ 10 です。

max_objects

パラメーター ​

名前区分説明範囲・種類デフォルト値
data入力値(ブロック)物体の最大数0 ~ 10 の整数-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.max_objects(5)

信頼度のしきい値を設定 ​

物体検出の最小の確率(信頼度)を設定します。確率(信頼度)がこれ以上の場合だけ画面に表示されます。確率(信頼度)の範囲は 0 ~ 1 です。

confidence_threshold

パラメーター ​

名前区分説明範囲・種類デフォルト値
data入力値(ブロック)信頼度のしきい値0 ~ 1 の実数-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.confidence_threshold(0.5)

物体を1回検出 ​

いま画面にある物体を見つけて、1 回だけ表示します。

detect_once

パラメーター ​

(なし)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.detect_once()

物体の連続検出を開始 / 停止 ​

いま画面にある物体を続けて追いかけながら、画面上に表示します。

detect_continuous

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプション動作開始(start), 停止(stop)-

Python ​

python
object_detection = ObjectDetection(0)

# unit = "start"
object_detection.detect_continuous()
# unit = "stop"
object_detection.stop()

結果を表示 ​

カメラの画面に物体検出の結果を表示するかどうかを決めます。

display

パラメーター ​

名前区分説明範囲・種類デフォルト値
onドロップダウンオプション表示 ON / OFF表示(on=True), 非表示(off=False)TRUE

Python ​

python
object_detection = ObjectDetection(0)

object_detection.display(True)
object_detection.display(False)

物体の位置の情報 ​

指定した物体の位置/大きさの値を返します。

object_data

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプション物体の名前物体クラス 80 種('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'cat', 'dog', 'apple', 'cup', 'laptop', 'cell_phone' など)-
posドロップダウンオプション座標x, y-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object('person', 'x')
object_detection.object('bicycle', 'y')

物体の矩形の情報 ​

指定した物体の領域の矩形の位置/大きさの値を返します。

object_square

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプション物体の名前物体クラス 80 種-
posドロップダウンオプション矩形の情報min_x, max_x, min_y, max_y, width, height, area-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object('person', 'width')
object_detection.object('car', 'area')

2つの物体の間の距離 ​

2 つの物体クラスの間の距離を返します。

object_distance

パラメーター ​

名前区分説明範囲・種類デフォルト値
unit1ドロップダウンオプション1 つ目の物体の名前物体クラス 80 種-
unit2ドロップダウンオプション2 つ目の物体の名前物体クラス 80 種-
typeドロップダウンオプション距離の種類距離(省略または None), 横の距離(horizontal), 縦の距離(vertical)None

Python ​

python
object_detection = ObjectDetection(0)

object_detection.get_distance('person', 'bicycle')  # 距離
object_detection.get_distance('person', 'car', 'horizontal')  # 横の距離

物体の信頼度 ​

選んだ物体である確率(信頼度)

object_confidence

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプション物体の名前物体クラス 80 種-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object_confidence('person')

物体モデルの読み込み状態 ​

物体モデルの読み込み状態を返します。
まだ読み込んでいなければ 0、読み込み中なら 1、読み込みが完了していれば 2 を返します。

model_state

パラメーター ​

(なし)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.model_state()

物体を検出した? ​

物体を見つけたかどうか

detected

パラメーター ​

(なし)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.detected()

特定の物体を検出した? ​

選んだ物体を見つけたかどうか

object_detected

パラメーター ​

名前区分説明範囲・種類デフォルト値
unitドロップダウンオプション物体の名前物体クラス 80 種-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object_detected('person')