vision_detect · Object, QR, hand and pose recognition

Detects objects, QR codes, poses, hand gestures and markers.

Class: putTextPIL() Detect

openpibo.vision_detect.putTextPIL(img, text, points, size=30, colors=(255, 255, 255))[source]

Writes text on an image. (Korean/English supported - uses pillow)- COPY

Parameters:
  • img (numpy.ndarray) – Image object

  • text (str) – Text to display

  • points (tuple(int, int)) – Top-left coordinates of the text block (x, y)

  • size (int) – Font size of the text

  • colors (tuple(int, int, int)) – Text color BGR value (b, g, r) or hex value ‘#rrggbb’

class openpibo.vision_detect.Detect(object_model=None)[source]

Bases: object

Functions: load_object_model() detect_object() detect_object_vis() detect_qr() detect_qr_vis() detect_pose() detect_pose_vis() analyze_pose() load_hand_gesture_model() recognize_hand_gesture() recognize_hand_gesture_vis() detect_marker() detect_marker_vis()

A class that provides various detection functions.

  • Object detection (easydetect ed, 80 COCO classes by default · models trained in the lab, onnxruntime)

  • QR/barcode detection (pyzbar)

  • Pose detection (MoveNet)

  • Hand gesture recognition (MediaPipe)

  • Marker detection (ArUco)

example:

from openpibo.vision_detect import Detect

detect = Detect()
# 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
load_hand_gesture_model(modelpath='/home/pi/.model/hand/gesture_recognizer.task')[source]

Loads a hand gesture recognition model.

Parameters:

modelpath (str) – Path of the hand gesture recognition model

recognize_hand_gesture(image)[source]

Recognizes hand gestures.

Parameters:

image (numpy.ndarray) – Image object

Returns:

Hand gesture recognition result depending on the model

recognize_hand_gesture_vis(img, items)[source]

Displays the hand gesture recognition result.

Parameters:
  • img (numpy.ndarray) – Image object

  • items (array) – Hand gesture recognition result

load_object_model(modelpath=None)[source]

Loads an object detection model.

Picks an easydetect model file (.onnx). The job<number>.onnx downloaded from the easydetect lab works as it is. The class names and the score threshold are inside the file; the names may be Korean. If the model cannot be used (missing file, onnxruntime older than 1.13, a file that does not load), an error says why.

example:

detect.load_object_model('/home/pi/code/job3.onnx')   # lab 에서 받은 모델
detect.load_object_model()                                  # 기본 모델(COCO)로 돌아가기
Parameters:

modelpath (str) – Object detection model file (.onnx). Left out, the default model

detect_object(img)[source]

Finds objects in an image (change the model with load_object_model).

Parameters:

img (numpy.ndarray) – Image object

Returns:

[{"name": name, "score": score(%), "box": (x1, y1, x2, y2)}, ...]

detect_object_vis(img, items)[source]

Displays the object detection result.

Parameters:
  • img (numpy.ndarray) – Image object

  • items (array) – Object detection result

detect_qr(img)[source]

Detects QR codes and barcodes in an image.

example:

img = camera.read()
detect.detect_qr(img)
Parameters:

img (numpy.ndarray) – Image object

Returns:

{"data": content, "type": barcode / QR code, "position":(startX,startY,endX,endY)}

detect_qr_vis(img, items)[source]

Displays the QR/barcode result.

Parameters:
  • img (numpy.ndarray) – Image object

  • items (array) – QR detection result

detect_pose(img)[source]

Detects poses in an image.

example:

img = camera.read()
detect.detect_pose(img)
Parameters:

img (numpy.ndarray) – Image object

Returns:

detection result

detect_pose_vis(img, items)[source]

Displays the pose.

Parameters:
  • img (numpy.ndarray) – Image object

  • items (array) – Pose data

analyze_pose(data)[source]

Analyzes the result of the detect_pose function.

example:

img = camera.read()
result = detect.detect_pose(img)
detect.analyze_pose(result)
Parameters:

data (dict) – Image object

Returns:

list of detected poses ['left_hand_up', 'right_hand_up', 'clap']

detect_marker(img, marker_length=2)[source]

Detects markers in an image. # cv2.aruco.DICT_4X4_50

example:

img = camera.read()
result = detect.detect_marker(img)
Parameters:

img (numpy.ndarray) – Image object

Returns:

[{"id": marker number, "center":  }, ...]

detect_marker_vis(img, items)[source]

Displays the marker result.

Parameters:
  • img (numpy.ndarray) – Image object

  • items (array) – Marker result