复现PTA人事机考照片审核的功能

官方PTA照片审核软件下载地址:http://202.61.89.231/download-A57C21A39F5FEBE5

主要涉及5个方向的判别:

1、文件大小

2、图片的真实格式

3、图片的尺寸

4、背景颜色是不是符合要求

5、人脸是否正常,包括是半身照还是寸照、头部在不在中间等。

import cv2 as cv
import imghdr
import numpy as np
from io import BytesIO
import json
import time
import shutil
import io
import os
import logging
from cv2 import dnn
from face_detect import UltraFace as uf
allow_format_jpg = ["jpg", "JPG", "jpeg", "JPEG"]
# 字节bytes转化kb\M\G
def pre_formatSize(bytes):
    try:
        bytes = float(bytes)
        kb = bytes / 1024
    except:
        print("传入的字节格式不对")
        return "Error"
    return round(kb,2)

# 获取文件大小
def file_size_1st(path):
    try:
        size = os.path.getsize(path)
        return pre_formatSize(size)
    except Exception as err:
        print(err)

# 检查文件大小
def check_file_size(vol, file_size_min, file_size_max): 
    if vol>=file_size_min and vol<=file_size_max:
        return True
    else:
        return False

# 检查图像格式
def is_allow_format_2nd(path):
    flag =  imghdr.what(path)
    if flag not in allow_format_jpg:
        # 会有空判断出现
        if flag==None:
            s = path.split(".")[-1]
            if s in allow_format_jpg:
                flag =  True
            else:
                flag = False
        else:
            flag = False
    else:
        flag = True
    return flag

# 检查图像尺寸
def is_1inch_3rd(path, pic_size_lower_height, 
                pic_size_lower_width, pic_size_higher_height, 
                pic_size_higher_width):
    im = cv.cvtColor(cv.imread(path), cv.COLOR_BGR2RGB)  
    w,h,_ = im.shape
    if(w>=pic_size_lower_height and w<=pic_size_higher_height and \
        h>=pic_size_lower_width and h<=pic_size_higher_width and im.shape[2]==3):
        return True
    else:
        return False

# 检查背景颜色
def is_blue_white_red_bg_4th(pic_path):
    im = cv.imread(pic_path)
    check_bar = im[10:20,10:20]
    hsv=cv.cvtColor(check_bar,cv.COLOR_BGR2HSV)
    # # 蓝底
    # blue_hsv_min = np.array([78,43,46]) # 默认色值
    # blue_hsv_max = np.array([124,255,255])
    blue_hsv_min = np.array([78,42,46])  # 自定义
    blue_hsv_max = np.array([140,255,255])    
    blue_mask=cv.inRange(hsv,blue_hsv_min,blue_hsv_max)
    blue_avg_bitmap = np.mean(blue_mask)
    # print(blue_avg_bitmap)
    # # 白底
    white_hsv_min = np.array([0,0,221])
    white_hsv_max = np.array([190,30,255])
    white_mask=cv.inRange(hsv,white_hsv_min,white_hsv_max)
    white_avg_bitmap = np.mean(white_mask)
    # print(white_avg_bitmap)
    # # 红底
    red_hsv_min_1 = np.array([0,43,46])
    red_hsv_max_1 = np.array([10,255,255])
    red_hsv_min_2 = np.array([156,43,46])
    red_hsv_max_2 = np.array([180,255,255])
    red_mask_1=cv.inRange(hsv,red_hsv_min_1,red_hsv_max_1)
    red_mask_2=cv.inRange(hsv,red_hsv_min_2,red_hsv_max_2)
    red_mask = red_mask_1 +
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值