参考http://blog.csdn.net/chinabinlang/article/details/6576889
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src, src_thresh;
src = imread("1.bmp", 0);
threshold(src, src_thresh, 220, 255, 0);
int n=4;
for(int i=0; i<src.rows; i++)
{
uchar* src_thresh_data = src_thresh.ptr<uchar>(i);
for(int j=0; j<src.cols; j++)
{
for(int nTemp=0; nTemp<n; nTemp++)
{
if(src_thresh_data[j+nTemp] != 0)
{
if((j+nTemp-n<src.cols) && ((i*src.cols+j+nTemp-n)>NULL) && src_thresh_data[j+nTemp-n] ==0)
{
break;
}
for(int nTemp1=0; nTemp1<nTemp; nTemp1++)
{
src_thresh_data[j+nTemp1] = 255;
break;
}
break;
}
}
}
}
namedWindow("src", CV_WINDOW_AUTOSIZE);
namedWindow("src_thresh", CV_WINDOW_AUTOSIZE);
imshow("src", src);
imshow("src_thresh", src_thresh);
waitKey(0);
return 0;
}
通过记录黑点, 把黑点重新设为255;n=4,应该是把,前3个黑点设为255;