Example #1
0
    def test_detect_base64(self):
        """
        API-Rest URL /estimation-requests/gender/face/base64 works for base64 requests.
        """

        image = Image("main/samples/image1.jpg")

        # Black and white
        image.load_from_uri(as_gray=True)

        jpeg_b64_content = base64.b64encode(image.get_jpeg())
        response = self.send_request(jpeg_b64_content, "base64", {})
        self.assertEqual(len(response), 1)
        self.assertIn("Gender", response)

        # Color
        image.load_from_uri(as_gray=False)

        jpeg_b64_content = base64.b64encode(image.get_jpeg())
        response = self.send_request(jpeg_b64_content, "base64", {})
        self.assertEqual(len(response), 1)
        self.assertIn("Gender", response)

        jpeg_b64_content = base64.b64encode(
            b'asdasd1io23u897das0dasdoasijdoasidja')
        response = self.send_request(jpeg_b64_content, "base64", {})
        self.assertEqual(
            response, {
                'message':
                "Content of file not valid: Resource was empty. "
                "Couldn't perform the analysis on an empty resource."
            })
Example #2
0
    def test_detect_stream(self):
        """
        API-Rest URL /estimation-requests/gender/face/stream works for stream requests.
        """

        image = Image("main/samples/example_image.jpg")

        # Grayscale
        image.load_from_uri(as_gray=True)

        jpeg_content = image.get_jpeg()
        response = self.send_request(jpeg_content, "stream", {})
        self.assertEqual(len(response), 1)
        self.assertIn("Gender", response)

        # Color
        image.load_from_uri(as_gray=False)

        jpeg_content = image.get_jpeg()
        response = self.send_request(jpeg_content, "stream", {})
        self.assertEqual(len(response), 1)
        self.assertIn("Gender", response)

        jpeg_content = b'asdasd1io23u897das0dasdoasijdoasidja'
        response = self.send_request(jpeg_content, "stream", {})
        self.assertEqual(
            response, {
                'message':
                "Content of file not valid: Resource was empty. "
                "Couldn't perform the analysis on an empty resource."
            })
Example #3
0
    def test_detect_stream_service_parameter(self):
        """
        STREAM can work with default and different services.
        :return:
        """

        image = Image("main/samples/example_image.jpg")
        image.load_from_uri(as_gray=True)

        jpeg_content = image.get_jpeg()
        response = self.send_request(
            jpeg_content, "stream",
            {"service": "caffe-cnn-levi-hassner-gender-estimation"})

        response2 = self.send_request(jpeg_content, "stream", {})

        response3 = self.send_request(jpeg_content, "stream",
                                      {"service": "default"})

        response4 = self.send_request(jpeg_content, "stream",
                                      {"service": "INVALID SERVICE TEST"})

        self.assertEqual(len(response), 1)
        self.assertEqual(len(response2), 1)
        self.assertEqual(len(response3), 1)
        self.assertEqual(len(response4), 1)
        self.assertIn("Gender", response)
        self.assertIn("Gender", response2)
        self.assertIn("Gender", response3)

        self.assertEqual(set(response), set(response2))
        self.assertEqual(set(response2), set(response3))
        self.assertEqual(
            response4,
            {'message': "Service name 'INVALID SERVICE TEST' not valid."})
Example #4
0
    def test_detect_base64(self):
        """
        API-Rest URL /ensemble-requests/faces/detection-estimation-age-gender/base64 works for base64 requests.
        """

        image = Image("main/samples/image1.jpg")
        image.load_from_uri(as_gray=True)

        jpeg_b64_content = base64.b64encode(image.get_jpeg())
        response = self.send_request(jpeg_b64_content, "base64", {})

        self.assertEqual(len(response), 3)
        ids = []

        for face_index, content in response.items():
            self.assertIn('Bounding_box', content)
            self.assertIn('Gender', content)
            self.assertIn('Age_range', content)
            self.assertIn('Face_ID', content)
            self.assertNotIn(face_index, ids)
            ids.append(int(face_index))
Example #5
0
    def test_detect_stream_without_gender(self):
        """
        Face-ensemble API-Rest works when requested without gender.
        """

        image = Image("main/samples/image1.jpg")
        image.load_from_uri(as_gray=True)

        jpeg_content = image.get_jpeg()
        response = self.send_request(jpeg_content, "stream",
                                     {"service_gender": "none"})

        self.assertEqual(len(response), 3)
        ids = []

        for face_index, content in response.items():
            self.assertIn('Bounding_box', content)
            self.assertNotIn('Gender', content)
            self.assertIn('Age_range', content)
            self.assertIn('Face_ID', content)
            self.assertNotIn(face_index, ids)
            ids.append(int(face_index))