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

Fix cropping when rendering video #842

Merged
merged 8 commits into from
Aug 3, 2022
Merged

Conversation

roomrys
Copy link
Collaborator

@roomrys roomrys commented Jul 16, 2022

Description

Although we allowed users to attempt to export a cropped version of their video - and had most of the code set-up to do so - there were still a few bugs making the crop feature unusable.

This PR allows users to render a cropped video that attempts to track instances in the frame - sometimes if instances move too fast, the crop does not follow in time due to smoothing or the crop may be too tiny to fit the instances.

Types of changes

  • Bugfix
  • New feature (doubt this feature ever worked beforehand)
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

Render Video > Crop Size: Half results in cv2.error #672

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

@codecov
Copy link

codecov bot commented Jul 16, 2022

Codecov Report

Merging #842 (8d82acf) into develop (28b395d) will increase coverage by 0.12%.
The diff coverage is 83.09%.

@@             Coverage Diff             @@
##           develop     #842      +/-   ##
===========================================
+ Coverage    66.73%   66.85%   +0.12%     
===========================================
  Files          129      129              
  Lines        21729    21742      +13     
===========================================
+ Hits         14500    14535      +35     
+ Misses        7229     7207      -22     
Impacted Files Coverage Δ
sleap/io/visuals.py 90.81% <83.09%> (+7.47%) ⬆️
sleap/instance.py 88.45% <0.00%> (+0.48%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@roomrys roomrys marked this pull request as ready for review July 16, 2022 12:56
@roomrys roomrys requested a review from talmo July 16, 2022 12:57
Comment on lines 142 to 148
except Exception as e:
raise (e)
finally:
if writer_object is not None:
writer_object.close()
# send (-1, time) to signal done
progress_queue.put((-1, total_elapsed))
Copy link
Collaborator Author

@roomrys roomrys Jul 19, 2022

Choose a reason for hiding this comment

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

We are still able to get stuck in the code somewhere even with this try except finally executing as expected. For example, I intentionally errored-out to this message but was not returned to the CLI:

(sleap_render-video-crop) λ python tests\liezl_test_script.py
Saving config: C:\Users\TalmoLab/.sleap/1.2.4/preferences.yaml
Writing video with 14100 frame images...
INFO:sleap.io.visuals:Chunks: 221, chunk size: 64
Done in 0.41996690000000036 s, fps = 33574.07452825446.
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\TalmoLab\miniconda3\envs\sleap_render-video-crop\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\TalmoLab\miniconda3\envs\sleap_render-video-crop\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "d:\social-leap-estimates-animal-poses\pull-requests\sleap_render-video-crop\sleap\sleap\io\visuals.py", line 145, in writer
    raise (e)
  File "d:\social-leap-estimates-animal-poses\pull-requests\sleap_render-video-crop\sleap\sleap\io\visuals.py", line 126, in writer
    h, w = data[0].shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'

Definitely getting stuck in the thread, now just need to figure out how to get unstuck.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opting to push the crop video fixes in this PR and handle the threading hang-up as a different issue.

@roomrys roomrys requested a review from talmo July 21, 2022 00:14
@roomrys roomrys merged commit 44e4661 into develop Aug 3, 2022
@roomrys roomrys deleted the liezl/render-video-crop branch August 3, 2022 23:28
@roomrys roomrys mentioned this pull request Sep 11, 2022
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.

2 participants