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