microsoft/ProjectOxford-ClientSDK

a error "Image is too small" occurs when detect face

qinyuanpei opened this issue · 8 comments

OK, there is a error "Image is too small" occurs when I try to detect face in image to upload
Here are results returned by API:

{
    u'error': 
    {
        u'message': u'Image size is too small.', 
        u'code': u'InvalidImageSize'
    }
}

Actually, all width and height of these images are more than 640px.
These images can be handled when I upload them into your website, so I am so confused about this result. I write Python script as following:

#!/usr/bin/python
#-*- coding: utf-8 -*-

import json
import requests

class FaceAPI:

    def __init__(self,secretKey):
        self.baseUrl = 'https://westcentralus.api.cognitive.microsoft.com'
        self.secretKey = secretKey

    def detectFace(self,image):
        # Request headers.
        headers = {
            'Content-Type': 'application/octet-stream',
            'Ocp-Apim-Subscription-Key': self.secretKey,
        }

        # Request parameters.
        params = {
            'returnFaceId': 'true',
            'returnFaceLandmarks': 'false',
            'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
        }

        # Body. The URL of a JPEG image to analyze.
        imgData = open(image).read()

        # Call REST API
        try:
            response = requests.post(
                self.baseUrl + '/face/v1.0/detect',
                json = None,
                data = imgData,
                headers = headers,
                params = params
            )

            if(response.status_code == '200'):
                data = json.loads(response.text)
                return (True,data)
            else:
                data = json.loads(response.text)
                return (False,data)
        except Exception as e:
            return (False, e.message)

So can you help me to resolve this issue? Thanks you.

Hi qinyuanpei, I'm facing the same issue right now.
Did you manage to find a fix?

I submit this issue at last year, but I can't solve it yet. 😃

Ah okay, i'll just try a manual api call. thanks

I am facing the same issue is there any fix to this problem yet
does manual call worked ?? @fatahfattah

@chetanyachopra Yes manual implementations work, can't recall what the issue was. I'd suggest to do all the calls manually though, not just this one.

Just wondering, if there have been any updates for this issue.

@chetanyachopra @fatahfattah @qinyuanpei @fadyanwar Is there any ways of resolving this issue?

I see there is no solution here yet but want to share how we fix this on our side:

We used to detect the face and then creating a person within a group right after detection. For these both operations we were using the same MemoryStream object so when I check the MemoryStream object right before the second operation I saw that the position of the stream was the end of the size. I just set the position to 0 again so everything started to work fine.

Be cautious when we try to use the same MemoryStream object multiple times. At first usage, the position is 0 but for the next usages the position will be the end file and you need to set it to 0 again to be able to use.