【发布时间】:2018-10-20 22:22:50
【问题描述】:
我正在尝试在python中裁剪图像,并且在裁剪它们时需要保留exif数据,但是当我保存生成的裁剪图像时丢失了原始图像的exif数据,我该如何避免这种情况发生? 我一直在运行的代码:
from imutils import face_utils
import imutils
import numpy as np
import collections
import dlib
import cv2
import glob
import os
detector = dlib.get_frontal_face_detector()
PREDICTOR_PATH = "shape_predictor_68_face_landmarks.dat"
predictor = dlib.shape_predictor(PREDICTOR_PATH)
def face_remap(shape):
remapped_image = cv2.convexHull(shape)
return remapped_image
def faceCrop(imagePattern):
imgList=glob.glob(imagePattern)
if len(imgList)<=0:
print ('No Images Found')
return
for img in imgList:
image = cv2.imread(img)
image = imutils.resize(image, width=500)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
out_face = np.zeros_like(image)
rects = detector(gray, 1)
for (i, rect) in enumerate(rects):
shape = predictor(gray, rect)
shape = face_utils.shape_to_np(shape)
#initialize mask array
remapped_shape = np.zeros_like(shape)
feature_mask = np.zeros((image.shape[0], image.shape[1]))
# we extract the face
remapped_shape = face_remap(shape)
cv2.fillConvexPoly(feature_mask, remapped_shape[0:27], 1)
feature_mask = feature_mask.astype(np.bool)
out_face[feature_mask] = image[feature_mask]
fname,ext=os.path.splitext(img)
cv2.imwrite(fname+'_crop'+ext, out_face)
print ('Listo \n')
faceCrop('/Users/alejandroramirez/Documents/imagenes nuevas/2/*.JPG')
【问题讨论】:
-
你能告诉我们你到目前为止所做的尝试吗?
-
当然,我上传了问题中的代码
-
OpenCV 帮不了你。查找其他一些可让您读取和写入 EXIF 数据的 python 库。 this 可能是一个很好的起点。
-
谢谢,枕头有用吗?
标签: python opencv image-processing