mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-12 11:40:34 +08:00
Merge pull request #111 from IndicoDataSolutions/diana-fl
ADD: facial localization api
This commit is contained in:
@@ -19,6 +19,7 @@ from indicoio.text.keywords import keywords
|
||||
from indicoio.text.ner import named_entities
|
||||
from indicoio.images.fer import fer
|
||||
from indicoio.images.features import facial_features
|
||||
from indicoio.images.faciallocalization import facial_localization
|
||||
from indicoio.images.features import image_features
|
||||
from indicoio.images.filtering import content_filtering
|
||||
from indicoio.utils.multi import predict_image, predict_text
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import requests
|
||||
|
||||
from indicoio.utils.image import image_preprocess
|
||||
from indicoio.utils.api import api_handler
|
||||
|
||||
|
||||
def facial_localization(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
"""
|
||||
Given an image, returns a list of faces found within the image.
|
||||
For each face, we return a dictionary containing the upper left corner and lower right corner.
|
||||
If crop is True, the cropped face is included in the dictionary.
|
||||
Input should be in a numpy ndarray or a filename.
|
||||
|
||||
Example usage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> from indicoio import facial_localization
|
||||
>>> import numpy as np
|
||||
>>> img = np.zeros([image of a face])
|
||||
>>> faces = facial_localization(img)
|
||||
>>> len(faces)
|
||||
1
|
||||
|
||||
:param image: The image to be analyzed.
|
||||
:type image: filepath or ndarray
|
||||
:rtype: List of faces (dict) found.
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch)
|
||||
url_params = {"batch": batch, "api_key": api_key}
|
||||
return api_handler(image, cloud=cloud, api="faciallocalization", url_params=url_params, **kwargs)
|
||||
@@ -16,7 +16,7 @@ def facial_features(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
|
||||
>>> from indicoio import facial_features
|
||||
>>> import numpy as np
|
||||
>>> face = np.zeros((48,48)).tolist()
|
||||
>>> face = np.zeros((48,48))
|
||||
>>> features = facial_features(face)
|
||||
>>> len(features)
|
||||
48
|
||||
@@ -25,7 +25,7 @@ def facial_features(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:type image: list of lists
|
||||
:rtype: List containing feature responses
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch)
|
||||
image = image_preprocess(image, batch=batch, size=(48,48))
|
||||
url_params = {"batch": batch, "api_key": api_key}
|
||||
return api_handler(image, cloud=cloud, api="facialfeatures", url_params=url_params, **kwargs)
|
||||
|
||||
|
||||
@@ -24,6 +24,6 @@ def content_filtering(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:type image: list of lists
|
||||
:rtype: float of nsfwness
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch, size=None, min_axis=128)
|
||||
image = image_preprocess(image, batch=batch, min_axis=128)
|
||||
url_params = {"batch": batch, "api_key": api_key}
|
||||
return api_handler(image, cloud=cloud, api="contentfiltering", url_params=url_params, **kwargs)
|
||||
|
||||
@@ -10,7 +10,7 @@ from indicoio.utils.errors import IndicoError, DataStructureException
|
||||
|
||||
B64_PATTERN = re.compile("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)")
|
||||
|
||||
def image_preprocess(image, size=(48,48), min_axis=None, batch=False):
|
||||
def image_preprocess(image, size=None, min_axis=None, batch=False):
|
||||
"""
|
||||
Takes an image and prepares it for sending to the api including
|
||||
resizing and image data/structure standardizing.
|
||||
|
||||
Reference in New Issue
Block a user