Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

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

Open
qinyuanpei opened this issue Dec 21, 2017 · 8 comments
Open

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

qinyuanpei opened this issue Dec 21, 2017 · 8 comments

Comments

@qinyuanpei
Copy link

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.

@fatahfattah
Copy link

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

@qinyuanpei
Copy link
Author

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

@fatahfattah
Copy link

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

@chetanyachopra22
Copy link

chetanyachopra22 commented May 18, 2018

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

@fatahfattah
Copy link

@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.

@fadyanwar
Copy link

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

@Soorya018
Copy link

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

@sabrimev
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants