OpenCV实现局部动态阈值分割 利用OpenCV实现局部动态阈值分割
NUAA_CV 人气:0想了解利用OpenCV实现局部动态阈值分割的相关内容吗,NUAA_CV在本文为您仔细讲解OpenCV实现局部动态阈值分割的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:OpenCV动态阈值分割,OpenCV局部动态阈值分割,OpenCV阈值分割,下面大家一起来学习吧。
利用OpenCV实现局部动态阈值分割,参考Halcon dyn_threshold算子的思路实现。
#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; }
加载全部内容