-
-
Notifications
You must be signed in to change notification settings - Fork 55.6k
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
Can not set trackBarPos, if two trackbar in the same window #25537
Comments
There is no exception if img is not empty.
Did you checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution? NO |
I am sure that |
@RichardZeenChen Does the sample work well for you? |
The program work well, only if you do not set the trackbarPos. Can not set trackBarPos, if two trackbar in the same window. Hower, the code work well if only one trackbar in the window. #include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
void gaussianBlurCall(int pos, void* userdata) {
Mat* img = static_cast<Mat*>(userdata);
int k = getTrackbarPos("kernel", "dst");
if (k % 2 == 0) {
k = k - 1;
}
int sigma = getTrackbarPos("sigma", "dst");
Mat dst;
GaussianBlur(*img, dst, Size(k, k), sigma);
imshow("dst", dst);
}
int main(int argc, char** argv)
{
Mat src = imread("blur.tif");
namedWindow("dst", WINDOW_NORMAL);
createTrackbar("kernel", "dst", nullptr, 21, gaussianBlurCall, &src);
setTrackbarMin("kernel", "dst", 1);
setTrackbarPos("kernel", "dst", 3); //can not set pos
createTrackbar("sigma", "dst", nullptr, 10, gaussianBlurCall, &src);
setTrackbarMin("sigma", "dst", 1);
setTrackbarPos("sigma", "dst", 7); //can not set pos
waitKey();
return 0;
} |
@RichardZeenChen when we call the first setTrackbarPos("kernel", "dst", 3); interanlly it call the gaussianBlurCall which tries to get the value of "sigma" trackbar even before we created it using createTrackbar("sigma", "dst", nullptr, 10, gaussianBlurCall, &src); hence causing it to crash. |
Agree with @anshulchou-123. The provided code runs getTrackbarPos("sigma"...) before createTrackbar("sigma"...) which causes the crash. The code works fine if you run setTrackbarPos after creating both the trackbars. |
System Information
OpenCV version: 4.8.0
Operating System / Platform: Win 10
Compiler & compiler version: vs2019 vc16
Detailed description
When you uncomment code
setTrackbarPos("kernel", "dst", 3);
, the program will report an error during runtimeThe text was updated successfully, but these errors were encountered: