Skip to content

Commit

Permalink
Merge pull request #24 from robmarkcole/add-get_vehicles
Browse files Browse the repository at this point in the history
Add get vehicles
  • Loading branch information
robmarkcole authored Dec 29, 2020
2 parents bdef9f8 + 8985e77 commit 18c78dc
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 302 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "0.5"
VERSION = "0.6"

REQUIRES = ["requests"]

Expand Down
32 changes: 32 additions & 0 deletions simplehound/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,38 @@ def get_license_plates(recognitions: Dict) -> List[Dict]:
return plates


def get_vehicles(detections: Dict) -> List[Dict]:
"""
Get the list of the vehicles.
"""
vehicles = []
for obj in detections["objects"]:
if not obj["objectType"] == "vehicle":
continue
vehicle = {}
vehicle["boundingBox"] = obj["vehicleAnnotation"]["bounding"]
vehicle["recognitionConfidence"] = obj["vehicleAnnotation"][
"recognitionConfidence"
]
attributes = obj["vehicleAnnotation"]["attributes"]["system"]
vehicle["vehicleType"] = attributes["vehicleType"]
vehicle["make"] = attributes["make"]["name"]
vehicle["model"] = attributes["model"]["name"]
vehicle["color"] = attributes["color"]["name"]
if "licenseplate" in obj["vehicleAnnotation"]:
vehicle["licenseplate"] = obj["vehicleAnnotation"]["licenseplate"][
"attributes"
]["system"]["string"]["name"]
vehicle["region"] = obj["vehicleAnnotation"]["licenseplate"]["attributes"][
"system"
]["region"]["name"]
else:
vehicle["licenseplate"] = "unknown"
vehicle["region"] = "unknown"
vehicles.append(vehicle)
return vehicles


def _sighthound_call(image_encoded: str, api_key: str, url: str, params=()) -> Dict:
headers = {"Content-type": "application/json", "X-Access-Token": api_key}
response = requests.post(
Expand Down
214 changes: 214 additions & 0 deletions tests/test_simplehound.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,175 @@
"requestId": "467f195c4bbf46c69f964b59884dee04",
}

RECOGNITIONS_VEHICLES = {
"image": {"width": 1080, "height": 675, "orientation": 1},
"requestId": "7b09bdf1547441c78fcd336ac1b78077",
"objects": [
{
"objectId": "_vehicle_c3b12324-1f19-4606-90c6-39c25c8c39fb",
"vehicleAnnotation": {
"bounding": {
"vertices": [
{"x": 289, "y": 150},
{"x": 1036, "y": 150},
{"x": 1036, "y": 602},
{"x": 289, "y": 602},
]
},
"recognitionConfidence": 0.8554,
"attributes": {
"system": {
"make": {"name": "Ford", "confidence": 0.8554},
"model": {"name": "Ranger", "confidence": 0.8554},
"color": {"name": "black", "confidence": 0.9988},
"vehicleType": "car",
}
},
},
"objectType": "vehicle",
}
],
}

