程式語言 - OpenCV - Window Utils - Use Trackbar



參考資訊:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

main.cpp

#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int threshval = 100;

static void on_trackbar(int, void *)
{
    char buf[255] = {0};

    sprintf(buf, "%d", threshval);
    Mat img(250, 250, CV_8UC3, Scalar(128, 255, 255));
    putText(img, buf, Point(80, 100), FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 1, LINE_AA);
    imshow("trackbar", img);
}

int main(int argc, const char **argv)
{
    namedWindow("trackbar", WINDOW_AUTOSIZE);
    createTrackbar("Threshold", "trackbar", &threshval, 255, on_trackbar);
    on_trackbar(threshval, 0);
    waitKey(0);
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(main)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

編譯並且執行

$ cmake .
$ make
$ ./main

完成