标签:
Mat cannyClone= Mat::zeros(Size(gray.cols,gray.rows),gray.type());
Canny(gray,canny,100,255);
Mat element = getStructuringElement(MORPH_ELLIPSE,Size(7,3));
morphologyEx(canny,canny,CV_MOP_DILATE,element);
morphologyEx(canny,canny,CV_MOP_ERODE ,element);
imwrite("canny.jpg",canny);
findContours(canny,contours,CV_RETR_TREE,CV_CHAIN_APPROX_NONE);
for (int i=0;i<contours.size();i++)
{
int itmp = contourArea(contours[i]);
if (imaxcontour < itmp )
{
imax = i;
imaxcontour = itmp;
}
}
//找到轮廓的处理
Rect boundRect;//最小外接矩形
drawContours(cannyClone,contours,imax,Scalar(255),-1);
boundRect = boundingRect(Mat(contours[imax]));
Mat srcRoi = src(boundRect);
imwrite("barcode.jpg",srcRoi);
string opFilePath = System.Environment.CurrentDirectory + "\\result.jpg";
MultiFormatReader mutiReader = new com.google.zxing.MultiFormatReader();
Bitmap img = (Bitmap)Bitmap.FromFile(opFilePath);
if (img == null)
return;
LuminanceSource ls = new RGBLuminanceSource(img, img.Width, img.Height);
BinaryBitmap bb = new BinaryBitmap(new com.google.zxing.common.HybridBinarizer(ls));
Result r = mutiReader.decode(bb);
tb.Text = r.Text;
标签:
原文地址:http://www.cnblogs.com/jsxyhelu/p/4650158.html