MCPcopy Create free account
hub / github.com/asottile/nintendo-microcontrollers / cb

Function cb

scripts/debug_screen.py:31–60  ·  view source on GitHub ↗
(event: int, x: int, y: int, flags: object, param: object)

Source from the content-addressed store, hash-verified

29 start: Point | None = None
30
31 def cb(event: int, x: int, y: int, flags: object, param: object) -> None:
32 nonlocal start, pos
33
34 if event == cv2.EVENT_MOUSEMOVE:
35 pos = Point(y=y, x=x)
36 elif event == cv2.EVENT_LBUTTONDOWN:
37 start = Point(y=y, x=x)
38 elif event == cv2.EVENT_LBUTTONUP:
39 assert start is not None
40 start = start.denorm(frame.shape)
41 end = Point(y=y, x=x).denorm(frame.shape)
42
43 current = getframe()
44 if start == end:
45 as_ints = [int(p) for p in current[y][x]]
46 print(f'match_px({end}, {Color(*as_ints)})')
47 arr = numpy.array([[current[y][x]]])
48 print(f'hsv: {cv2.cvtColor(arr, cv2.COLOR_BGR2HSV)}')
49 else:
50 start, end = min(start, end), max(start, end)
51 for invert in (True, False):
52 text = get_text(current, start, end, invert=invert)
53 print('match_text(')
54 print(f' {text!r},')
55 print(f' {start},')
56 print(f' {end},')
57 print(f' invert={invert},')
58 print(')')
59
60 start = None
61
62 cv2.namedWindow('game2')
63 cv2.setMouseCallback('game2', cb)

Callers

nothing calls this directly

Calls 5

denormMethod · 0.95
PointClass · 0.90
ColorClass · 0.90
get_textFunction · 0.90
getframeFunction · 0.70

Tested by

no test coverage detected