Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added required libraries and altered camera_selector python file #728

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions afy/camera_selector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import cv2
import numpy as np
import yaml
import os

from afy.utils import log


g_selected_cam = None


Expand Down Expand Up @@ -43,8 +43,10 @@ def make_grid(images, cell_size=(320, 240), cols=2):
grid = np.zeros((h0 * _rows, w0 * _cols, 3), dtype=np.uint8)
for i, (camid, img) in enumerate(images.items()):
img = cv2.resize(img, (w0, h0))

# add rect
img = cv2.rectangle(img, (1, 1), (w0 - 1, h0 - 1), (0, 0, 255), 2)

# add id
img = cv2.putText(img, f'Camera {camid}', (10, 30), 0, 1, (0, 255, 0), 2)
c = i % cols
Expand Down Expand Up @@ -85,7 +87,7 @@ def select_camera(cam_frames, window="Camera selector"):

if g_selected_cam is not None:
break

if key == 27:
break

Expand All @@ -98,14 +100,17 @@ def select_camera(cam_frames, window="Camera selector"):


if __name__ == '__main__':
with open('config.yaml', 'r') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
parent_dir = os.path.basename(os.path.dirname(os.getcwd()))
file_location = ['Desktop', 'Downloads', 'Documents', parent_dir, '', 'Programs']
for loc in file_location:
yml_file_path = os.path.join(os.path.expanduser('~'), loc, 'config.yaml')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're still effectively only looking in the user's home folder, it needs to work regardless of where they have downloaded it. Joining parent_dir with the home folder also doesn't make much sense, but maybe this is a bug and you intended to do something else? I'm not quite sure if it's logical that someone would have "~/Downloads/config.yaml" while the actual application is somewhere else.

if os.path.exists(yml_file_path):
with open(yml_file_path, "r") as f:
config = yaml.load(f, Loader=yaml.FullLoader)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be a good idea to check that a config was loaded, and print a helpful error message if it wasn't found in any of the locations. Since the new code doesn't fail when it can't find the config file, it would probably lead to a more cryptic error later.

cam_frames = query_cameras(config['query_n_cams'])

if cam_frames:
selected_cam = select_camera(cam_frames)
print(f"Selected camera {selected_cam}")
else:
log("No cameras are available")

4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ pyzmq==20.0.0
msgpack-numpy==0.4.7.1
pyyaml==5.4
requests==2.32.0
pyfakewebcam==0.1.0
pyfakewebcam==0.1.0
scipy==1.13.1
torch==2.3.0