RECOGNITIONS_ALL = {
"image": {"width": 1080, "height": 675, "orientation": 1},
"requestId": "a14d1d7e426a429d960fa100d2351cdb",
"objects": [
{
"objectId": "_vehicle_c3b12324-1f19-4606-90c6-39c25c8c39fb",
"vehicleAnnotation": {
"bounding": {
"vertices": [
{"x": 289, "y": 150},
{"x": 1036, "y": 150},
{"x": 1036, "y": 602},
{"x": 289, "y": 602},
]
},
"recognitionConfidence": 0.8554,
"licenseplate": {
"bounding": {
"vertices": [
{"x": 755, "y": 377},
{"x": 914, "y": 377},
{"x": 914, "y": 419},
{"x": 755, "y": 419},
]
},
"attributes": {
"system": {
"string": {"name": "CV67CBU", "confidence": 0.4044},
"characters": [
{
"bounding": {
"vertices": [
{"y": 385, "x": 778},
{"y": 385, "x": 794},
{"y": 413, "x": 794},
{"y": 413, "x": 778},
]
},
"index": 0,
"confidence": 0.9797,
"character": "C",
},
{
"bounding": {
"vertices": [
{"y": 384, "x": 796},
{"y": 384, "x": 812},
{"y": 412, "x": 812},
{"y": 412, "x": 796},
]
},
"index": 1,
"confidence": 0.985,
"character": "V",
},
{
"bounding": {
"vertices": [
{"y": 384, "x": 812},
{"y": 384, "x": 829},
{"y": 412, "x": 829},
{"y": 412, "x": 812},
]
},
"index": 2,
"confidence": 0.4732,
"character": "6",
},
{
"bounding": {
"vertices": [
{"y": 383, "x": 830},
{"y": 383, "x": 846},
{"y": 411, "x": 846},
{"y": 411, "x": 830},
]
},
"index": 3,
"confidence": 0.9895,
"character": "7",
},
{
"bounding": {
"vertices": [
{"y": 383, "x": 853},
{"y": 383, "x": 869},
{"y": 411, "x": 869},
{"y": 411, "x": 853},
]
},
"index": 4,
"confidence": 0.998,
"character": "C",
},
{
"bounding": {
"vertices": [
{"y": 382, "x": 869},
{"y": 382, "x": 886},
{"y": 410, "x": 886},
{"y": 410, "x": 869},
]
},
"index": 5,
"confidence": 0.9933,
"character": "B",
},
{
"bounding": {
"vertices": [
{"y": 381, "x": 887},
{"y": 381, "x": 903},
{"y": 410, "x": 903},
{"y": 410, "x": 887},
]
},
"index": 6,
"confidence": 0.9026,
"character": "U",
},
],
"region": {"name": "UK", "confidence": 0.9972},
}
},
},
"attributes": {
"system": {
"make": {"name": "Ford", "confidence": 0.8554},
"model": {"name": "Ranger", "confidence": 0.8554},
"color": {"name": "black", "confidence": 0.9988},
"vehicleType": "car",
}
},
},
"objectType": "vehicle",
}
],
}

## Processed responses
FACES = [
{
Expand Down Expand Up @@ -210,6 +379,46 @@
}
]

VEHICLES_PROCESSED = [
{
"boundingBox": {
"vertices": [
{"x": 289, "y": 150},
{"x": 1036, "y": 150},
{"x": 1036, "y": 602},
{"x": 289, "y": 602},
]
},
"recognitionConfidence": 0.8554,
"vehicleType": "car",
"make": "Ford",
"model": "Ranger",
"color": "black",
"licenseplate": "unknown",
"region": "unknown",
}
]

ALL_PROCESSED = [
{
"boundingBox": {
"vertices": [
{"x": 289, "y": 150},
{"x": 1036, "y": 150},
{"x": 1036, "y": 602},
{"x": 289, "y": 602},
]
},
"recognitionConfidence": 0.8554,
"vehicleType": "car",
"make": "Ford",
"model": "Ranger",
"color": "black",
"licenseplate": "CV67CBU",
"region": "UK",
}
]


def test_bbox_to_tf_style():
bbox = {"x": 227, "y": 133, "height": 245, "width": 125}
Expand Down Expand Up @@ -243,6 +452,11 @@ def test_get_license_plates():
assert hound.get_license_plates(RECOGNITIONS_LICENSEPLATE) == LICENSEPLATE_PROCESSED


def test_get_vehicles():
assert hound.get_vehicles(RECOGNITIONS_VEHICLES) == VEHICLES_PROCESSED
assert hound.get_vehicles(RECOGNITIONS_ALL) == ALL_PROCESSED


def test_get_people():
assert hound.get_people(DETECTIONS) == PEOPLE

Expand Down
366 changes: 65 additions & 301 deletions usage.ipynb

Large diffs are not rendered by default.

0 comments on commit 18c78dc

Please sign in to comment.