Pytorch_人脸检测

人脸检测

人脸识别的目的就是要对图片和视频中人脸的身份进行判断
Face Recognition 
docker pull animcogn/face_recognition:cpu-nightly

  Harr级联人脸检测、Dlib人脸检测器
 【Dlib人脸检测】1. HOG特征描述方法	 https://blog.csdn.net/qq_44431690/article/details/106149793
   The Viola–Jones object detection framework is a machine learning object detection framework 
proposed in 2001 by Paul Viola and Michael Jones.

https://hub.docker.com/r/animcogn/face_recognition
https://github.com/ageitgey/face_recognition
  ArcFace  与Softmax、SphereFace和CosFace比较  虹软(ArcSoft) — 让视界从此不同
      
    load_image_file
    face_locations face_landmarks
    face_encodings compare_faces

人脸检测数据集

CelebFaces Attributes Dataset (CelebA) 
面部遮挡多姿态人脸识别数据集 戴口罩人脸识别数据集

 左上角(xmin,ymin)和右下角(xmax,ymax)坐标

人脸可视化代码

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# -----------------------------------
# Name:         plot_label.py
# Description:  Pillow 绘制bbox 以及opencv 绘制bbox
# ---------------------------------------

from PIL import Image, ImageDraw
import cv2
import os

def pil_draw(img_path,label_location):
    # 1.读取图片  size 宽度和高度
    im = Image.open(img_path)  
    print(img_path,im.size)
    draw = ImageDraw.Draw(im)
    for label_coord in label_location:
         bbox =label_coord[1:5]
         left,top,right,bottom =bbox[0],bbox[1],bbox[2],bbox[3]
         label=label_coord[0]
         #  # 绘制矩形框,加入label文本
         # label=right,top,left ,bottom
         # draw.rectangle(((left, top), (right, bottom)), outline=(0, 0, 255))
         draw.rectangle([left,top, right ,bottom], outline='red', width = 2 )
         # 1为字体缩放比例,2表示自体粗细
         draw.text([right,top ], str(label),fill=(255, 255, 255))
    out_img= os.path.join(os.path.split(img_path)[0],"PIL_draw_img.jpg")
    print(out_img)
    im.save(out_img)



def cv_draw(img_path,label_location):
    # 1.读取图片  shape(高度,宽度,颜色通道数目) H,W,C
    image = cv2.imread(img_path)
    print(img_path,image.shape)
    # 2.获取标签 label1,bbox
    # 边框格式 bbox = [xl, yl, xr, yr]
    for label_coord in label_location:
         bbox =label_coord[1:5]
         left,top,right,bottom =bbox[0],bbox[1],bbox[2],bbox[3]
         label=label_coord[0]
         # 设置字体格式及大小
         font = cv2.FONT_HERSHEY_SIMPLEX
         #label=(x_min,y_min),(x_max,y_max)
         cv2.rectangle(image, (left,top ), (right ,bottom), color=(0,0,255), thickness = 2 )
         # 1为字体缩放比例,2表示自体粗细
         cv2.putText(image, label, (right,top), font, 1, (255, 255, 255), 2)
    out_img= os.path.join(os.path.split(img_path)[0],"cv_draw_img.jpg")
    print(out_img)
    cv2.imwrite(out_img,image)


if __name__ == '__main__':
    exp_img_path=r"D:\in\C01.jpg"
    exp_label_location = ( ['man',72, 41, 208, 330], ['woman',100, 80, 248, 334])
    pil_draw(img_path=exp_img_path,label_location=exp_label_location)
    cv_draw(img_path=exp_img_path,label_location=exp_label_location)
###从方位讲-上下左右
#label=right,top,left ,bottom
###从坐标上讲
#label=x_min,y_min,x_max,y_max
###从坐标的数据表示上看

Python可视化

OpenCV

scikit-image 是一个专门用于图像处理的 Python 库,
      它可以与 Scipy 库和其他可能有助于计算的 Python 库一起使用,
	  为了充分使用 scikit-image,
	  用户还必须使用 Matplotlib 来显示转换后的图像并进行图像分析
Matplotlib
  import matplotlib.pyplot as plt
  #创建画布
   fig = plt.figure()
  
Pillow  
    Matplotlib与OpenCV都以ndarray的格式存储读取的图片,
	 而Pillow以其自定义的格式读取图片,但是可以轻松地通过np.array对两种格式进行转换,

    Pillow is the friendly PIL fork by Alex Clark and Contributors. 
        PIL is the Python Imaging Library by Fredrik Lundh and Contributor
    	PIL仅支持到Python 2.7,加上年久,
    	于是一群在PIL的基础上创建了兼容的版本,名字叫Pillow,支持最新Python 3.x,pip install pillow
    
    https://github.com/python-pillow/Pillow
    https://pillow.readthedocs.io/en/latest/handbook/index.html
	
Seaborn	

图像坐标

 --------------> x1
 |
 | y
###从方位讲-上下左右
label=right,top,left ,bottom
###从坐标上讲
label=x_min,y_min,x_max,y_max

python中的四元数和旋转矩阵转换

 返回值四元数形式- # "x","y" ,"z" ,"w"
 matlab中有dcm2quat()函数;
 python中可以利用 from pyquaternion import Quaternion 
             或者 from scipy.spatial.transform import Rotation as R来实现
 
 三维旋转 scipy.spatial.transform.Rotation
 from scipy.spatial.transform import Rotation 
 import open3d as o3d
 from pyquaternion import Quaternion

参考

 https://github.com/CMU-Perceptual-Computing-Lab/openpose	
 http://vis-www.cs.umass.edu/lfw/ Labeled Faces in the Wild Home
posted @ 2023-02-13 13:34  辰令  阅读(104)  评论(0编辑  收藏  举报