|
|
|
@ -205,43 +205,62 @@ namespace Rs.MotionPlat.Commom
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// HOperatorSet.GenRectangle1(out HObject searchRegion, new HTuple(1533), new HTuple(731), new HTuple(1751), new HTuple(1071));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HOperatorSet.GenRectangle1(out HObject searchRegion, new HTuple(1533), new HTuple(731), new HTuple(1751), new HTuple(1071));
|
|
|
|
|
HOperatorSet.GenRectangle1(out HObject searchRegion, new HTuple(SysConfigParam.GetValue<int>("CodeRow1")), new HTuple(SysConfigParam.GetValue<int>("CodeColumn1")), new HTuple(SysConfigParam.GetValue<int>("CodeRow2")), new HTuple(SysConfigParam.GetValue<int>("CodeColumn2")));
|
|
|
|
|
|
|
|
|
|
HOperatorSet.ReduceDomain(images, searchRegion, out HObject imgReduaced);
|
|
|
|
|
HOperatorSet.CropDomain(imgReduaced, out HObject imagePart);
|
|
|
|
|
|
|
|
|
|
HOperatorSet.InvertImage(imagePart, 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[] { "maximum_recognition" };
|
|
|
|
|
foreach (string mode in modes)
|
|
|
|
|
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.CreateDataCode2dModel("Data Matrix ECC 200", "default_parameters", mode, out HTuple dataCodeHandle);
|
|
|
|
|
HOperatorSet.FindDataCode2d(imageScaled, out xlds, dataCodeHandle, new HTuple(), new HTuple(), out HTuple resultHandles, out decodedDataStrings);
|
|
|
|
|
//找到了二维码区域
|
|
|
|
|
HOperatorSet.DilationRectangle1(searchRegions, out HObject regionDilation, new HTuple(20), new HTuple(20));
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if (decodedDataStrings.Length > 0)
|
|
|
|
|
string[] modes = new string[] {"standard_recognition","enhanced_recognition","maximum_recognition" };
|
|
|
|
|
foreach (string mode in modes)
|
|
|
|
|
{
|
|
|
|
|
mr.SN = decodedDataStrings.ToString().Replace("\"", "");
|
|
|
|
|
mr.ScanOK = true;
|
|
|
|
|
HOperatorSet.ClearDataCode2dModel(dataCodeHandle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (mode == "maximum_recognition")
|
|
|
|
|
HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", "default_parameters", mode, out HTuple dataCodeHandle);
|
|
|
|
|
HOperatorSet.FindDataCode2d(imageScaled, out xlds, dataCodeHandle, new HTuple(), new HTuple(), out HTuple resultHandles, out decodedDataStrings);
|
|
|
|
|
|
|
|
|
|
if (decodedDataStrings.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
mr.ScanOK = false;
|
|
|
|
|
mr.SN = decodedDataStrings.ToString().Replace("\"", "");
|
|
|
|
|
mr.ScanOK = true;
|
|
|
|
|
HOperatorSet.ClearDataCode2dModel(dataCodeHandle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (mode == "maximum_recognition")
|
|
|
|
|
{
|
|
|
|
|
HOperatorSet.WriteImage(images, "bmp", 0, $"d://images/scanfail/{DateTime.Now.ToString("yyyy-MM-dd HHmmss ffff")}");
|
|
|
|
|
mr.ScanOK = false;
|
|
|
|
|
HOperatorSet.ClearDataCode2dModel(dataCodeHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HOperatorSet.WriteImage(images, "bmp", 0, $"d://images/scanfail/{DateTime.Now.ToString("yyyy-MM-dd HHmmss ffff")}");
|
|
|
|
|
mr.ScanOK = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//HOperatorSet.WriteImage(imagePart, "bmp", 0, "d://images/11");
|
|
|
|
|