From 0c2cf1ec0204298e90902c0569923f7f6706eec0 Mon Sep 17 00:00:00 2001 From: zchen Date: Fri, 26 Apr 2024 15:37:16 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=96=B0=E5=A2=9E=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=20=E4=B8=AD=E5=BF=83=E7=82=B9=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/generate_image/service.py | 16 ++++++++-------- .../generate_image/utils/image_processing.py | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/service/generate_image/service.py b/app/service/generate_image/service.py index d6e9771..03b24be 100644 --- a/app/service/generate_image/service.py +++ b/app/service/generate_image/service.py @@ -85,17 +85,17 @@ class GenerateImage: image_result = cv2.cvtColor(np.squeeze(image.astype(np.uint8)), cv2.COLOR_RGB2BGR) is_smudge = True if self.category == "sketch": + # 色阶调整 + cutoff = 1 + levels_img = autoLevels(image_result, cutoff) + # 亮度调整 + luminance = luminance_adjust(0.3, levels_img) + # 去背景 + remove_bg_image = remove_background(luminance) # 人脸检测 - if face_detect_pic(image_result) > 0: + if face_detect_pic(remove_bg_image) > 0: is_smudge = False else: - # 色阶调整 - cutoff = 1 - levels_img = autoLevels(image_result, cutoff) - # 亮度调整 - luminance = luminance_adjust(0.3, levels_img) - # 去背景 - remove_bg_image = remove_background(luminance) # 污点/ is_smudge, not_smudge_image = stain_detection(remove_bg_image) # 类型识别 diff --git a/app/service/generate_image/utils/image_processing.py b/app/service/generate_image/utils/image_processing.py index 3530a08..c2910ee 100644 --- a/app/service/generate_image/utils/image_processing.py +++ b/app/service/generate_image/utils/image_processing.py @@ -263,6 +263,12 @@ def face_detect_pic(image): # 3、检测人脸(用灰度图检测,返回人脸矩形坐标(4个角)) faces_rect = face_detector.detectMultiScale(gray, 1.05, 3) + if DEBUG: + dst = image.copy() + for x, y, w, h in faces_rect: + cv2.rectangle(dst, (x, y), (x + w, y + h), (0, 0, 255), 3) # 画出矩形框 + cv2.imshow("", dst) + cv2.waitKey(0) return len(faces_rect)