摄像头#
简介#
VEX AIR 无人机包含两个视觉传感器,作为其机载摄像头——一个位于前部,一个位于底部。这些传感器可以在飞行过程中捕获图像和画面。在 VEXcode AIR 中,“camera”一词始终指代其中一个视觉传感器。例如,在类似 drone.camera.start_recording(FORWARD_CAMERA) 的命令中,camera 指摄像头,而 FORWARD_CAMERA 选择前视摄像头。
要从 VEX AIR 无人机控制器传输视频记录和图像,请将控制器连接到计算机。它将显示为大容量存储设备(类似于 USB 驱动器),允许您直接复制文件。结束项目后,请等待大约一分钟,让控制器完成从无人机下载所有图像或记录,然后再尝试复制它们。
以下是所有可用方法的列表:
动作
start_recording– 从摄像头录制画面。stop_recording– 停止从摄像头录制画面。capture_image– 从摄像头捕获图像。
修改方法
show_camera– 在 VEX AIR 无人机控制器上显示选定的摄像头。hide_camera– 隐藏遥控器上的摄像头画面。set_overlay_reticle– 显示或隐藏叠加准星。set_overlay_telemetry– 显示或隐藏遥测数据。
获取方法
is_recording– 返回摄像头是否正在录制。get_recording_time– 返回录制所花费的时间。
动作#
start_recording#
start_recording 使用指定的摄像头开始录制。
For information about viewing and retrieving recordings, go here.
用法:
drone.camera.start_recording(camera)
参数 |
描述 |
|---|---|
|
要用于录制的摄像头: |
# Press button 7 to end recording
def end_recording():
drone.camera.stop_recording(FORWARD_CAMERA)
drone.land()
controller.button7.pressed(end_recording)
# Record a video as you fly around
controller.screen.show_camera(FORWARD_CAMERA)
drone.take_off(climb_to=500)
drone.camera.start_recording(FORWARD_CAMERA)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
stop_recording#
stop_recording 使用指定的摄像头开始录制。
For information about viewing and retrieving recordings, go here.
用法:
drone.camera.stop_recording(camera)
参数 |
描述 |
|---|---|
|
要用于停止录制的摄像头: |
# Press button 7 to end recording
def end_recording():
drone.camera.stop_recording(FORWARD_CAMERA)
drone.land()
controller.button7.pressed(end_recording)
# Record a video as you fly around
controller.screen.show_camera(FORWARD_CAMERA)
drone.take_off(climb_to=500)
drone.camera.start_recording(FORWARD_CAMERA)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
capture_image#
capture_image 使用指定的摄像头捕获一张图像。
有关查看和检索捕获图像的信息,转至此处。
用法:
drone.camera.capture_image(camera)
参数 |
描述 |
|---|---|
|
要用于拍摄的摄像头: |
# Press button 7 to take pictures
def take_picture():
drone.camera.capture_image(FORWARD_CAMERA)
controller.button7.pressed(take_picture)
# Take pictures while you control the drone
controller.screen.show_camera(FORWARD_CAMERA)
drone.take_off(climb_to=500)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
修改方法#
show_camera#
show_camera 将当前屏幕模式设置为指定的摄像头画面。
用法:
controller.screen.show_camera(camera)
参数 |
描述 |
|---|---|
|
要显示的摄像头画面: |
# Switch camera feeds after 3 seconds
controller.screen.show_camera(DOWNWARD_CAMERA)
wait(3, SECONDS)
controller.screen.show_camera(FORWARD_CAMERA)
hide_camera#
hide_camera 隐藏指定摄像头的画面。
用法:
controller.screen.hide_camera()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Hide camera feed after 3 seconds
controller.screen.show_camera(FORWARD_CAMERA)
wait(3, SECONDS)
controller.screen.hide_camera()
set_overlay_reticle#
set_overlay_reticle 启用或禁用叠加准星。准星是一种视觉标记,如十字准线,会出现在摄像头画面中,以帮助瞄准或对齐物体。
默认情况下,在项目启动时,准星叠加层设置为 True,且仅在下视摄像头上生效。
用法:
controller.screen.set_overlay_reticle(state)
参数 |
描述 |
|---|---|
|
叠加准星的状态: |
# Hide the reticle when not aligning to a landing area
controller.screen.show_camera(DOWNWARD_CAMERA)
drone.take_off(climb_to=500)
controller.screen.set_overlay_reticle(False)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
set_overlay_telemetry#
set_overlay_telemetry 启用或禁用无人机遥测数据在控制器屏幕上的可见性。遥测数据是无人机在飞行或运行项目时的实时数据。
默认情况下,在项目启动时,遥测数据叠加层设置为 True。
用法:
controller.screen.set_overlay_telemetry(state)
参数 |
描述 |
|---|---|
|
遥测数据的状态: |
# Clear the camera video for better visibility
controller.screen.show_camera(FORWARD_CAMERA)
drone.take_off(climb_to=500)
controller.screen.set_overlay_telemetry(False)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
获取方法#
is_recording#
is_recording 返回一个布尔值,指示指定的摄像头当前是否正在录制。
True– 指定的摄像头正在录制。False– 指定的摄像头未在录制。
用法:
drone.camera.is_recording(camera)
参数 |
描述 |
|---|---|
|
要检查录制状态的摄像头: |
# Use button 7 to start and stop recording
def toggle_recording():
if drone.camera.is_recording(FORWARD_CAMERA):
drone.camera.stop_recording(FORWARD_CAMERA)
else:
drone.camera.start_recording(FORWARD_CAMERA)
controller.button7.pressed(toggle_recording)
# Make video recordings while you control the drone
controller.screen.show_camera(FORWARD_CAMERA)
drone.take_off(climb_to=500)
while True:
# Move with controller
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
get_recording_time#
get_recording_time 返回指定摄像头已录制的时间,以秒为单位,为小数 (float)。
用法:
drone.camera.get_recording_time(camera)
参数 |
描述 |
|---|---|
|
要检查录制时长的摄像头: |
# Record a video for 10 seconds
controller.screen.show_camera(FORWARD_CAMERA)
drone.camera.start_recording(FORWARD_CAMERA)
drone.take_off(climb_to=500)
while not (drone.camera.get_recording_time(FORWARD_CAMERA)) >= 10:
wait(5, MSEC)
drone.camera.stop_recording(FORWARD_CAMERA)