Vision
Ask what a camera sees, one frame at a time. Each command takes the next frame from a video source, works on it in compiled code and gives back plain numbers, so a script never holds a camera image. Use it for a script deciding something now and then, such as how many red objects are in view or whether the lights are on. Following something frame by frame belongs in a robot skill such as OpenCV Filter Flow or Color Tracking.
Colors are given as [hue, saturation, value] in OpenCV's ranges: hue 0 to 179 (half degrees: red 0, yellow 30, green 60, cyan 90, blue 120, magenta 150), saturation and value 0 to 255. A hue minimum above the maximum wraps around through 0, which is how red is described: [170, 120, 70] to [10, 255, 255]. AverageColor reads these numbers from whatever is in front of the camera.
Where to find it: type Vision. in a Python script, or open the ARCx API view of the script editor and expand Vision
Commands
| Command | What it does |
|---|---|
| Vision.AverageColor | Reads the average color of part of the next frame from a camera. |
| Vision.Brightness | Measures how bright the next frame from a camera is, such as to tell whether the lights are on. |
| Vision.ColorPercent | Measures how much of the next frame from a camera is a color. |
| Vision.CountColor | Counts the separate objects of a color in the next frame from a camera. |
| Vision.FindColor | Finds the largest object of a color in the next frame from a camera. |
| Vision.GetSources | Lists the names of the video sources in the project, such as Camera. |
Details
Vision.AverageColor
Reads the average color of part of the next frame from a camera. Without a region it reads the middle fifth of the picture, so holding an object in front of the camera gives the numbers to use with CountColor. The region is in percent of the picture, so 0, 0, 50, 100 is the left half.
Vision.AverageColor(source)
Vision.AverageColor(source, xPercent, yPercent, widthPercent, heightPercent)
| Value | Type | What it is |
|---|---|---|
source |
str | The video source name, such as Camera. |
xPercent |
number | Optional. The left edge of the region, 0 to 100. |
yPercent |
number | Optional. The top edge of the region, 0 to 100. |
widthPercent |
number | Optional. The width of the region, 0 to 100. |
heightPercent |
number | Optional. The height of the region, 0 to 100. |
Gives back: list. The color as [hue, saturation, value].
Vision.Brightness
Measures how bright the next frame from a camera is, such as to tell whether the lights are on.
Vision.Brightness(source)
| Value | Type | What it is |
|---|---|---|
source |
str | The video source name, such as Camera. |
Gives back: number. The average brightness, 0 (black) to 255 (white).
Vision.ColorPercent
Measures how much of the next frame from a camera is a color.
Vision.ColorPercent(source, hsvMin, hsvMax)
| Value | Type | What it is |
|---|---|---|
source |
str | The video source name, such as Camera. |
hsvMin |
list | The lowest color as [hue, saturation, value], such as [100, 120, 70]. |
hsvMax |
list | The highest color as [hue, saturation, value], such as [130, 255, 255]. |
Gives back: number. The percent of the picture that is the color, 0 to 100.
Vision.CountColor
Counts the separate objects of a color in the next frame from a camera. Objects smaller than 0.1% of the picture are ignored as specks, unless a different smallest size is given.
Vision.CountColor(source, hsvMin, hsvMax)
Vision.CountColor(source, hsvMin, hsvMax, minAreaPercent)
| Value | Type | What it is |
|---|---|---|
source |
str | The video source name, such as Camera. |
hsvMin |
list | The lowest color as [hue, saturation, value], such as [100, 120, 70]. |
hsvMax |
list | The highest color as [hue, saturation, value], such as [130, 255, 255]. |
minAreaPercent |
number | Optional. The smallest object counted, in percent of the picture, such as 1. |
Gives back: number. How many objects of the color are in view.
# Say how many red things the robot can see
count = Vision.CountColor("Camera", [170, 120, 70], [10, 255, 255])
Audio.Say("I can see " + str(count) + " red things")
Vision.FindColor
Finds the largest object of a color in the next frame from a camera.
Vision.FindColor(source, hsvMin, hsvMax)
| Value | Type | What it is |
|---|---|---|
source |
str | The video source name, such as Camera. |
hsvMin |
list | The lowest color as [hue, saturation, value], such as [100, 120, 70]. |
hsvMax |
list | The highest color as [hue, saturation, value], such as [130, 255, 255]. |
Gives back: list. [centerX, centerY, width, height, areaPercent] in camera pixels, or an empty list when the color is not in view.
blue = Vision.FindColor("Camera", [100, 120, 70], [130, 255, 255])
if len(blue) > 0:
print("Blue object at", blue[0], blue[1])
else:
print("No blue in view")
Vision.GetSources
Lists the names of the video sources in the project, such as Camera. Pass one of these to the other Vision commands.
Vision.GetSources()
Gives back: list. The video source names, or an empty list when there are none.