イベントとアラームのストリーミング
このページは自動翻訳されたもので、まだレビューされていません。内容に相違がある場合は、英語の原文が優先されます。 英語の原文を読む
blickfeld_qb2.percept_processing.services の Event サービスは、ゾーンのイベントを照会し、ストリーミングします。
セキュリティゾーンの侵入イベントには、ゾーン識別子、侵入の開始と終了のタイムスタンプ、および侵入しているオブジェクトのプロパティが含まれます。
車線ゾーンは、各車両をイベントとして報告します。車両のストリーミングを参照してください。
これらの例は Pythonライブラリを使用し、アプリケーションキーでサインインします。qb2-xxxxxxxxx をお使いのセンサーのホスト名またはIPアドレスに、application-key-for-qb2-xxxxxxxxx をキーのシークレットに置き換えてください。
すべてのセキュリティゾーンのアラームをストリーミングする
Pythonクライアントを使用して、すべてのセキュリティゾーンのアラームをストリーミングします。blickfeld_qb2ライブラリをインストールし、下のスクリプトをstream_alarms.pyとして保存し、センサーのホスト名とWebGUIで作成したアプリケーションキーのシークレットを指定して実行してください。
pip install -U blickfeld_qb2
python3 stream_alarms.py qb2-<serial number> <application key>
stream_alarms.py
import sys
import blickfeld_qb2
from blickfeld_qb2.betterproto import which_one_of
def describe(kind, event):
if kind == "security_zone_intrusion_started":
return f"Alarm in {event.state.generator_name}"
if kind == "security_zone_intrusion_ended":
return f"Alarm ended after {event.duration:.1f} s"
return None
def stream_alarms(host, key=None):
token = blickfeld_qb2.TokenFactory(application_key_secret=key) if key else None
with blickfeld_qb2.Channel(host, token=token) as channel:
events = blickfeld_qb2.percept_processing.services.Event(channel)
for response in events.stream():
line = describe(*which_one_of(response.event, "type"))
if line:
print(line)
if __name__ == "__main__":
stream_alarms(*sys.argv[1:3])
人がゾーンを通過したときの出力(例):
Alarm in Pre-Alarm
Alarm ended after 13.0 s
以下の例では、Event サービスを段階的に説明します。
イベントのストリーミング
この例では、各イベントを出力します。
import blickfeld_qb2
def stream_security_events() -> None:
# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")
# Open a secure connection to the sensor
with blickfeld_qb2.Channel("qb2-xxxxxxxxx", token=token_factory) as channel:
# Use Event service
service = blickfeld_qb2.percept_processing.services.Event(channel)
# Iterate over events stream and print them
for response in service.stream():
print("Event:", response.event)
stream_security_events()
人がゾーンに入ったときの最初の2つのイベントの出力です(1行に1フィールド、長いリストは … で省略):
Event: Event(
timestamp=1794557816515962216,
security_intrusion_started=EventSecurityIntrusionStarted()
)
Event: Event(
timestamp=1794557816515962216,
security_zone_intrusion_started=EventSecurityZoneIntrusionStarted(
zone_uuid='6dde4732-d2d2-4981-bee6-6864d7669a75',
state=State(
generator_name='Pre-Alarm',
object_based_security=StateObjectBasedSecurity(
alarm=True,
objects={
'59': DetectedObject(
pose=Pose(
position=Vector3(x=-1.2360198497772217, y=7.185153961181641, z=1.0974624156951904)
),
shape=Shape(
pose=Pose(
position=Vector3(x=-1.2197115421295166, y=7.104532241821289, z=1.0974624156951904)
),
box=ShapeBox(
dimensions=Vector3(x=0.32164937257766724, y=0.3377991318702698, z=1.2932387590408325)
)
),
properties=DetectedObjectProperties(size=2, num_points=220, average_intensity=3884, bounding_box_2_d_surface=0.43685492873191833, track_length=5.475871562957764, median_reflectivity=4146),
point_cloud=Frame(
binary=FrameBinary(
length=220,
cartesian=array(
[
[-1.1444434 , 7.0532727 , 1.2344986 ],
[-1.1692843 , 7.128196 , 1.5870416 ],
[-1.3347117 , 7.079878 , 1.000879 ],
...
],
dtype=float32
),
photon_count=array(
[5381, 5142, 4758, ...],
dtype=uint16
),
direction_id=array(
[393, 50, 2640, ...],
dtype=uint32
)
)
),
timestamp=1794557808515962216,
path=[
Pose(
position=Vector3(x=-4.121706008911133, y=1.7800681591033936, z=0.4839831292629242)
),
Pose(
position=Vector3(x=-3.488027572631836, y=3.0714902877807617, z=1.079064130783081)
),
Pose(
position=Vector3(x=-2.86340594291687, y=4.3938727378845215, z=1.0780154466629028)
),
...
],
visible_to_sensors=['ABC123XYZ'],
intruding=Flag(state=True, since_timestamp=1794557808515962216),
intruder=Flag(state=True, since_timestamp=1794557808515962216),
lifetime=8000000000,
velocity=Vector3(x=0.3014988899230957, y=0.27406570315361023),
in_zone_uuids=['6dde4732-d2d2-4981-bee6-6864d7669a75']
)
},
intrusion=Flag(state=True, since_timestamp=1794557816515962216),
intrusion_confidence=1.0,
tampering=Flag(since_timestamp=1794557807015962216, since_duration=9500000000)
),
coverage=1.0,
coverage_observed_area=24.43000030517578
),
disqualification=Disqualification()
)
)
ゾーン侵入の詳細の処理
この例では、侵入が開始したときに、ゾーンのUUIDと各オブジェクトの位置を出力します。
import blickfeld_qb2
def stream_zone_intrusion_details() -> None:
# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
application_key_secret="application-key-for-qb2-xxxxxxxxx"
)
# Open a secure connection to the sensor
with blickfeld_qb2.Channel("qb2-xxxxxxxxx", token=token_factory) as channel:
# Use Event service
service = blickfeld_qb2.percept_processing.services.Event(channel)
# Iterate over events stream
for response in service.stream():
event = response.event
# Condition for checking start of the intrusion of any zone
if event.security_zone_intrusion_started:
zone_event = event.security_zone_intrusion_started
print(f"Zone: {zone_event.zone_uuid}")
print("Objects involved:")
# Iterate over objects in intrusion zone and print their position
for obj_id, obj in zone_event.state.object_based_security.objects.items():
pos = obj.pose.position
print(f" - ID {obj_id}: (x={pos.x:.2f}, y={pos.y:.2f}, z={pos.z:.2f})")
stream_zone_intrusion_details()
出力:
Zone: 6dde4732-d2d2-4981-bee6-6864d7669a75
Objects involved:
- ID 60: (x=-1.24, y=7.19, z=1.10)
イベントのファイルへの保存
この例では、Ctrl+Cを押すまで、各イベントを受信するとすぐにJSONの1行としてファイル events.log に書き込みます。
import blickfeld_qb2
def log_events_to_file(filepath="events.log") -> None:
# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")
# Open a secure connection to the sensor
with blickfeld_qb2.Channel("qb2-xxxxxxxxx", token=token_factory) as channel:
service = blickfeld_qb2.percept_processing.services.Event(channel)
# Line buffered: each event is in the file as soon as it is written
with open(filepath, "w", buffering=1) as f:
for response in service.stream():
# Write each event as one line of JSON
f.write(f"{response.event.to_json()}\n")
log_events_to_file()