Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chapter11/animals_ann.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def dog_class():
return [1, 0, 0, 0]

def condor_sample():
return [uniform(3.0, 10.0), randint(3.0, 5.0), 0]
return [uniform(3.0, 10.0), randint(3, 5), 0]

def condor_class():
return [0, 1, 0, 0]
Expand Down
2 changes: 1 addition & 1 deletion chapter11/hand-gesture-recognition/detect_gesture.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# Flip the image horizontally for a selfie-view display.
final = cv2.flip(image, 1)
cv2.putText(final, gestures[gesture_index],
(10, 30), cv2.FONT_HERSHEY_DUPLEX, 1, 255)
(10, 30), cv2.FONT_HERSHEY_DUPLEX, 1, (255, 255, 255))
cv2.imshow('MediaPipe Hands', final)
if cv2.waitKey(5) & 0xFF == 27:
break
Expand Down
4 changes: 2 additions & 2 deletions chapter11/hand-gesture-recognition/landmark_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def calc_bounding_rect(image, landmarks):

def log_csv(number, landmark_list):
if number > 9 or number == -1:
pass
csv_path = csv_path = 'model/keypoint_classifier/keypoint.csv'
return
csv_path = 'model/keypoint_classifier/keypoint.csv'
with open(csv_path, 'a', newline="") as f:
writer = csv.writer(f)
writer.writerow([number, *landmark_list])
Expand Down
2 changes: 1 addition & 1 deletion chapter11/hand-gesture-recognition/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
# If loading a video, use 'break' instead of 'continue'.
continue
receivedKey = cv2.waitKey(20)
number = receivedKey - 48
number = (receivedKey - 48) if receivedKey != -1 else -1
# To improve performance, optionally mark the image as not writeable to
# pass by reference.
image.flags.writeable = False
Expand Down
10 changes: 7 additions & 3 deletions chapter12/tests/unit/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

import numpy as np
import pytest

from hello_world import app
Expand Down Expand Up @@ -34,7 +35,7 @@ def apigw_event():
},
"stage": "prod",
},
"queryStringParameters": {"foo": "bar"},
"queryStringParameters": {"url": "https://example.com/test.jpg"},
"headers": {
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
"Accept-Language": "en-US,en;q=0.8",
Expand Down Expand Up @@ -63,10 +64,13 @@ def apigw_event():


def test_lambda_handler(apigw_event, mocker):
mock_response = mocker.MagicMock()
mock_response.content = b""
mocker.patch("hello_world.app.requests.get", return_value=mock_response)
mocker.patch("hello_world.app.cv2.imread", return_value=np.zeros((100, 100, 3), dtype=np.uint8))

ret = app.lambda_handler(apigw_event, "")
data = json.loads(ret["body"])

assert ret["statusCode"] == 200
assert "message" in ret["body"]
assert data["message"] == "hello world"
assert "coords" in data