-
Notifications
You must be signed in to change notification settings - Fork 12
Add subt/tools/locimg.py - tool for image extraction for given location #879
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
Draft
m3d
wants to merge
2
commits into
master
Choose a base branch
from
feature/tool-locimg
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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """ | ||
| Extract log images observing given location | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from osgar.logger import LogReader, lookup_stream_names | ||
| from osgar.lib.serialize import deserialize | ||
| from subt.trace import distance3D | ||
|
|
||
|
|
||
| POSE3D_STREAM = 'fromrospy.pose3d' | ||
|
|
||
|
|
||
| def locimg(logfile, loc, out_dir, stream_name, radius): | ||
| print(loc) | ||
| names = lookup_stream_names(logfile) | ||
| assert POSE3D_STREAM in names, (POSE3D_STREAM, names) | ||
| assert stream_name in names, (stream_name, names) | ||
| pose_id = names.index(POSE3D_STREAM) + 1 | ||
| camera_id = names.index(stream_name) + 1 | ||
|
|
||
| stream_ids = [pose_id, camera_id] | ||
| img_count = 0 | ||
| selected = 0 | ||
| last_pose3d = None | ||
| for dt, channel, data in LogReader(logfile, only_stream_id=stream_ids): | ||
| data = deserialize(data) | ||
| if channel == pose_id: | ||
| last_pose3d = data | ||
| elif channel == camera_id: | ||
| if last_pose3d is not None and distance3D(last_pose3d[0], loc) < radius: | ||
| selected += 1 | ||
| if out_dir is not None: | ||
| with open(os.path.join(out_dir, 'image_%04d.jpg' % img_count), 'wb') as f: | ||
| f.write(data) | ||
| img_count += 1 | ||
| print(f'Images {selected}/{img_count}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument('logfile', help='recorded log file') | ||
| parser.add_argument('--out-dir', help='where tu dump relevant images') | ||
|
Collaborator
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. s/tu/to |
||
| parser.add_argument('--stream', help='image source', default='logimage.image') | ||
| parser.add_argument('--loc', help='xyz position', nargs=3, type=float, required=True) | ||
| parser.add_argument('-r', '--radius', help='sphere radius of interest', type=float, default=5.0) | ||
| args = parser.parse_args() | ||
|
|
||
| locimg(args.logfile, args.loc, args.out_dir, args.stream, radius=args.radius) | ||
|
|
||
| # vim: expandtab sw=4 ts=4 | ||
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.
This could also be a commandline flag.
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.
OK ... I just realized that we wanted to take this
pose3dfrom true position ... so this is just first approximation.