Skip to main content

cocube_sengo2

import cocube_sengo2 as sg2

Initialization

sg2.init()
sg2.reset()
sg2.change_algo("AprilTag")

Notes:

  • init() waits for the camera to become ready, up to about 5s
  • reset() resets all algorithms
  • most read functions require you to switch to the matching algorithm first

Supported algorithms

  • "Color Recog"
  • "Blob Detect"
  • "AprilTag"
  • "Line Detect"
  • "Deep Learning"
  • "Card Recog"
  • "Face Recog"
  • "Obj20Class"
  • "QRcode"
  • "Motion Detect"

Color recognition

sg2.change_algo("Color Recog")
sg2.set_color_area(x, y, w, h)
sg2.read_color()
sg2.get_color_rgb("R")

Blob detection

sg2.change_algo("Blob Detect")
sg2.set_blob_property("red", w, h)
sg2.read_blob()
sg2.get_blob("x")

AprilTag

sg2.change_algo("AprilTag")
sg2.set_apriltag_type("36H11")
sg2.read_apriltag()
sg2.get_apriltag("x")

Available families:

  • 16H5
  • 25H9
  • 36H11

Line following

sg2.change_algo("Line Detect")
sg2.get_line("degree")
sg2.get_line("x2")

Deep learning

sg2.change_algo("Deep Learning")
sg2.record_learning(id)
sg2.delete_learning(id)
sg2.get_learning_id()

Notes:

  • the valid range for record_learning(id) and delete_learning(id) is 1~15
  • get_learning_id() returns the currently recognized learned category ID

Card recognition

sg2.change_algo("Card Recog")
sg2.read_card()
sg2.get_card("x")

Sengo2 has a larger card set than Sengo1. Common examples include:

  • forward
  • turn_left
  • turn_right
  • turn_around
  • park
  • green_light
  • red_light
  • speed_40
  • speed_60
  • speed_80

Face, 20-class objects, QR code, and motion detection

sg2.change_algo("Face Recog")
sg2.record_face(id)
sg2.delete_face(id)
sg2.get_face_id()

sg2.change_algo("Obj20Class")
sg2.read_obj20()
sg2.get_obj20("x")

sg2.change_algo("QRcode")
sg2.read_qrcode()

sg2.change_algo("Motion Detect")
sg2.get_motion("x")

Notes:

  • the valid range for record_face(id) and delete_face(id) is 1~10
  • Face Recog only returns the face ID directly; it does not expose x / y / w / h bounding boxes
  • read_obj20() returns one of 20 object names, such as person, car, or cat
  • read_qrcode() returns the QR code string content
  • get_motion("x" / "y" / "w" / "h") returns the motion area

Notes

  • set_apriltag_type(...) only accepts 16H5, 25H9, and 36H11
  • when no clear color is recognized, Sengo2 color recognition may return unknown

Minimum example

import time
import cocube_sengo2 as sg2

sg2.init()
sg2.change_algo("Color Recog")

while True:
color_name = sg2.read_color()
if color_name:
print(color_name)
time.sleep_ms(100)