#include "stdafx.h"
#include
#include
#include
#include
void thredChange(cv::InputArray src,cv::OutputArray dst)
{
cv::threshold(src,dst,180,255,CV_THRESH_BINARY_INV);
}
void filterPoints(cv::Mat image,cv::Mat result)
{
// allocate if necessary
//result.create(image.size(), image.type());
for(int j=0;
j
int d=10;
for (int j= d;
j
const uchar* previous=
image.ptr
const uchar* current=
image.ptr
const uchar* next=
image.ptr
uchar* output= result.ptr
for (int i=d;
i
current[i-d]!=0||
current[i+d]!=0||
previous[i]!=0||
previous[i-d]!=0||
previous[i+d]!=0||
previous[i+1]!=0||
previous[i+2]!=0||
previous[i+3]!=0||
previous[i+4]!=0||
previous[i-4]!=0||
previous[i-3]!=0||
previous[i-2]!=0||
previous[i-1]!=0||
next[i-d]!=0||
next[i+d]!=0||
next[i-1]!=0||
next[i-2]!=0||
next[i-3]!=0||
next[i-4]!=0||
next[i+1]!=0||
next[i+2]!=0||
next[i+3]!=0||
next[i+4]!=0||
next[i]!=0
)
*output++=0;
else
*output++=255;
}
}
}
void removeLittle(cv::Mat image,cv::Mat result,int num)
{
// allocate if necessary
//result.create(image.size(), image.type());
for(int j=0;
j
int d=1;
for (int j= d;
j
const uchar* previous=
image.ptr
const uchar* current=
image.ptr
const uchar* next=
image.ptr
uchar* output= result.ptr
for (int i=d;
i
+previous[i-1]+previous[i]+previous[i+1]
+next[i-1]+next[i]+next[i+1];
if((current[i]==255)&&
(a>255*num))
*output++=255;
else
*output++=0;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat image=cv::imread("./data/test1/points.jpg",CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat p2;
cv::Mat p3=image.clone();
;
cv::Mat p4=image.clone();
cv::Mat p5=image.clone();
thredChange(image,p2);
filterPoints(p2,p3);
removeLittle(p3,p4,5);
removeLittle(p4,p5,3);
cv::namedWindow("gui");
cv::imshow("gui",p5);
cv::waitKey(0);
return 0;
}
推荐阅读
- 人脸识别|【人脸识别系列】| 实现自动化妆
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- opencv|图像处理之椒盐噪声的添加与去除
- 人脸识别|【人脸识别系列】| 实现人脸截图保存并编写128维特征向量
- opencv|网络爬虫入门练习
- OpenCV|【OpenCV 完整例程】89. 带阻滤波器的传递函数
- OpenCV|【OpenCV 完整例程】90. 频率域陷波滤波器
- OpenCV|【OpenCV 完整例程】22. 图像添加非中文文字
- OpenCV|【OpenCV 完整例程】91. 高斯噪声、瑞利噪声、爱尔兰噪声
- opencv|python+opencv车道线,实线虚线的检测