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

Deal better with looping on a video file and the start and stop frame #66

Closed
wants to merge 1 commit into from

Conversation

awesomebytes
Copy link
Member

@awesomebytes awesomebytes commented Apr 28, 2020

Based on this issue: #61

And this PR: #65

I've used the approach from @martiege. I tried to have a flag to mark if the dynamic_reconfigure server needed to be updated, and the call updateConfig with the new configuration, but this didn't work (the updateConfig never actually calls the dynamic_reconfigure server to update itself).

I've also added some extra logging to try to make a bit clearer what is happening when a user plays with the start_frame and stop_frame parameters.

I've increased the dynamic_reconfigure levels of changing start_frame and stop_frame to force re-subscribing as in the subscription point in the code we have the checks for the frame count. I couldn't move these checks to the dynamic_reconfigure call because we don't have a way to know the amount of frames up until we've opened the video file to call that API. Changing this would imply more changes than I'm comfortable making right now without adding a lot of unit tests (that we should have).

gen.add("start_frame", int_t, LEVEL.NORMAL, "Start frame of the video ", 0, 0)
gen.add("stop_frame", int_t, LEVEL.NORMAL, "Stop frame of the video", -1, -1)
gen.add("start_frame", int_t, LEVEL.RUNNING, "Start frame of the video ", 0, 0)
gen.add("stop_frame", int_t, LEVEL.RUNNING, "Stop frame of the video", -1, -1)
Copy link
Member Author

Choose a reason for hiding this comment

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

Incrased the level to force the dynamic_reconfigure callback to do unsubscribe and then subscribe so frame correctness checks are done.

if (video_stream_provider_type == "videofile" &&
frame_counter == latest_config.stop_frame - latest_config.start_frame)
frame_counter >= latest_config.stop_frame - latest_config.start_frame)
Copy link
Member Author

Choose a reason for hiding this comment

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

There are cases where the frame_counter variable can go over this check and then we are stuck forever on the Could not capture frame error. By doing >= we make sure to reset.

@@ -241,16 +243,22 @@ virtual void subscribe() {
cap->open(video_stream_provider);
if(video_stream_provider_type == "videofile" )
{
if(latest_config.stop_frame == -1) latest_config.stop_frame = cap->get(cv::CAP_PROP_FRAME_COUNT);
// We can only check the number of frames when we actually open the video file
NODELET_INFO_STREAM("Video number of frames: " << cap->get(cv::CAP_PROP_FRAME_COUNT));
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a bit of extra output to help users.

NODELET_INFO_STREAM("Video number of frames: " << cap->get(cv::CAP_PROP_FRAME_COUNT));
if(latest_config.stop_frame == -1)
{
NODELET_WARN_STREAM("'stop_frame' set to -1, setting internally (won't be shown in dynamic_reconfigure) to last frame: " << cap->get(cv::CAP_PROP_FRAME_COUNT));
Copy link
Member Author

Choose a reason for hiding this comment

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

Try to avoid doing things obscurely and warn the user. The user may want to use this information to update their launch file to the last frame.

if(latest_config.stop_frame > cap->get(cv::CAP_PROP_FRAME_COUNT))
{
NODELET_WARN_STREAM("Invalid 'stop frame' " << latest_config.stop_frame << " for video which has " << cap->get(cv::CAP_PROP_FRAME_COUNT) << " frames. Set 'stop frame' to " << cap->get(cv::CAP_PROP_FRAME_COUNT) << ".");
NODELET_ERROR_STREAM("Invalid 'stop_frame' " << latest_config.stop_frame << " for video which has " << cap->get(cv::CAP_PROP_FRAME_COUNT) << " frames. Setting internally (won't be shown in dynamic_reconfigure) 'stop_frame' to " << cap->get(cv::CAP_PROP_FRAME_COUNT));
Copy link
Member Author

Choose a reason for hiding this comment

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

Upgrade these to errors, as they are actually configuration errors.

@awesomebytes
Copy link
Member Author

Oops messed up a bit with an unnecessary log to screen, redoing this.

@awesomebytes awesomebytes deleted the video_file_loop_issues branch April 28, 2020 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant