利用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;}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。
新闻热点
疑难解答
图片精选