diff --git a/chapter11/animals_ann.py b/chapter11/animals_ann.py index 917bdd4..90c9dec 100755 --- a/chapter11/animals_ann.py +++ b/chapter11/animals_ann.py @@ -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] diff --git a/chapter11/hand-gesture-recognition/detect_gesture.py b/chapter11/hand-gesture-recognition/detect_gesture.py index f7e0973..e6d42bd 100644 --- a/chapter11/hand-gesture-recognition/detect_gesture.py +++ b/chapter11/hand-gesture-recognition/detect_gesture.py @@ -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 diff --git a/chapter11/hand-gesture-recognition/landmark_utils/utils.py b/chapter11/hand-gesture-recognition/landmark_utils/utils.py index ccc8d20..2a49aab 100644 --- a/chapter11/hand-gesture-recognition/landmark_utils/utils.py +++ b/chapter11/hand-gesture-recognition/landmark_utils/utils.py @@ -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]) diff --git a/chapter11/hand-gesture-recognition/train.py b/chapter11/hand-gesture-recognition/train.py index 333a621..62d49f8 100644 --- a/chapter11/hand-gesture-recognition/train.py +++ b/chapter11/hand-gesture-recognition/train.py @@ -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 diff --git a/chapter12/tests/unit/test_handler.py b/chapter12/tests/unit/test_handler.py index ab6d6a0..b11a047 100644 --- a/chapter12/tests/unit/test_handler.py +++ b/chapter12/tests/unit/test_handler.py @@ -1,5 +1,6 @@ import json +import numpy as np import pytest from hello_world import app @@ -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", @@ -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