Repository navigation
Conversation
cv2.putText only accepts 8-bit images from OpenCV 5 on, but play_movie normalizes frames to floating point before drawing the frame number, so movie.play(plot_text=True) failed with an assertion in the demos. Render the text into a uint8 mask and copy it onto the frame instead. Output is unchanged on OpenCV 4. Add a headless test that plays a small movie with plot_text=True.
Member
|
Thanks for this; sorry I've been so slow to dig into it. Been very busy at work. Will try to dig in this weekend. I really appreciate your effort to tackle it. |
Member
|
This is good work! thanks |
Member
|
I'll return to this after I fix the CI infra |
Member
|
Hey sorry to make a fuss on this; do you mind rebasing? The CI was broken for a bit and I think a rebase will correctly test it. |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
movie.play(plot_text=True)fails on OpenCV 5 with(-215:Assertion failed) img.depth() == CV_8U in function 'cv::putText'.play_movienormalizes each frame to floating point before drawing the frame number, and from OpenCV 5 oncv2.putTextonly draws on 8-bit images.This draws the text into a uint8 mask and sets those pixels to 255 in the float frame, which is the value the old call wrote. On OpenCV 4 the displayed frames are byte-identical before and after. OpenCV 5 antialiases text, but partial coverage saturates to white on the 0-1 display scale anyway.
I saw your note on the issue about looking for a good alternative for text rendering. This is one small option that keeps
putTextand the current look, so feel free to take it, change it or close it if you'd rather go another way.compute_flow_single_frameinmotion_correction.py(withplay_flow) has the same pattern. I left it alone to keep this small and can follow up if you like.Fixes #1589
Type of change
Branching
Targets
dev.Has your PR been tested?
Added
test_play_plot_texttocaiman/tests/test_movies.py. It runs the opencv backend headless by recordingcv2.imshow. It fails without the change on OpenCV 5.0.0 and passes with it on 5.0.0 and 4.14.0. I also checked that the frames shown on OpenCV 4.14 are identical before and after. I ran only the movie tests (Windows, Python 3.13), not the fullcaimanmanager testordemotest.