Skip to content

Fix bugs in chapters 11 and 12#4

Open
techfort wants to merge 1 commit into
mainfrom
ch11-ch12-bugfixes
Open

Fix bugs in chapters 11 and 12#4
techfort wants to merge 1 commit into
mainfrom
ch11-ch12-bugfixes

Conversation

@techfort

@techfort techfort commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • animals_ann.py: randint(3.0, 5.0)randint(3, 5)random.randint requires integer arguments; floats raise TypeError on Python 3.10+
  • landmark_utils/utils.py: passreturn in log_csv() guard — the early-exit condition was a no-op, so the CSV was always written regardless of the key pressed; also fixed double assignment typo (csv_path = csv_path = ...)
  • train.py: Fixed key-to-number translation — cv2.waitKey returns -1 when no key is pressed, so number = receivedKey - 48 produced -49 instead of -1, meaning the "Press key for gesture number" prompt never displayed
  • detect_gesture.py: Color argument to cv2.putText changed from bare 255 to (255, 255, 255) — BGR images require a 3-tuple
  • test_handler.py: Updated test to match the active lambda_handler (returns {"coords": ...}, not {"message": "hello world"}); added mocks for requests.get and cv2.imread; fixed fixture to supply the required url query parameter

Test plan

  • Run python chapter11/animals_ann.py and confirm condor samples generate without TypeError
  • Run python chapter11/hand-gesture-recognition/train.py and confirm "Press key for gesture number" appears on screen when no key is held
  • Confirm gesture labels render visibly in detect_gesture.py output window
  • Run pytest chapter12/tests/ and confirm test_lambda_handler passes

🤖 Generated with Claude Code

- animals_ann.py: pass integers to randint() instead of floats
- landmark_utils/utils.py: return early in log_csv() guard (was pass, so CSV was always written); fix double assignment typo
- train.py: preserve -1 sentinel from waitKey before subtracting 48, so the "no key pressed" branch works correctly
- detect_gesture.py: pass BGR color tuple to putText() instead of bare int
- test_handler.py: update test to match active lambda_handler (returns coords, not message); mock requests.get and cv2.imread; fix fixture to supply url query param

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant