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

New requirement: iter_frames #3

Closed
b2m opened this issue Jun 13, 2016 · 3 comments
Closed

New requirement: iter_frames #3

b2m opened this issue Jun 13, 2016 · 3 comments
Assignees

Comments

@b2m
Copy link

b2m commented Jun 13, 2016

It would be helpful if there would be a function iter_frames(start=None, end=None, cam=None) analogous to iter_fnames.

This function would iterate through frames in a given time range.

Start is inclusive, end is exclusive.

No start or end given: behavior like iter_fnames.

@berleon
Copy link
Member

berleon commented Jun 15, 2016

Would the function simple yield raw Cap'N Proto frames? Or would they also be converted to
numpy arrays? What if you are interested in the cam_id which is stored only in the FrameContainer at the top level? Would this use-case be out of scope of the iter_frames function?
I personally prefer start till end like the python range function.

@b2m
Copy link
Author

b2m commented Jun 16, 2016

I personally prefer start till end like the python range function.

Agreed

Regarding the cam_id: I do not like the idea of dropping the information for a convenience method like iter_frames. So here are three suggestions:

  1. Move cam_id from FrameContainer to Frame in the Schema, making it possible to store frames from different cameras in one FrameContainer.
  2. yield the FrameContainer object as dictionary (without frames) as second return value along with the Frame object
  3. Convert the Frame to a python dictionary and add the missing information from the FrameContainer.

Otherwise it could be argued, that if you need the cam_id or other information from FrameContainer, use iter_fnames or make several passes with the cam parameter of iter_frames.

I would prefer option 2 with the FrameContainer as second return value.
The calling code then would look something like:

from numpy.lib.recfunctions import append_fields
for frame, fc in repo.iter_frames(start, end):
    arr = convert_frame_to_numpy(frame)
    cam_col = np.repeat(fc.camId, arr.shape[0])
    arr_ext = append_fields(arr, 'cam_id', cam_col, usemask=False)
    # ... do something with arr_ext like stacking

We also could enhance convert_frame_to_numpy() to automatically add and fill columns like:

for frame, fc in repo.iter_frames(start, end):
    arr = convert_frame_to_numpy(frame, add_columns={'cam_id': fc.camId})

From my perspective this would be the most practical solution.

@berleon
Copy link
Member

berleon commented Jun 16, 2016

I would prefer option 2 with the FrameContainer as second return value.

I would prefer that too. That way the caller can always get the values he is interested in.

I also like you suggested enhancement, but you have to decide how useful it would be for the tracking.

You already had some basic code for iter_frames, right? Do you want to implement it?

@b2m b2m self-assigned this Jun 16, 2016
b2m pushed a commit that referenced this issue Jun 20, 2016
…iners

The Repository class has a new convenience function to extract all
frames in a given time range. Before it only was possible to iterate
over frame containers, which also hold frames that are **not** in
the requested time range.

Refs #3
@b2m b2m closed this as completed in c9c94c3 Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants