opencv trackbar binary image threshold

//
// Created by shanghaitech on 18-10-28.
//

#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace std;
using namespace cv;
Mat srcImage;
int pos = 0;
void onChangeTrackBar(int, void *)
{

    Mat dstImage;
    threshold(srcImage, dstImage, pos, 255, THRESH_BINARY);
    imshow("threshold2", dstImage);
}
int main()
{

     srcImage = imread("/home/Pictures/part.png");
    if (!srcImage.data){
        cout << "read failed" << endl;
        system("pause");
        return -1;
    }

    Mat srcGray;
    cvtColor(srcImage, srcGray, CV_RGB2GRAY);
    namedWindow("threshold");//创建窗口
    imshow("threshold", srcGray);
    //创建滑动条createTrackbar
    createTrackbar("pos", "threshold",
                   &pos, 255, onChangeTrackBar);


    waitKey(0);
    return 0;
}
发布了95 篇原创文章 · 获赞 8 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/ttomchy/article/details/83503981