利用OpenCV实现局部动态阈值分割,参考Halcon dyn_threshold算子的思路实现。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "dialog.h" #include <QApplication> #include "cv.h" #include "highgui.h" #include <QDebug> int main( int argc, char *argv[]) { IplImage *img = cvLoadImage( "D:/cs/1227/f9.bmp" ,0); IplImage *out = cvCreateImage(cvGetSize(img),img->depth,1); cvSmooth(img,out,CV_BLUR,50); IplImage *res = cvCreateImage(cvGetSize(img),img->depth,1); qDebug()<<img->nChannels; double a = 0; double b = 0; for ( int i=0;i<img->height;i++){ for ( int j=0;j<img->width;j++){ CvScalar color = cvGet2D(img,i,j); CvScalar color1 = cvGet2D(out,i,j); a = color.val[0]; b = color1.val[0]; //a = exp(a); CvScalar c = cvScalar(b-a+128); cvSet2D(res,i,j,c); } } cvThreshold(res,res,150,255,CV_THRESH_BINARY_INV); cvNamedWindow( "Image" ,0); cvShowImage( "Image" ,res); cvSaveImage( "D:/cs/cs.bmp" ,out); cvWaitKey(0); cvReleaseImage(&img); cvDestroyWindow( "Image" ); return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/qq_34316932/article/details/75330673