资源简介
python文件,需要安装python,需要有cv2的库。首先cmd,cd 你的路径,python annotate_faces.py -d ./img -n 4(是图片数目)。但是不能保存坐标值,可以对其修改保存坐标值。
代码片段和文件信息
#!/usr/bin/env python
“““
Facial landmark annotation tool
This program expects either a single image as an argument or a directory
with many images and a number n of images to be processed in that directory.
In this last case names are sorted and images at positions 0 floor(N/n)
floor(2N/n) ... floor((n - 1)N/n) are selected.
Output is to stdout and follows a csv format:
‘image_fname‘ +
‘leye_xleye_yreye_xreye_ynose_xnose_y ‘ +
‘lmouth_xlmouth_yrmouth_xrmouth_y‘ +
‘rect_top_xrect_top_yrect_widthrect_height‘
It is not necessary to annotate all points and images can be skipped when
in multiple image mode.
Run without arguments for usage information.
“““
from __future__ import print_function
from __future__ import division
import os
import argparse
import warnings
import cv2
from matplotlib import pyplot as plt
from matplotlib.widgets import Button
import matplotlib.cbook
warnings.filterwarnings(‘ignore‘ category=matplotlib.cbook.mplDeprecation)
def enum(**enums):
return type(‘Enum‘ () enums)
class InteractiveViewer(object):
def __init__(self img_path):
self.img_path = img_path
self.key_pressed = False
self.key_event = None
self.rect_clicked = False
self.rect_coords = [(0 0) (0 0)]
self.leye_coords = None
self.reye_coords = None
self.nose_coords = None
self.lmouth_coords = None
self.rmouth_coords = None
self.image = cv2.imread(img_path)
self.image = cv2.cvtColor(self.image cv2.COLOR_BGR2RGB)
self.clone = self.image.copy()
self.fig = None
self.im_ax = None
self.button_rect = None
self.button_leye = None
self.button_reye = None
self.button_nose = None
self.button_lmouth = None
self.button_rmouth = None
self.button_done = None
self.button_skip = None
self.is_finished = False
self.is_skipped = False
self.States = enum(GET_RECT=1
GET_LEYE=2
GET_REYE=3
GET_NOSE=4
GET_LMOUTH=5
GET_RMOUTH=6)
self.curr_state = self.States.GET_RECT
def redraw_annotations(self):
self.image = self.clone.copy()
cv2.rectangle(self.image self.rect_coords[0] self.rect_coords[1]
(0 255 0) 5)
if self.leye_coords is not None:
cv2.circle(self.image self.leye_coords 10 (255 0 0) -1)
if self.reye_coords is not None:
cv2.circle(self.image self.reye_coords 10 (255 0 0) -1)
if self.nose_coords is not None:
cv2.circle(self.image self.nose_coords 10 (255 0 0) -1)
if self.lmouth_coords is not None:
cv2.circle(self.image self.lmouth_coords 10 (255 0 0) -1)
if self.rmouth_coords is not None:
cv2.circle(self.imag
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-16 20:28 annotate-faces-master (1)\
目录 0 2017-10-16 20:50 annotate-faces-master (1)\annotate-faces-master\
文件 6 2017-10-09 02:07 annotate-faces-master (1)\annotate-faces-master\.gitignore
文件 13020 2017-10-09 02:07 annotate-faces-master (1)\annotate-faces-master\annotate_faces.py
目录 0 2017-10-16 20:49 annotate-faces-master (1)\annotate-faces-master\img\
文件 6613 2013-04-15 17:52 annotate-faces-master (1)\annotate-faces-master\img\Aaron_Eckhart_0001.jpg
文件 9052 2013-04-15 17:52 annotate-faces-master (1)\annotate-faces-master\img\Aaron_Guiel_0001.jpg
文件 74240 2017-10-16 20:47 annotate-faces-master (1)\annotate-faces-master\img\Thumbs.db
文件 1081 2017-10-09 02:07 annotate-faces-master (1)\annotate-faces-master\LICENSE.md
文件 439 2017-10-09 02:07 annotate-faces-master (1)\annotate-faces-master\README.md
文件 6566 2017-10-16 20:49 annotate-faces-master (1)\annotate-faces-master\图像名字不能是__.png
评论
共有 条评论