0

问候,我一直在尝试从面部提取一些区域在这种情况下(上唇)使用 Dlib,事情是在提取 ROI 之后(看起来很完美)我意识到 ROI 周围有一些噪音无法弄清楚我做错了什么,以及如何解决这个问题。这是使用的 Python 代码:

import cv2
import numpy as np
import dlib
import os 
from scipy import ndimage, misc
import time

def extract_index_nparray(nparray):
    index = None
    for num in nparray[0]:
        index = num
        break
    return index
img = cv2.imread( 'input_facial_image.jpg')
img=cv2.resize(img,(512,512))
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
mask = np.zeros_like(img_gray)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("/facial-landmarks-recognition/shape_predictor_68_face_landmarks.dat")
# Face 1
faces = detector(img_gray)
for face in faces:
    landmarks = predictor(img_gray, face)
    landmarks_points = []
    for n in [48,49,50,51,52,53,54,64,63,62,61,60]:
        x = landmarks.part(n).x
        y = landmarks.part(n).y
        landmarks_points.append((x, y))
   points = np.array(landmarks_points, np.int32)
   convexhull = cv2.convexHull(points)
   # cv2.polylines(img, [convexhull], True, (255, 0, 0), 3)
   cv2.fillConvexPoly(mask, convexhull, 255)

   face_image_1 = cv2.bitwise_or(img, img, mask=mask)
   cv2.imwrite('extracted_lips.jpg', face_image_1 )

提取的图像如下所示: 上唇提取图像 但是在我的工作的进一步步骤中,我意识到上唇周围有噪音,所以我检查并发现unclean_upperlip 有没有办法在 ROI 提取期间消除噪音或有什么图像处理技术可以绕过这个问题吗?提前致谢

4

1 回答 1

0

对于和我遇到同样问题的人来说,这很简单。只需将输出格式更改为png. JPG压缩是这里的问题。我希望这个对你有用

于 2021-12-09T10:52:31.840 回答