Máy ảnh#

Giới thiệu#

Máy bay không người lái VEX AIR bao gồm hai cảm biến hình ảnh đóng vai trò là camera tích hợp – một ở phía trước và một ở phía dưới. Chúng có thể chụp cả ảnh và quay video trong khi bay. Trong VEXcode AIR, từ “camera” luôn đề cập đến một trong hai cảm biến hình ảnh này. Ví dụ, trong một lệnh như drone.camera.start_recording(FORWARD_CAMERA), camera đề cập đến các cảm biến hình ảnh, và FORWARD_CAMERA chọn cảm biến phía trước.

Để chuyển các bản ghi video và hình ảnh từ bộ điều khiển máy bay không người lái VEX AIR, hãy kết nối bộ điều khiển với máy tính của bạn. Nó sẽ được nhận dạng như một thiết bị lưu trữ (tương tự như ổ USB), cho phép bạn sao chép tệp trực tiếp. Sau khi kết thúc một dự án, hãy đợi khoảng một phút để bộ điều khiển hoàn tất việc tải xuống bất kỳ hình ảnh hoặc bản ghi nào từ máy bay không người lái trước khi tiến hành sao chép chúng.

Dưới đây là danh sách tất cả các phương pháp hiện có:

Hành động

Các sinh vật đột biến

  • show_camera – Hiển thị Cảm biến Thị giác đã chọn trên Bộ điều khiển Máy bay không người lái VEX AIR.

  • hide_camera – Ẩn nguồn cấp dữ liệu Cảm biến Thị giác trên bộ điều khiển.

  • set_overlay_reticle – Hiển thị hoặc ẩn tâm ngắm phủ.

  • set_overlay_telemetry – Hiển thị hoặc ẩn dữ liệu đo từ xa.

Người đạt giải

Hành động#

start_recording#

start_recording bắt đầu ghi hình với Cảm biến Thị giác được chỉ định.

Để biết thông tin về cách xem và truy xuất bản ghi, hãy vào đây.

Cách sử dụng:

drone.camera.start_recording(camera)

Thông số

Sự miêu tả

camera

Cảm biến hình ảnh dùng để ghi hình: DOWNWARD_CAMERA hoặc FORWARD_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 dừng việc ghi hình của Cảm biến Thị giác được chỉ định.

Để biết thông tin về cách xem và truy xuất bản ghi, hãy vào đây.

Cách sử dụng:

drone.camera.stop_recording(camera)

Thông số

Sự miêu tả

camera

Cảm biến thị giác để dừng ghi hình với: DOWNWARD_CAMERA hoặc FORWARD_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 chụp ảnh bằng Cảm biến Thị giác được chỉ định.

Để biết thông tin về cách xem và truy xuất hình ảnh đã chụp, hãy vào đây.

Cách sử dụng:

drone.camera.capture_image(camera)

Thông số

Sự miêu tả

camera

Cảm biến thị giác để chụp ảnh với: DOWNWARD_CAMERA hoặc FORWARD_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)

Biến đổi#

show_camera#

show_camera thiết lập chế độ màn hình hiện tại thành nguồn cấp dữ liệu Cảm biến Thị giác được chỉ định.

Cách sử dụng:

controller.screen.show_camera(camera)

Thông số

Sự miêu tả

camera

Dữ liệu từ Cảm biến Thị giác được hiển thị: DOWNWARD_CAMERA hoặc FORWARD_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 ẩn nguồn cấp dữ liệu của Cảm biến Thị giác được chỉ định.

Cách sử dụng:

controller.screen.hide_camera()

Thông số

Sự miêu tả

Phương pháp này không có tham số.

# 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 bật hoặc tắt tâm ngắm phủ. Tâm ngắm là một dấu hiệu trực quan, giống như hình chữ thập, xuất hiện trong khung hình camera để hỗ trợ ngắm bắn hoặc căn chỉnh đối tượng.

Theo mặc định, lớp phủ tâm ngắm được đặt thành True khi bắt đầu dự án, chỉ trên Cảm biến Thị giác hướng xuống.

Usage:
controller.screen.set_overlay_reticle(state)

Thông số

Sự miêu tả

state

Trạng thái của tâm ngắm phủ: True bật tâm ngắm phủ. False tắt tâm ngắm phủ.

# 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 cho phép hoặc vô hiệu hóa việc hiển thị dữ liệu đo từ xa của máy bay không người lái trên màn hình điều khiển. Dữ liệu đo từ xa là dữ liệu trực tiếp từ máy bay không người lái trong khi nó đang bay hoặc đang thực hiện một dự án.

Theo mặc định, lớp phủ dữ liệu đo từ xa được đặt thành True khi bắt đầu dự án.

Usage:
controller.screen.set_overlay_telemetry(state)

Thông số

Sự miêu tả

state

Trạng thái dữ liệu đo từ xa: True cho phép hiển thị dữ liệu đo từ xa trên màn hình. False vô hiệu hóa việc hiển thị dữ liệu đo từ xa trên màn hình.

# 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)

Người nhận#

is_recording#

is_recording trả về giá trị Boolean cho biết liệu cảm biến hình ảnh được chỉ định có đang ghi hình hay không.

  • True – Cảm biến thị giác được chỉ định đang ghi hình.

  • False – Cảm biến thị giác được chỉ định không ghi hình.

Cách sử dụng:

drone.camera.is_recording(camera)

Thông số

Sự miêu tả

camera

Cảm biến thị giác dùng để kiểm tra trạng thái ghi hình của: DOWNWARD_CAMERA hoặc FORWARD_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 trả về khoảng thời gian mà Cảm biến Thị giác cụ thể đã ghi lại dưới dạng số thập phân (float) tính bằng giây.

Cách sử dụng:

drone.camera.get_recording_time(camera)

Thông số

Sự miêu tả

camera

Cảm biến thị giác dùng để kiểm tra thời gian ghi hình của: DOWNWARD_CAMERA hoặc FORWARD_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)