<!-- lang: cpp --> void ClearResidualBorder(IplImage* img_bw)
{ int i,j,t; int left,right; int height = img_bw->height; int width = img_bw->width; int* hisHor = histogramVH(img_bw,1); for(i=0;i<width;i++) { CV_IMAGE_ELEM(img_bw,uchar,0,i) = 0; CV_IMAGE_ELEM(img_bw,uchar,1,i) = 0;code
CV_IMAGE_ELEM(img_bw,uchar,height-1,i) = 0; CV_IMAGE_ELEM(img_bw,uchar,height-2,i) = 0; } for(i=0;i<height;i++) { CV_IMAGE_ELEM(img_bw,uchar,i,0) = 0; CV_IMAGE_ELEM(img_bw,uchar,i,1) = 0; CV_IMAGE_ELEM(img_bw,uchar,i,width-1) = 0; CV_IMAGE_ELEM(img_bw,uchar,i,width-2) = 0; } //水平濾波 for(i=0;i<height;i++) { left = -1; for(j=0;j<width;j++) { if(CV_IMAGE_ELEM(img_bw,uchar,i,j) == 255) { if(left == -1) { left = j; right = j; } else { right++; } } else { if(left != -1) { if(right - left > width*0.2) { for(t=left;t<right;t++) { CV_IMAGE_ELEM(img_bw,uchar,i,t) = 0; } } left = -1; } } } } //豎直濾波 for(i=0;i<width;i++) { left = -1; for(j=1;j<height-1;j++) { if(CV_IMAGE_ELEM(img_bw,uchar,j,i) == 255 && CV_IMAGE_ELEM(img_bw,uchar,j-1,i) == 0 && CV_IMAGE_ELEM(img_bw,uchar,j+1,i) == 0) { CV_IMAGE_ELEM(img_bw,uchar,j,i) = 0; } } } for(i = 0;i<img_bw->width/2;i++) { if(hisHor[i] > img_bw->height*0.92) { for(j=0;j<img_bw->height;j++) CV_IMAGE_ELEM(img_bw,uchar,j,i)=0; } else break; } for(i = img_bw->width-1;i>img_bw->width/2;i--) { if(hisHor[i] > img_bw->height*0.92) { for(j=0;j<img_bw->height;j++) CV_IMAGE_ELEM(img_bw,uchar,j,i)=0; } else break; } /*for(i=1;i<height-1;i++) { for(j=0;j<width;j++) { if(CV_IMAGE_ELEM(img_bw,uchar,i,j) == 255) { if(CV_IMAGE_ELEM(img_bw,uchar,i-1,j) == 0 && CV_IMAGE_ELEM(img_bw,uchar,i+1,j) == 0) CV_IMAGE_ELEM(img_bw,uchar,i,j) = 0; } } }*/ free(hisHor);
}im