2
我想从谷歌视觉api中挖出脸部的图像。我明白如何从他们的示例代码中获取地标。但我不知道如何使用这些地标来裁剪脸部。有人可以提供一些伪代码或指导我如何进一步感谢。作物地标部分使用谷歌视觉API的脸部
我想从谷歌视觉api中挖出脸部的图像。我明白如何从他们的示例代码中获取地标。但我不知道如何使用这些地标来裁剪脸部。有人可以提供一些伪代码或指导我如何进一步感谢。作物地标部分使用谷歌视觉API的脸部
下面的代码演示如何使用云愿景客户端检索面的顶点的图像中(假设下列文件被称为faces.py
):
import io
import sys
from google.cloud import vision
vision_client = vision.Client()
with io.open(sys.argv[1], 'rb') as image_file:
content = image_file.read()
image = vision_client.image(content=content)
faces = image.detect_faces()
print('Faces:')
for face in faces:
bounds = ''
for bound in face.bounds.vertices:
bounds += ('{' + str(getattr(bound, 'x_coordinate', 0)) + ',' +
str(getattr(bound, 'y_coordinate', 0)) + '}')
print('face bounds: {}'.format(bounds))
你requirements.txt
会看起来像:
google-cloud-vision==0.22.0
您将运行该应用程序为:
virutalenv env && source env/bin/activate
pip install -r requirements.txt
python faces.py image.jpg
输出是:
face bounds: {105,460}{516,460}{516,938}{105,938}
这些将是在那里你会夹到突出面是covered in depth elsewhere。
您正在使用哪种mimetype? Jpeg,PNG,GIF等?你看过图像处理库,如Imagemagick,opencv吗? Java也提供了可能支持裁剪的BufferedImage。但要支持CMYK或Gif等图像,您必须使用ImageMagick/twelvemonkeys等。请提供更多信息。另外,有足够的资源在线完成这样简单的任务。 http://stackoverflow.com/help/how-to-ask – saurabheights