【发布时间】:2019-10-09 00:36:57
【问题描述】:
起始数据:二维数组 (620x480) 包含图像,其中显示人脸,二维数组 (30x20) 包含眼睛图像。人脸图像包括眼睛图像。
如何将眼睛图像扩展到 36x60 以包含面部图像的像素?有现成的解决方案吗?
另一个类似的任务:眼睛图像的大小为 37x27。如何将眼睛图像扩展到目标(最接近 36x60)尺寸,例如39x65,即在调整大小之前保持所需的纵横比,然后调整为 36x60。
测试代码(项目由reference提供):
import dlib
import cv2 as cv
from imutils.face_utils import shape_to_np
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('res/model.dat')
frame = cv.imread('photo.jpg')
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
img = frame.copy()
dets = detector(gray, 0)
for i, det in enumerate(dets):
shape = shape_to_np(predictor(gray, det))
shape_left_eye = shape[36:42]
x, y, h, w = cv.boundingRect(shape_left_eye)
cv.rectangle(img, (x, y), (x + h, y + w), (0, 255, 0), 1)
cv.imwrite('file.png', frame[y: y+w, x: x+h])
【问题讨论】:
-
你能添加一些图片来更详细地解释你想要什么吗?就目前而言,这有点令人困惑。
-
@TheChubbyPanda 进行测试,您必须安装 opencv 和 dlib 库,并从 github.com/davisking/dlib-models/blob/master/… 下载经过训练的 dlib 模型
-
@TheChubbyPanda 测试项目yadi.sk/d/Gg-NlNc-yM959Q
标签: arrays python-3.x numpy opencv