AI 비전 센서#
소개#
IQ AI 비전 센서는 사물, 색상 및 AprilTag ID를 감지하고 추적할 수 있습니다. 이를 통해 로봇은 주변 환경을 분석하고, 물체를 추적하며, 감지된 시각 데이터를 기반으로 반응할 수 있습니다.
For the examples below, the configured IQ AI Vision Sensor will be named ai_vision_1, and the configured Color Signature objects, such as RED_BOX, will be used in all subsequent examples throughout this API documentation when referring to AiVision class methods.
다음은 모든 방법 목록입니다.
데이터 가져오기 — IQ AI 비전 센서에서 데이터를 가져옵니다.
take_snapshot— 특정 서명에 대한 데이터를 캡처합니다.installed— IQ AI 비전 센서가 IQ(2세대) 브레인에 연결되어 있는지 여부.
속성 — take_snapshot에서 반환된 객체 데이터.
.exists— 현재 감지에 객체가 존재하는지 여부..width— 감지된 객체의 너비..height— 감지된 객체의 높이..centerX— 객체 중심의 X 위치..centerY— 객체 중심의 Y 위치..angle— 색상 코드 또는 AprilTag ID의 방향..originX— 객체의 왼쪽 상단 모서리의 X 위치..originY— 객체의 왼쪽 상단 모서리의 Y 위치..id— 객체의 분류 또는 태그 ID..score— AI 분류에 대한 신뢰도 점수.
생성자 — 센서를 수동으로 초기화하고 구성합니다.
게터스#
take_snapshot#
take_snapshot IQ AI 비전 센서의 프레임에서 데이터를 단일 서명(사전 학습된 객체, AprilTag ID 또는 구성된 색상 서명이나 색상 코드와 같이 센서가 인식할 수 있는 것에 대한 저장된 설명)으로 필터링하고 튜플을 반환합니다.
색상 서명 및 색상 코드는 이 방법을 사용하기 전에 먼저 Vision Utility에서 구성해야 합니다.
튜플은 인덱스 0부터 시작하여 너비가 큰 순서부터 작은 순서로 정렬된 객체를 저장합니다. 각 객체의 속성은 해당 인덱스를 사용하여 접근할 수 있습니다. 일치하는 객체가 감지되지 않으면 빈 튜플이 반환됩니다.
Usage:
ai_vision_1.take_snapshot(SIGNATURE)
매개변수 |
설명 |
|---|---|
|
지정된 서명에 해당하는 데이터만 포함하도록 데이터 세트를 필터링합니다. 사용 가능한 서명은 다음과 같습니다.
|
|
선택 사항입니다. 반환할 수 있는 객체의 최대 개수를 1에서 24 사이로 설정합니다(기본값: 8). |
# Move forward if an object is detected
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
drivetrain.drive_for(FORWARD, 50, MM)
wait(50, MSEC)
Note: The returned tuple can be sorted by any property, not just width, using Python’s sorted function. For example, sorting by AprilTag ID:
# Print each detected AprilTag ID in ascending order by ID
while True:
apriltags = sorted(ai_vision_1.take_snapshot(AiVision.ALL_TAGS), key=id)
for tag in apriltags:
print(tag.id)
wait(1, SECONDS)
또는 높이 순으로 정렬할 수도 있습니다.
# Print each detected AprilTag ID in ascending order by height
while True:
apriltags_by_height = sorted(ai_vision_1.take_snapshot(AiVision.ALL_TAGS), key=lambda tag: tag.height)
for tag in apriltags_by_height:
print(tag.height)
wait(1, SECONDS)
AI 분류#
IQ AI 비전 센서는 특정 AI 분류에 따라 다양한 객체를 감지할 수 있습니다. 장치 창에서 AI 비전 센서를 구성할 때 선택한 AI 분류 모델에 따라 감지되는 객체가 달라집니다. 현재 사용 가능한 모델은 다음과 같습니다.
교실 용품
신분증 번호 |
AI 분류 |
|---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
VEX IQ 로봇 경진대회 믹스 앤 매치
신분증 번호 |
AI 분류 |
|---|---|
0 |
|
1 |
|
2 |
|
3 |
|
VEX IQ 로봇 경진대회 레벨 업
신분증 번호 |
AI 분류 |
|---|---|
0 |
|
1 |
|
2 |
|
색상 특징#
컬러 시그니처는 IQ AI 비전 센서가 인식할 수 있는 고유한 색상입니다. 이러한 시그니처를 통해 IQ AI 비전 센서는 색상을 기반으로 객체를 감지하고 추적할 수 있습니다. 컬러 시그니처가 구성되면 센서는 시야 내에서 해당 특정 색상의 객체를 식별할 수 있습니다. 컬러 시그니처는 take_snapshot과 함께 사용하여 실시간으로 색상이 있는 객체를 처리하고 감지합니다.
프로젝트에서 구성된 컬러 시그니처를 사용하려면 해당 이름은 센서 이름, 두 개의 밑줄, 그리고 컬러 시그니처 이름이어야 합니다. 예를 들어: ai_vision_1__RED_BOX.
# Display if any objects match the RED_BOX signature
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_row(1)
# Change to any configured Color Signature
red_box = ai_vision_1.take_snapshot(ai_vision_1__RED_BOX)
if red_box[0].exists:
brain.screen.print("Color detected!")
wait(100, MSEC)
색상 코드#
컬러 코드는 특정 순서로 배열된 색상 특징으로 구성된 구조화된 패턴입니다. 이 코드를 통해 IQ AI 비전 센서는 미리 정의된 색상 패턴을 인식할 수 있습니다. 컬러 코드는 복잡한 물체를 식별하거나 자율 주행을 위한 고유한 마커를 생성하는 데 유용합니다.
프로젝트에서 구성된 컬러 코드를 사용하려면 해당 이름은 센서 이름, 두 개의 밑줄, 그리고 컬러 코드 이름이어야 합니다. 예를 들어: ai_vision_1__BOX_CODE.
# Display if any objects match the BOX_CODE code
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_row(1)
# Change to any configured Color Code
box_code = ai_vision_1.take_snapshot(ai_vision_1__BOX_CODE)
if box_code[0].exists:
brain.screen.print("Code detected!")
wait(100, MSEC)
installed#
installed IQ AI 비전 센서가 현재 IQ(2세대) 브레인에 연결되어 있는지 여부를 나타내는 부울 값을 반환합니다.
True— IQ AI 비전 센서가 IQ(2세대) 브레인에 연결되어 있습니다.False— IQ AI 비전 센서는 IQ(2세대) 브레인에 연결되어 있지 않습니다.
Usage:
ai_vision_1.installed()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Display a message if the AI Vision Sensor is connected
if ai_vision_1.installed():
brain.screen.print("Installed!")
속성#
take_snapshot을 사용한 후 tuple에 저장된 각 객체에는 10개의 속성이 포함됩니다.
.id 및 .score 을 제외한 모든 속성 값은 take_snapshot 이 사용된 시점에 IQ AI Vision 센서의 시야에서 감지된 객체의 위치와 크기를 나타냅니다. 이 값들은 센서의 320x240 픽셀 해상도를 기준으로 픽셀 단위로 측정됩니다.
.exists#
.exists 튜플에 해당 인덱스가 존재하는지 여부를 나타내는 부울 값을 반환합니다.
True— 인덱스가 존재합니다.False— 인덱스가 존재하지 않습니다.
# Check if at least two objects are detected
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[1].exists:
brain.screen.print("At least 2")
else:
brain.screen.print("Less than 2")
wait(50, MSEC)
.width#
.width 감지된 객체의 너비를 픽셀 단위로 반환하며, 이는 1에서 320 사이의 정수입니다.
# Approach an object until it's at least 100 pixels wide
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[0].width < 100:
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(50, MSEC)
.height#
.height 감지된 객체의 높이를 픽셀 단위로 반환하며, 이는 1에서 240 사이의 정수입니다.
# Approach an object until it's at least 90 pixels tall
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[0].height < 90:
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(50, MSEC)
.centerX#
.centerX 감지된 객체 중심의 x 좌표를 픽셀 단위로 반환하며, 이 값은 0에서 320 사이의 정수입니다.
# Turn until an object is directly in front of the sensor
drivetrain.set_turn_velocity(10, PERCENT)
drivetrain.turn(RIGHT)
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if 140 < objects[0].centerX < 180:
drivetrain.stop()
wait(10,MSEC)
.centerY#
.centerY 감지된 객체 중심의 y 좌표를 픽셀 단위로 반환하며, 이 값은 0에서 240 사이의 정수입니다.
# Approach an object until the object's center is
# high enough in the field of view
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[0].centerY < 150:
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(50, MSEC)
.angle#
.angle 감지된 색상 코드 또는 AprilTag ID의 방향을 도 단위로 반환하며, 이는 0에서 359 사이의 정수입니다.
# Turn left or right depending on how a
# configured Color Code is rotated
while True:
box_code = ai_vision_1.take_snapshot(ai_vision_1__BOX_CODE)
if box_code[0].exists:
if 50 < box_code[0].angle < 100:
drivetrain.turn(RIGHT)
elif 270 < box_code[0].angle < 330:
drivetrain.turn(LEFT)
else:
drivetrain.stop()
else:
drivetrain.stop()
wait(50, MSEC)
.originX#
.originX 감지된 객체의 경계 상자의 왼쪽 상단 모서리의 x 좌표를 픽셀 단위로 반환하며, 이는 0에서 320 사이의 정수입니다.
# Display if an object is to the left or the right
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1,1)
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[0].originX < 120:
brain.screen.print("To the left!")
else:
brain.screen.print("To the right!")
else:
brain.screen.print("No objects")
wait(100, MSEC)
.originY#
.originY 감지된 객체의 경계 상자의 왼쪽 상단 모서리의 y 좌표를 픽셀 단위로 반환하며, 이는 0에서 240 사이의 정수입니다.
# Display if an object is close or far
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1,1)
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
if objects[0].originY < 110:
brain.screen.print("Close")
else:
brain.screen.print("Far")
.id#
.id 감지된 AI 분류 또는 AprilTag ID의 ID를 정수로 반환합니다. AI 분류는 AI Vision Utility에 구성된 모델에 따라 달라집니다.
AprilTag ID의 경우 .id 속성은 0~36 범위의 감지된 AprilTag ID 번호를 나타냅니다. AI 분류의 경우 .id 속성은 AI 분류 섹션에 있는 미리 정의된 ID에 해당합니다.
# Move forward when AprilTag ID 1 is detected
while True:
apriltags = ai_vision_1.take_snapshot(AiVision.ALL_TAGS)
if apriltags[0].exists:
if apriltags[0].id == 1:
robot.drive(FORWARD)
else:
drivetrain.stop()
wait(50, MSEC)
.score#
.score 감지된 AI 분류의 신뢰도 점수를 1에서 100 사이의 정수로 반환합니다.
점수가 낮을수록 센서가 감지한 물체에 대해 확신도가 낮다는 의미이고, 점수가 높을수록 센서가 더 확신한다는 의미입니다.
# Display if a score is confident
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
if objects[0].exists:
if objects[0].score > 95:
brain.screen.print("Confident")
else:
brain.screen.print("Not confident")
wait(50, MSEC)
건설업자#
생성자는 VEXcode 외부에서 IQ AI 비전 센서를 구성하는 데 필요한 AiVision, Colordesc및 Codedesc 객체를 수동으로 생성하는 데 사용됩니다.
AI Vision Sensor#
AiVision IQ AI 비전 센서를 생성합니다.
용법
Vision(port, sigs)
매개변수 |
설명 |
|---|---|
|
IQ AI 비전 센서가 연결된 스마트 포트는 1번부터 12번까지 중 몇 번째 포트입니까? |
|
선택 사항입니다. 하나 이상의 서명 이름: |
예
ai_vision_1 = AiVision(Ports.PORT1, AiVision.ALL_AIOBJS)
# Move forward if an object is detected
while True:
objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
if objects[0].exists:
drivetrain.drive_for(FORWARD, 50, MM)
wait(50, MSEC)
Color Signature#
Colordesc 컬러 시그니처를 생성합니다. IQ AI 비전 센서에는 최대 7개의 서로 다른 컬러 시그니처를 동시에 저장할 수 있습니다.
용법:
Colordesc(index, uMin, uMax, uMean, vMin, vMax, vMean, rgb, type)
매개변수 |
설명 |
|---|---|
|
|
|
비전 유틸리티에서 |
|
비전 유틸리티에서 |
|
비전 유틸리티에서 |
|
비전 유틸리티에서 |
|
비전 유틸리티에서 |
|
Vision Utility에서 |
|
비전 유틸리티에서 |
|
비전 유틸리티에서 |
컬러 시그니처를 생성하기 위한 값을 얻으려면 Vision Utility로 이동하십시오. 컬러 시그니처가 구성되면 구성 창에서 매개변수 값을 복사합니다.
예
# Create a new Signature RED_BOX with the Colordesc class
RED_BOX = Colordesc(1, 10121, 10757, 10439,-1657, -1223, -1440,2.5, 1)
# Create a new AI Vision Sensor "ai_vision_1" with the AiVision
# class, with the RED_BOX Signature.
ai_vision_1 = AiVision(Ports.PORT1, 100, RED_BOX)
# Move forward if a red object is detected
while True:
red_object = ai_vision_1.take_snapshot(RED_BOX)
if red_object[0].exists:
drivetrain.drive_for(FORWARD, 10, MM)
wait(5, MSEC)
Color Code#
Codedesc 색상 코드를 생성합니다. 사용하려면 최소 두 개의 이미 정의된 색상 시그니처가 필요합니다. 비전 센서에는 최대 8개의 서로 다른 색상 코드를 동시에 저장할 수 있습니다.
용법:
Codedesc(sig1, sig2, sig3, sig4, sig5)
매개변수 |
설명 |
|---|---|
|
이전에 생성된 색상 서명. |
|
이전에 생성된 색상 서명. |
|
선택 사항. 이전에 생성된 색상 서명. |
|
선택 사항. 이전에 생성된 색상 서명. |
|
선택 사항. 이전에 생성된 색상 서명. |
예
# Create two new Signatures for a red and blue box
RED_BOX = Colordesc(1, 10121, 10757, 10439,-1657, -1223, -1440, 2.5, 1)
BLUE_BOX = Colordesc(2, -4443, -3373, -3908,6253, 7741, 6997, 2.5, 1)
# Create a Color Code for a red box to the left of a blue box
RED_BLUE = Codedesc(RED_BOX, BLUE_BOX)
# Create a new AI Vision Sensor "ai_vision_1" with the AiVision
# class, with the RED_BOX and BLUE_BOX Signatures.
ai_vision_1 = AiVision(Ports.PORT1, RED_BOX, BLUE_BOX)
# Display a message if Color Code is detected
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_row(1)
# Change to any configured Color Code
box_code = ai_vision_1.take_snapshot(RED_BLUE)
if box_code[0].exists:
brain.screen.print("Code detected!")
wait(100, MSEC)