閾值操作
阿新 • • 發佈:2018-11-11
#include<opencv2\imgproc\imgproc.hpp> #include<opencv2\highgui\highgui.hpp> #include<iostream> using namespace std; using namespace cv; #define WINDOW "視窗" int g_nThresholdValue = 100; int g_nThresholdType = 3; Mat g_srcImage, g_grayImage, g_dstImage; void on_Threshold(int,void*); int main() { g_srcImage = imread("lena.jpg"); if (!g_srcImage.data) { return -1; } cvtColor(g_srcImage,g_grayImage,COLOR_RGB2GRAY); namedWindow(WINDOW); createTrackbar("模式",WINDOW,&g_nThresholdType,4,on_Threshold); createTrackbar("引數值",WINDOW,&g_nThresholdValue,255,on_Threshold); on_Threshold(0,0); waitKey(0); return 0; } void on_Threshold(int,void*) { threshold(g_grayImage,g_dstImage,g_nThresholdValue,255,g_nThresholdType); imshow(WINDOW,g_dstImage); }