GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add vision label detection by daspecster · Pull Request #2237 · googleapis/google-cloud-python

Add vision label detection #2237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
daspecster merged 1 commit into googleapis:master from daspecster:vision-label-detection
Sep 15, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

Add vision label detection #2237

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
408f929
Add Vision label detection.
daspecster Sep 12, 2016
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 google/cloud/vision/entity.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def from_api_repr(cls, response):
:rtype: :class:`~google.cloud.vision.entiy.EntityAnnotation`
:returns: Instance of ``EntityAnnotation``.
"""
bounds = Bounds.from_api_repr(response['boundingPoly'])
bounds = Bounds.from_api_repr(response.get('boundingPoly'))
description = response['description']
locations = [LocationInformation.from_api_repr(location)
for location in response.get('locations', [])]
Expand Down
13 changes: 7 additions & 6 deletions 13 google/cloud/vision/geometry.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ def from_api_repr(cls, response_vertices):
:type response_vertices: dict
:param response_vertices: List of vertices.

:rtype: :class:`~google.cloud.vision.geometry.BoundsBase`
:returns: Instance of BoundsBase with populated verticies.
:rtype: :class:`~google.cloud.vision.geometry.BoundsBase` or None
:returns: Instance of BoundsBase with populated verticies or None.
"""
vertices = []
for vertex in response_vertices['vertices']:
vertices.append(Vertex(vertex.get('x', None),
vertex.get('y', None)))
if not response_vertices:
return None

vertices = [Vertex(vertex.get('x', None), vertex.get('y', None)) for
vertex in response_vertices.get('vertices', [])]
Comment thread

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

return cls(vertices)

@property
Expand Down
13 changes: 13 additions & 0 deletions 13 google/cloud/vision/image.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def _detect_annotation(self, feature):
:class:`~google.cloud.vision.entity.EntityAnnotation`.
"""
reverse_types = {
'LABEL_DETECTION': 'labelAnnotations',
'LANDMARK_DETECTION': 'landmarkAnnotations',
'LOGO_DETECTION': 'logoAnnotations',
}
Expand Down Expand Up @@ -122,6 +123,18 @@ def detect_faces(self, limit=10):

return faces

def detect_labels(self, limit=10):
"""Detect labels that describe objects in an image.

:type limit: int
:param limit: The maximum number of labels to try and detect.

:rtype: list
:returns: List of :class:`~google.cloud.vision.entity.EntityAnnotation`
"""
feature = Feature(FeatureTypes.LABEL_DETECTION, limit)
return self._detect_annotation(feature)

def detect_landmarks(self, limit=10):
"""Detect landmarks in an image.

Expand Down
25 changes: 25 additions & 0 deletions 25 unit_tests/vision/_fixtures.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
LABEL_DETECTION_RESPONSE = {
'responses': [
{
'labelAnnotations': [
{
'mid': '/m/0k4j',
'description': 'automobile',
'score': 0.9776855
},
{
'mid': '/m/07yv9',
'description': 'vehicle',
'score': 0.947987
},
{
'mid': '/m/07r04',
'description': 'truck',
'score': 0.88429511
}
]
}
]
}


LANDMARK_DETECTION_RESPONSE = {
'responses': [
{
Expand Down
21 changes: 21 additions & 0 deletions 21 unit_tests/vision/test_client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ def test_face_detection_from_content(self):
image_request['image']['content'])
self.assertEqual(5, image_request['features'][0]['maxResults'])

def test_label_detection_from_source(self):
from google.cloud.vision.entity import EntityAnnotation
from unit_tests.vision._fixtures import (LABEL_DETECTION_RESPONSE as
RETURNED)
credentials = _Credentials()
client = self._makeOne(project=self.PROJECT, credentials=credentials)
client.connection = _Connection(RETURNED)

image = client.image(source_uri=_IMAGE_SOURCE)
labels = image.detect_labels(limit=3)
self.assertEqual(3, len(labels))
self.assertTrue(isinstance(labels[0], EntityAnnotation))
image_request = client.connection._requested[0]['data']['requests'][0]
self.assertEqual(_IMAGE_SOURCE,
image_request['image']['source']['gcs_image_uri'])
self.assertEqual(3, image_request['features'][0]['maxResults'])
self.assertEqual('automobile', labels[0].description)
self.assertEqual('vehicle', labels[1].description)
self.assertEqual('/m/0k4j', labels[0].mid)
self.assertEqual('/m/07yv9', labels[1].mid)

def test_landmark_detection_from_source(self):
from google.cloud.vision.entity import EntityAnnotation
from unit_tests.vision._fixtures import (LANDMARK_DETECTION_RESPONSE as
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.