public void WriteHalconObj(string fileName) { if (CodeReaderHand.Handle.ToInt32() > 0) { CodeReaderHand.WriteDataCode2dModel(fileName + ".dcm"); } if (SearchRegion.IsInitialized()) { SearchRegion.WriteRegion(fileName + ".hobj"); } }
public bool ReadHalconObj(string fileName) { bool state = true; if (System.IO.File.Exists(fileName + ".dcm")) { CodeReaderHand.ReadDataCode2dModel(fileName + ".dcm"); } else { state = false; } if (System.IO.File.Exists(fileName + ".hobj")) { SearchRegion.ReadRegion(fileName + ".hobj"); } else { state = false; } return(state); }
public bool FindDataCode(HImage img, HRegion region, bool train = false) { if (!region.IsInitialized()) { region = img.GetDomain(); } if (!train) { Display(0, region); } HImage reduceImg = img.ReduceDomain(region); HImage searchImg = reduceImg.CropDomain(); reduceImg.Dispose(); int width, height; searchImg.GetImageSize(out width, out height); HImage zoomImg = searchImg.ZoomImageFactor(DateCodeZoomImg, DateCodeZoomImg, "constant"); DataCodeContour.Dispose(); searchImg.Dispose(); HTuple ResultHandles, DecodedDataStrings; if (train) { DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "train", "all", out ResultHandles, out DecodedDataStrings); } else { DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings); } if (DecodedDataStrings.Length > 0) { DataCodeString = DecodedDataStrings[0].S; HHomMat2D mat = new HHomMat2D(); HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0); double row, col; region.AreaCenter(out row, out col); HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0); HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour); DataCodeContour.Dispose(); DataCodeContour = tranDataCodeContour; if (!train) { Display(2); Display(3); } } else { if (UseBrighten) { HImage brightenImg = zoomImg.ScaleImage(UseBrightenValue, 0.0); DataCodeContour = CodeReaderHand.FindDataCode2d(brightenImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings); if (DecodedDataStrings.Length > 0) { DataCodeString = DecodedDataStrings[0].S; HHomMat2D mat = new HHomMat2D(); HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0); double row, col; region.AreaCenter(out row, out col); HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0); HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour); DataCodeContour.Dispose(); DataCodeContour = tranDataCodeContour; if (!train) { Display(2); Display(3); } return(true); } } DataCodeString = string.Empty; if (!train) { Display(4); } return(false); } return(true); }