vision_face

영상처리, 인공지능 비전 기술을 사용합니다.

Class: putTextPIL() Face

openpibo.vision_face.putTextPIL(img, text, points, size=30, colors=(255, 255, 255))[소스]

이미지에 문자를 입력합니다. (한/영 가능 - pillow 이용)- COPY

매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • text (str) – 표시할 문자열

  • points (tuple(int, int)) – 텍스트 블록 좌측상단 좌표 (x, y)

  • size (int) – 표시할 글자의 크기

  • colors (tuple(int, int, int)) – 글자 색깔 RGB 값 (b, g, r) or 16진수 값 ‘#ffffff’

openpibo.vision_face.vision_api(mode, image, params={})[소스]

인공지능 비전 API를 호출합니다.

매개변수:
  • mode (str) – 호출할 비전 API (https://o-vapi.circul.us/guide)

  • image (str/numpy.ndarray) – 표시할 이미지 (파일 경로 or cv 이미지)

반환:

Json 타입 결과의 데이터

example:

{ 'type': 'caption', 'result': 'ok', 
  'data': {
    caption:  "사람에게 로봇을 과시하는 사람", 
    caption_en:  "a person showing off a robot to a person",
    raw:  [
      "a person showing off a robot to a person",
      "a robot that is sitting on top of a table",
      "a very cute white robot that is sitting in front of a table"
    ]
  }
}
class openpibo.vision_face.Face[소스]

기반 클래스: object

Functions: detect() get_ageGender() get_age() get_gender() init_db() train_face() delete_face() recognize() get_db() save_db() load_db()

얼굴과 관련된 다양한 기능을 수행하는 클래스입니다. 다음 기능을 수행할 수 있습니다.

  • 얼굴을 탐색합니다.

  • 얼굴을 학습/저장/삭제합니다.

  • 학습된 얼굴을 인식합니다.

  • 얼굴로 나이/성별/감정을 추정합니다.

얼굴 데이터베이스:

인스턴스 변수 facedb 를 의미하며, 여기에서 얼굴 데이터를 등록하고 불러오고 삭제합니다.

얼굴 데이터베이스의 포맷은 이중 list [[], []] 이며, 첫 번째 list에는 얼굴의 이름이, 두 번째 list에는 학습된 얼굴 데이터가 인코딩되어 들어갑니다.

또한 파일로 저장하여 인스턴스가 삭제된 후에도 얼굴 정보를 남겨둘 수 있습니다.

example:

from openpibo.vision_detect import Face

face = Face()
# 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
detect_face(img)[소스]

얼굴을 탐색합니다.

example:

img = camera.read()
face.detect_face(img)
매개변수:

img (numpy.ndarray) – 이미지 객체

반환:

인식된 얼굴들의 (x, y, w, h) 배열 입니다.

list 타입으로, 이미지 하나에 얼굴이 여러 개 인식된 경우 인식된 얼굴의 좌표가 모두 입력됩니다.

example:

[(10, 10, 40, 50), (120, 30, 160, 70), (130, 140, 200, 260)]

detect_face_vis(img, items)[소스]

얼굴 box 표시합니다.

매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (array) – 얼굴 좌표 (x1,y1,x2,y2) 리스트

landmark_face(img, item)[소스]

얼굴의 랜드마크를 탐색합니다.

example:

img = camera.read()
face.landmark_face(img)
매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (array) – 얼굴 좌표 (x1,y1,x2,y2)

반환:

좌표 리스트

landmark_face_vis(img, coords)[소스]

얼굴의 랜드마크를 탐색합니다.

example:

img = camera.read()
face.landmark_face(img)
매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (array) – 얼굴 좌표 (x1,y1,x2,y2)

반환:

좌표 리스트

analyze_face(img, item)[소스]

얼굴의 나이, 성별, 감정을 추정합니다.

example:

img = camera.read()
items = face.detect_face(img)
item = items[0] # item은 items 중 하나
face.analyze_face(img, item)
매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (numpy.ndarray) – 얼굴의 좌표 (x, y, w, h)

반환:

{age: 0~100, gender: Male 또는 Female, emotions: neutral, happy, sad, surprise, anger, box:좌표}

analyze_face_vis(img, item)[소스]

얼굴의 나이, 성별, 감정을 추정합니다.

매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (numpy.ndarray) – 얼굴 분석 결과

init_db()[소스]

얼굴 데이터베이스를 초기화합니다.

초기화된 데이터베이스는 빈 이중 list [[], []] 입니다.

example:

face.init_db()
train_face(img, item, name)[소스]

얼굴을 학습하여 얼굴 데이터베이스에 저장합니다.

example:

img = camera.read()
items = face.detect_face(img)
item = items[0] # item는 items중 하나
face.train_face(img, item, 'honggildong')
매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (numpy.ndarray) – 디텍팅한 얼굴의 사각형 좌측상단, 우측하단 포인트 (x1, y1, x2, y2)

  • name (str) – 디텍팅한 얼굴에 붙일 이름

delete_face(name)[소스]

등록된 얼굴을 삭제합니다.

example:

face.delete_face('honggildong')
매개변수:

name (str) – 삭제할 얼굴의 이름

반환:

True / False

recognize(img, item)[소스]

등록된 얼굴을 인식합니다.

example:

img = camera.read()
items = face.detect_face(img)
item = items[0] # item는 items중 하나
face.recognize(img, item)
매개변수:
  • img (numpy.ndarray) – 이미지 객체

  • item (numpy.ndarray) – 얼굴의 좌표 (x, y, w, h)

반환:

{"name": 이름, "score": 오차도}

얼굴이 비슷할수록 오차도가 낮게 측정됩니다.

오차도가 0.4 이하일 때 동일인으로 판정합니다.

get_db()[소스]

사용 중인 얼굴 데이터베이스를 확인합니다.

example:

face.get_db()
반환:

facedb (list(list, list) 타입)

example:

[
  ['honggildong'],
  [array([-0.06423206,  0.12474005,  0.0511112 , -0.05676335, -0.07211345,
          -0.03123881, -0.04119622, -0.12800875,  0.11717855, -0.11079554,
           0.22952782, -0.02007426, -0.17457265, -0.13562854, -0.04972655,
           0.15810637, -0.12785575, -0.16479518, -0.07002968, -0.00208595,
           0.169218  ,  0.03144928, -0.01074579,  0.04103286, -0.09245337,
          ...
          -0.00706697,  0.06025593, -0.0049719 ])]
]

save_db(filename)[소스]

얼굴 데이터베이스를 파일로 저장합니다.

example:

face.save_db('/home/pi/facedb')
매개변수:

filename (str) – 저장할 얼굴 데이터베이스 파일의 경로입니다.

load_db(filename)[소스]

얼굴 데이터베이스 파일을 불러옵니다.

example:

face.load_db('/home/pi/facedb')
매개변수:

filename (str) – 불러 올 facedb 파일의 경로입니다.

calculate_head_orientation(keypoints)[소스]

(내부 함수) 얼굴 랜드마크 데이터를 통해 얼굴 방향 계산

get_angle_between_lines(start, point1, point2)[소스]

Calculate angle between two lines defined by three points.

detect_mesh_vis(image, items)[소스]

Draw connections between landmarks based on Mediapipe’s face mesh.

detect_mesh(image)[소스]

Detect mesh and return distance, direction, and image with landmarks.