|
|
|
@ -225,7 +225,24 @@ namespace Rs.MotionPlat.Flow.Camera
|
|
|
|
|
vr.OffsetY =-1 * (row.D- upCameraScanBarCodeModel.ModelMatchResult[0].D) * GlobalVar.UpCameraMmPerPixel;
|
|
|
|
|
vr.OffsetR = AngleTool.Rad2Deg((angle.D - upCameraScanBarCodeModel.ModelMatchResult[2].D));
|
|
|
|
|
vr.SourceImage = image;
|
|
|
|
|
vr.SearchModelOK = true;
|
|
|
|
|
if(vr.OffsetX<GlobalVar.TurnoverTrayLocateXRange && vr.OffsetY<GlobalVar.TurnoverTrayLocateYRange && vr.OffsetR<GlobalVar.TurnoverTrayLocateRRange)
|
|
|
|
|
{
|
|
|
|
|
vr.SearchModelOK = true;
|
|
|
|
|
//只有定位成功的才去扫二维码
|
|
|
|
|
string sn = FindCode(image, upCameraScanBarCodeModel.BarCodeRegion);
|
|
|
|
|
if(string.IsNullOrEmpty(sn))
|
|
|
|
|
{
|
|
|
|
|
vr.ScanBarCodeOK = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vr.SN = sn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vr.SearchModelOK = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return vr;
|
|
|
|
|
}
|
|
|
|
@ -240,5 +257,67 @@ namespace Rs.MotionPlat.Flow.Camera
|
|
|
|
|
}
|
|
|
|
|
return vr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FindCode(HObject images,HObject _barCodeRegion)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// HOperatorSet.GenRectangle1(out HObject searchRegion, new HTuple(1533), new HTuple(731), new HTuple(1751), new HTuple(1071));
|
|
|
|
|
//HOperatorSet.GenRectangle1(out HObject searchRegion,row1, col1, row2, col2);
|
|
|
|
|
|
|
|
|
|
HOperatorSet.ReduceDomain(images, _barCodeRegion, out HObject imgReduaced);
|
|
|
|
|
//HOperatorSet.CropDomain(imgReduaced, out HObject imagePart);
|
|
|
|
|
//HOperatorSet.WriteImage(imagePart, "bmp", 0, "d://images/11");
|
|
|
|
|
//HOperatorSet.Threshold(imagePart, out HObject region, new HTuple(200), new HTuple(255));
|
|
|
|
|
//HOperatorSet.Connection(region, out HObject connectedRegions);
|
|
|
|
|
//HOperatorSet.FillUp(connectedRegions, out HObject regionFillUp);
|
|
|
|
|
//HOperatorSet.ShapeTrans(regionFillUp, out HObject regionTrans, "rectangle1");
|
|
|
|
|
//HOperatorSet.SelectShape(regionTrans, out HObject selectedRegions, "area", "and", new HTuple(7000), new HTuple(9000));
|
|
|
|
|
//HOperatorSet.SelectShape(selectedRegions, out HObject searchRegions, "outer_radius", "and", new HTuple(50), new HTuple(70));
|
|
|
|
|
//if (searchRegions.IsInitialized() && searchRegions.CountObj() == 1)
|
|
|
|
|
{
|
|
|
|
|
//找到了二维码区域
|
|
|
|
|
//HOperatorSet.DilationRectangle1(searchRegions, out HObject regionDilation, new HTuple(40), new HTuple(40));
|
|
|
|
|
//HOperatorSet.ReduceDomain(imagePart, regionDilation, out HObject imageReduacedQrcode);
|
|
|
|
|
//HOperatorSet.InvertImage(imageReduacedQrcode, out HObject imageInvert);
|
|
|
|
|
//HOperatorSet.ScaleImage(imageInvert, out HObject imageScaled, 2, 0);
|
|
|
|
|
//HOperatorSet.WriteImage(imageScaled, "bmp", 0, "d://images/22");
|
|
|
|
|
//HOperatorSet.ZoomImageFactor(imageScaled, out HObject imageZoomed, new HTuple(10), new HTuple(10), "constant");
|
|
|
|
|
HTuple decodedDataStrings = "";
|
|
|
|
|
HObject xlds = new HObject();
|
|
|
|
|
|
|
|
|
|
string[] modes = new string[] { "standard_recognition", "enhanced_recognition", "maximum_recognition" };
|
|
|
|
|
foreach (string mode in modes)
|
|
|
|
|
{
|
|
|
|
|
HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", "default_parameters", mode, out HTuple dataCodeHandle);
|
|
|
|
|
HOperatorSet.FindDataCode2d(imgReduaced, out xlds, dataCodeHandle, new HTuple(), new HTuple(), out HTuple resultHandles, out decodedDataStrings);
|
|
|
|
|
|
|
|
|
|
if (decodedDataStrings.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return decodedDataStrings.ToString().Replace("\"", "");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (mode == "maximum_recognition")
|
|
|
|
|
{
|
|
|
|
|
HOperatorSet.WriteImage(images, "bmp", 0, $"d://images/scanfail/{DateTime.Now.ToString("yyyy-MM-dd HHmmss ffff")}");
|
|
|
|
|
HOperatorSet.ClearDataCode2dModel(dataCodeHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// HOperatorSet.WriteImage(images, "bmp", 0, $"d://images/scanfail/{DateTime.Now.ToString("yyyy-MM-dd HHmmss ffff")}");
|
|
|
|
|
// mr.ScanOK = false;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error(ex.Message, ex);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|