-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
anirudh-hegde
wants to merge
5
commits into
alievk:master
Choose a base branch
from
anirudh-hegde:aviator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a47a09d
added required libraries and altered camera_selector python file
anirudh-hegde c061812
configured file's path
anirudh-hegde 96574e1
added location to load the file from each location
anirudh-hegde 94543e5
added Desktop location
anirudh-hegde 2ea1d20
added Programs location
anirudh-hegde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
@@ -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 | ||
|
@@ -85,7 +87,7 @@ def select_camera(cam_frames, window="Camera selector"): | |
|
||
if g_selected_cam is not None: | ||
break | ||
|
||
if key == 27: | ||
break | ||
|
||
|
@@ -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') | ||
if os.path.exists(yml_file_path): | ||
with open(yml_file_path, "r") as f: | ||
config = yaml.load(f, Loader=yaml.FullLoader) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.