MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / transparent_layout

Function transparent_layout

computer-vision/virtual_keyboard.py:45–77  ·  view source on GitHub ↗
(img, buttonList)

Source from the content-addressed store, hash-verified

43
44
45def transparent_layout(img, buttonList):
46 imgNew = np.zeros_like(img, np.uint8)
47 for button in buttonList:
48 x, y = button.pos
49 cvzone.cornerRect(
50 imgNew,
51 (button.pos[0], button.pos[1], button.size[0], button.size[0]),
52 20,
53 rt=0,
54 )
55 cv2.rectangle(
56 imgNew,
57 button.pos,
58 (x + button.size[0], y + button.size[1]),
59 (255, 144, 30),
60 cv2.FILLED,
61 )
62 cv2.putText(
63 imgNew,
64 button.text,
65 (x + 20, y + 65),
66 cv2.FONT_HERSHEY_PLAIN,
67 4,
68 (0, 0, 0),
69 4,
70 )
71
72 out = img.copy()
73 alpaha = 0.5
74 mask = imgNew.astype(bool)
75 print(mask.shape)
76 out[mask] = cv2.addWeighted(img, alpaha, imgNew, 1 - alpaha, 0)[mask]
77 return out
78
79
80class Button:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected