Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement createTrackbar

Shulou Source: shulou.com Published: 2022-06-03 05:00:46 09月21日 Update

This article mainly shows you "how to achieve createTrackbar", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve createTrackbar" this article.

CreateTrackbar is the API in Opencv, which can quickly create a sliding control in the window that displays the image, which can be used to adjust the threshold manually and has a very intuitive effect. The specific definition is as follows:

CV_EXPORTS int createTrackbar (const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange = 0, void* userdata = 0)

Formal parameter 1. Trackbarname: the name of the sliding space

Formal parameter 2. Winname: the name of the image window to which the sliding space is attached.

Formal parameter 3, value: initialization threshold

Formal parameter 4. Count: scale range of sliding controls

Formal parameter 5. TrackbarCallback is a callback function, which is defined as follows:

Typedef void (CV_CDECL * TrackbarCallback) (int pos, void* userdata)

The sample code for its use is as follows:

IplImage * src = NULL, * thresDst = NULL;int threshold_min = 100); cvNamedWindow ("threshold", CV_WINDOW_AUTOSIZE); thresDst = cvCloneImage (src); createTrackbar ("min Threshold", "threshold", & threshold_min, max_lowThreshold, threshold); threshold (0B0)

As you can see, the second parameter of createTrackbar must be exactly the same as the first parameter of cvNameWindow. The callback function is defined and implemented as follows:

Void threshold (int, void*) {cvThreshold (src, thresDst, threshold_min, 255, CV_THRESH_BINARY); cvShowImage ("threshold", thresDst);}

In this way, you can successfully create a sliding control above the image window with the following effect (the original image on the left and a binary image with the sliding control on the right):

The above is all the content of this article "how to achieve createTrackbar". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Parameters form images controls content articles functions available in name effect space threshold learning help consistency success intuition code scale Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Shulou Technology MySQL Linux