大家好,又见面了,我是全栈君。 从原理:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/threshold/threshold.html
本节简单介绍:
注意:本节的解释出自Bradski与Kaehler的书籍 Learning OpenCV 。
部分代码:
// ConsoleApplication3_6_23.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
Mat src,gray,dst;
int thr_value = 0;
int thr_type = 0;
const int max_type = 4;
const int max_value = 255;
const int max_binary_value = 255;
char *windowName = "Demo";
void Image_thred(int,void*);
int _tmain(int argc, _TCHAR* argv[])
{
src = imread("test.png");
if(!src.data)
return -1;
cvtColor(src,gray,CV_RGB2GRAY);
namedWindow("灰度图",CV_WINDOW_AUTOSIZE);
imshow("灰度图",gray);
namedWindow(windowName,CV_WINDOW_AUTOSIZE);
createTrackbar("Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted",
windowName,&thr_type,max_type,Image_thred);
createTrackbar("Value",
windowName,&thr_value,max_value,Image_thred);
Image_thred(0,0);
waitKey(0);
return 0;
}
void Image_thred(int,void*)
{
/* 0: 二进制阈值
1: 反二进制阈值
2: 截断阈值
3: 0阈值
4: 反0阈值
*/
threshold(gray,dst,thr_value,max_binary_value,thr_type);
imshow(windowName,dst);
}
关键函数解释:
threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117272.html原文链接:https://javaforall.cn