(cam_frames, window="Camera selector")
| 65 | |
| 66 | |
| 67 | def select_camera(cam_frames, window="Camera selector"): |
| 68 | cell_size = 320, 240 |
| 69 | grid_cols = 2 |
| 70 | grid = make_grid(cam_frames, cols=grid_cols) |
| 71 | |
| 72 | # to fit the text if only one cam available |
| 73 | if grid.shape[1] == 320: |
| 74 | cell_size = 640, 480 |
| 75 | grid = cv2.resize(grid, cell_size) |
| 76 | |
| 77 | cv2.putText(grid, f'Click on the web camera to use', (10, grid.shape[0] - 30), 0, 0.7, (200, 200, 200), 2) |
| 78 | |
| 79 | cv2.namedWindow(window) |
| 80 | cv2.setMouseCallback(window, mouse_callback, (cell_size, grid_cols, cam_frames)) |
| 81 | cv2.imshow(window, grid) |
| 82 | |
| 83 | while True: |
| 84 | key = cv2.waitKey(10) |
| 85 | |
| 86 | if g_selected_cam is not None: |
| 87 | break |
| 88 | |
| 89 | if key == 27: |
| 90 | break |
| 91 | |
| 92 | cv2.destroyAllWindows() |
| 93 | |
| 94 | if g_selected_cam is not None: |
| 95 | return list(cam_frames)[g_selected_cam] |
| 96 | else: |
| 97 | return list(cam_frames)[0] |
| 98 | |
| 99 | |
| 100 | if __name__ == '__main__': |
no test coverage detected