feat 新增人脸识别 中心点检测
This commit is contained in:
@@ -154,11 +154,24 @@ def stain_detection(image, spot_size=100):
|
||||
if num_white_pixels != spot_size * spot_size:
|
||||
logger.info(f"第{index + 1}发现了污点")
|
||||
return False, None
|
||||
|
||||
# 中心区域检测
|
||||
center_x, center_y = width // 2, height // 2
|
||||
center_image = image[center_y - spot_size // 2:center_y + spot_size // 2, center_x - spot_size // 2:center_x + spot_size // 2]
|
||||
gray_center_image = cv2.cvtColor(center_image, cv2.COLOR_BGR2GRAY)
|
||||
white_threshold = 200 # 设定的接近最大值的阈值
|
||||
is_pure_white = (gray_center_image >= white_threshold).all()
|
||||
if is_pure_white:
|
||||
return False, None
|
||||
if DEBUG:
|
||||
for corner_coords in [(0, 0), (0, width - spot_size), (height - spot_size, 0), (height - spot_size, width - spot_size)]:
|
||||
for corner_coords in [
|
||||
(0, 0),
|
||||
# (0, width - spot_size),
|
||||
(height - spot_size, 0),
|
||||
# (height - spot_size, width - spot_size)
|
||||
# 中心点
|
||||
]:
|
||||
cv2.rectangle(image, corner_coords, (corner_coords[0] + spot_size, corner_coords[1] + spot_size), (0, 0, 255), 2)
|
||||
|
||||
cv2.rectangle(image, (center_x - spot_size // 2, center_y - spot_size // 2), (center_x + spot_size // 2, center_y + spot_size // 2), (0, 255, 0), 2) # 在原始图像上绘制矩形框
|
||||
return True, image
|
||||
|
||||
|
||||
@@ -241,6 +254,20 @@ def luminance_adjust(alpha, img):
|
||||
# 14.14 Photoshop 自动色阶调整算法
|
||||
|
||||
|
||||
def face_detect_pic(image):
|
||||
# 1、转灰度图
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
||||
# cv2.imshow("gray", gray)
|
||||
|
||||
# 2、训练一组人脸
|
||||
face_detector = cv2.CascadeClassifier("service/generate_image/utils/haarcascade_frontalface_alt.xml")
|
||||
|
||||
# 3、检测人脸(用灰度图检测,返回人脸矩形坐标(4个角))
|
||||
faces_rect = face_detector.detectMultiScale(gray, 1.05, 3)
|
||||
|
||||
return len(faces_rect)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Photoshop 自动色阶调整算法
|
||||
img = cv2.imread("2.png", flags=1) # 读取彩色图像
|
||||
|
||||
Reference in New Issue
Block a user