Skip to content

BUGFIX in sample falsecolor.cpp | Fix trackbar position settings#21005

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
nikpappas:bug-samples-falsecolor-trackbar
Nov 6, 2021
Merged

BUGFIX in sample falsecolor.cpp | Fix trackbar position settings#21005
opencv-pushbot merged 1 commit intoopencv:3.4from
nikpappas:bug-samples-falsecolor-trackbar

Conversation

@nikpappas
Copy link
Copy Markdown
Contributor

@nikpappas nikpappas commented Nov 3, 2021

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

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@nikpappas nikpappas force-pushed the bug-samples-falsecolor-trackbar branch 2 times, most recently from 468d970 to 4707efc Compare November 4, 2021 07:55
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you for contribution!

setTrackbarMin("colormap", winName, COLORMAP_AUTUMN);
setTrackbarMax("colormap", winName, COLORMAP_TURBO+1);
setTrackbarPos("colormap", winName, -1);
setTrackbarPos("colormap", winName, 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

1 => 0

See line 105.


or even use COLORMAP_AUTUMN to avoid magic constants.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

&p.iColormap => NULL as there is no way to properly handle lifetime of this variable (memory corruption may happen)

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(int)ColorMaps->capacity()

See on the line with setTrackbarMax call.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

COLORMAP_TURBO

It is not the last value anymore. This sample need to be updated.

@nikpappas nikpappas force-pushed the bug-samples-falsecolor-trackbar branch from 4707efc to dcebf26 Compare November 5, 2021 07:51
@nikpappas nikpappas requested a review from alalek November 5, 2021 07:52
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

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)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@nikpappas nikpappas changed the base branch from 4.x to 3.4 November 6, 2021 09:57
@nikpappas nikpappas force-pushed the bug-samples-falsecolor-trackbar branch from dcebf26 to 219f917 Compare November 6, 2021 10:05
@nikpappas nikpappas force-pushed the bug-samples-falsecolor-trackbar branch from 219f917 to 968d94d Compare November 6, 2021 10:12
@nikpappas nikpappas requested a review from alalek November 6, 2021 10:13
@nikpappas
Copy link
Copy Markdown
Contributor Author

Cheers, thank you for your time.
Happy to be contributing here.

@opencv-pushbot opencv-pushbot merged commit 1ac7bac into opencv:3.4 Nov 6, 2021
@nikpappas nikpappas deleted the bug-samples-falsecolor-trackbar branch November 6, 2021 15:50
@alalek alalek mentioned this pull request Nov 13, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants