BUGFIX in sample falsecolor.cpp | Fix trackbar position settings#21005
Conversation
468d970 to
4707efc
Compare
samples/cpp/falsecolor.cpp
Outdated
| setTrackbarMin("colormap", winName, COLORMAP_AUTUMN); | ||
| setTrackbarMax("colormap", winName, COLORMAP_TURBO+1); | ||
| setTrackbarPos("colormap", winName, -1); | ||
| setTrackbarPos("colormap", winName, 1); |
There was a problem hiding this comment.
1 => 0
See line 105.
or even use COLORMAP_AUTUMN to avoid magic constants.
samples/cpp/falsecolor.cpp
Outdated
| imshow("Gray image",img); | ||
| namedWindow(winName); | ||
| createTrackbar("colormap", winName,&p.iColormap,1,TrackColorMap,(void*)&p); | ||
| createTrackbar("colormap", winName,&p.iColormap, (int)ColorMaps->capacity(), TrackColorMap, (void*)&p); |
There was a problem hiding this comment.
&p.iColormap => NULL as there is no way to properly handle lifetime of this variable (memory corruption may happen)
samples/cpp/falsecolor.cpp
Outdated
| createTrackbar("colormap", winName,&p.iColormap,1,TrackColorMap,(void*)&p); | ||
| createTrackbar("colormap", winName,&p.iColormap, (int)ColorMaps->capacity(), TrackColorMap, (void*)&p); | ||
| setTrackbarMin("colormap", winName, COLORMAP_AUTUMN); | ||
| setTrackbarMax("colormap", winName, COLORMAP_TURBO+1); |
There was a problem hiding this comment.
(int)ColorMaps->capacity()
See on the line with setTrackbarMax call.
samples/cpp/falsecolor.cpp
Outdated
| createTrackbar("colormap", winName,&p.iColormap,1,TrackColorMap,(void*)&p); | ||
| createTrackbar("colormap", winName,&p.iColormap, (int)ColorMaps->capacity(), TrackColorMap, (void*)&p); | ||
| setTrackbarMin("colormap", winName, COLORMAP_AUTUMN); | ||
| setTrackbarMax("colormap", winName, COLORMAP_TURBO+1); |
There was a problem hiding this comment.
COLORMAP_TURBO
It is not the last value anymore. This sample need to be updated.
4707efc to
dcebf26
Compare
alalek
left a comment
There was a problem hiding this comment.
Thank you for update!
This patch should go into 3.4 branch first.
We will merge changes from 3.4 into master regularly (weekly/bi-weekly).
Please:
- change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
- rebase your commits from master onto 3.4 branch. For example:
git rebase -i --onto upstream/3.4 upstream/master
(check list of your commits, save and quit (Esc + "wq" + Enter)
whereupstreamis configured by following this GitHub guide and fetched (git fetch upstream). - push rebased commits into source branch of your fork (with
--forceoption)
Note: no needs to re-open PR, apply changes "inplace".
dcebf26 to
219f917
Compare
219f917 to
968d94d
Compare
|
Cheers, thank you for your time. |
There are two values that provoke unintended behaviour when running the sample code falsecolor.cpp.
First instance is trying to set the tracker position to -1 and that throws and out of bounds exception.
The second instance sets the maximum tracker position to 1 which only allows the two colormaps to be applied the first and the last.
There is an issue that could be closed after this PR is merged. (#21002)
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.