public void PreprocessDlClassifierImagesForTrain(HWindowControl hv_HWindowControl, HTuple hv_Pretrained_DlClassifierName) { this.hv_HWindowControl = hv_HWindowControl; this.hv_WindowHandle = this.hv_HWindowControl.HalconWindow; this.hv_Pretrained_DlClassifierName = hv_Pretrained_DlClassifierName; hv_ImageFiles.Dispose(); hv_GroundTruthLabels.Dispose(); hv_LabelsIndices.Dispose(); hv_UniqueClasses.Dispose(); //读取训练数据集,图像Lable为图像所在目录名 read_dl_classifier_data_set(path_Train_Images, "last_folder", out hv_ImageFiles, out hv_GroundTruthLabels, out hv_LabelsIndices, out hv_UniqueClasses); //Create the directories for writing the preprocessed images. CreatePreprocessedImagesFolder(); //Prepare the new image names. HTuple hv_BaseNames = new HTuple(); HTuple hv_Extensions = new HTuple(); HTuple hv_Directories = new HTuple(); hv_BaseNames.Dispose(); hv_Extensions.Dispose(); hv_Directories.Dispose(); parse_filename(hv_ImageFiles, out hv_BaseNames, out hv_Extensions, out hv_Directories); hv_ObjectFilesOut.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ObjectFilesOut = (((path_Preprocessed_Images + "/") + hv_GroundTruthLabels) + "/") + hv_BaseNames; } // System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ImagePreprocessThreading); this._PreprocessThread = new System.Threading.Thread(ts); this._PreprocessThread.IsBackground = true;//设置线程为后台线程 this._PreprocessThread.Start(); }
/// <summary> /// 批量处理并显示图像线程 /// </summary> private void ImagePreprocessThreading() { //Loop through all images, //preprocess and then write them. HObject ho_Image = new HObject(); HObject ho_ImagePreprocessed = new HObject(); for (HTuple hv_ImageIndex = 0; (int)hv_ImageIndex <= (hv_ImageFiles.TupleLength() - 1); hv_ImageIndex = (int)hv_ImageIndex + 1) { //显示原图像 using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_ImageIndex)); DispImageAdaptively(ref hv_HWindowControl, ho_Image); HOperatorSet.DispText(hv_HWindowControl.HalconWindow, "ImagesPreprocessing:" + hv_ImageIndex, "window", "top", "left", "red", "box", "true"); Console.WriteLine(hv_ImageIndex.ToString()); } ho_ImagePreprocessed.Dispose(); //预处理图像 PreprocessImage(this.hv_Pretrained_DlClassifierName, ho_Image, out ho_ImagePreprocessed); //保存预处理后图像 using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteObject(ho_ImagePreprocessed, hv_ObjectFilesOut.TupleSelect(hv_ImageIndex)); } } HOperatorSet.DispText(this.hv_WindowHandle, "Preprocessing over,Click to continue...", "window", "bottom", "right", "red", "box", "false"); }
public void ocr_split(HTuple hv_SymbolNames_OCR_01_0, out HTuple hv_Ocr) { // Local iconic variables // Local control variables HTuple hv_Index = new HTuple(); // Initialize local and output iconic variables hv_Ocr = new HTuple(); hv_Ocr.Dispose(); hv_Ocr = ""; for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_SymbolNames_OCR_01_0.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Ocr = hv_Ocr + (hv_SymbolNames_OCR_01_0.TupleSelect( hv_Index)); hv_Ocr.Dispose(); hv_Ocr = ExpTmpLocalVar_Ocr; } } } hv_Index.Dispose(); return; }
// Main procedure private void action() { // Local iconic variables HObject ho_ProfileImageTLW = null, ho_ProfileImageBW = null; // Local control variables HTuple hv_ImageFilesTL = new HTuple(), hv_ImageFilesBW = new HTuple(); HTuple hv_Index = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ProfileImageTLW); HOperatorSet.GenEmptyObj(out ho_ProfileImageBW); hv_ImageFilesTL.Dispose(); HOperatorSet.ListFiles("E:/image/MVS/0923/1", (new HTuple("files")).TupleConcat( "follow_links"), out hv_ImageFilesTL); { HTuple ExpTmpOutVar_0; HOperatorSet.TupleRegexpSelect(hv_ImageFilesTL, (new HTuple("\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$")).TupleConcat( "ignore_case"), out ExpTmpOutVar_0); hv_ImageFilesTL.Dispose(); hv_ImageFilesTL = ExpTmpOutVar_0; } hv_ImageFilesBW.Dispose(); HOperatorSet.ListFiles("E:/image/MVS/0923/2", (new HTuple("files")).TupleConcat( "follow_links"), out hv_ImageFilesBW); { HTuple ExpTmpOutVar_0; HOperatorSet.TupleRegexpSelect(hv_ImageFilesBW, (new HTuple("\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$")).TupleConcat( "ignore_case"), out ExpTmpOutVar_0); hv_ImageFilesBW.Dispose(); hv_ImageFilesBW = ExpTmpOutVar_0; } for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ImageFilesTL.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ProfileImageTLW.Dispose(); HOperatorSet.ReadImage(out ho_ProfileImageTLW, hv_ImageFilesTL.TupleSelect( hv_Index)); } //Image Acquisition 01: Do something using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ProfileImageBW.Dispose(); HOperatorSet.ReadImage(out ho_ProfileImageBW, hv_ImageFilesTL.TupleSelect(hv_Index)); } } ho_ProfileImageTLW.Dispose(); ho_ProfileImageBW.Dispose(); hv_ImageFilesTL.Dispose(); hv_ImageFilesBW.Dispose(); hv_Index.Dispose(); }
public void image_display_datacode(HObject ho_SymbolXLDs, HTuple hv_ResultHandles, HTuple hv_WindowHandle, HTuple hv_DecodedDataStrings, HTuple hv_DataCodeHandle) { // Local iconic variables HObject ho_SymbolXLD = null; // Local control variables HTuple hv_i = new HTuple(), hv_Row = new HTuple(); HTuple hv_Col = new HTuple(), hv_ModuleSize = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolXLD); //Display all symbols, the strings encoded in them, and the module size if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_ResultHandles.TupleLength())) - 1); hv_i = (int)hv_i + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_SymbolXLD.Dispose(); HOperatorSet.SelectObj(ho_SymbolXLDs, out ho_SymbolXLD, hv_i + 1); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SymbolXLD, HDevWindowStack.GetActive()); } hv_Row.Dispose(); hv_Col.Dispose(); HOperatorSet.GetContourXld(ho_SymbolXLD, out hv_Row, out hv_Col); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetTposition(hv_WindowHandle, hv_Row.TupleMin(), hv_Col.TupleMax() ); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteString(hv_WindowHandle, hv_DecodedDataStrings.TupleSelect( hv_i)); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ModuleSize.Dispose(); HOperatorSet.GetDataCode2dResults(hv_DataCodeHandle, hv_ResultHandles.TupleSelect( hv_i), (new HTuple("module_height")).TupleConcat("module_width"), out hv_ModuleSize); } HOperatorSet.NewLine(hv_WindowHandle); //write_string (WindowHandle, 'module size = ' + ModuleSize[0] + 'x' + ModuleSize[1]) } ho_SymbolXLD.Dispose(); hv_i.Dispose(); hv_Row.Dispose(); hv_Col.Dispose(); hv_ModuleSize.Dispose(); return; }
public void RandomGetImage() { HTuple hv_TestImageFiles = new HTuple(); hv_TestImageFiles.Dispose(); HOperatorSet.ListFiles(this.path_Test_Images, "files", out hv_TestImageFiles); //Read / acquire images in a loop and classify them. using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TestImageName = hv_TestImageFiles.TupleSelect((new HTuple(HTuple.TupleRand(1) * (new HTuple(hv_TestImageFiles.TupleLength())))).TupleFloor()); } HOperatorSet.ReadImage(out this.ho_TestImage, ho_TestImageName); }
/// <summary> /// 创建预处理图像保存目录 /// </summary> public void CreatePreprocessedImagesFolder() { HOperatorSet.MakeDir(this.path_Preprocessed_Images); HTuple hv_path = new HTuple(); for (HTuple hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_UniqueClasses.TupleLength())) - 1); hv_I = (int)hv_I + 1) { hv_path.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_path = (path_Preprocessed_Images + "/") + (hv_UniqueClasses.TupleSelect(hv_I)); } HOperatorSet.MakeDir(hv_path); } }
static void TestHalCs() { HTuple hv_a = new HTuple(), hv_b = new HTuple(); HTuple hv_c = new HTuple(); // Initialize local and output iconic variables hv_a.Dispose(); hv_a = 1; hv_b.Dispose(); hv_b = 2; hv_c.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_c = hv_a + hv_b; } Console.WriteLine(hv_a.I); Console.WriteLine(hv_b.I); Console.WriteLine(hv_c.I); hv_a.Dispose(); hv_b.Dispose(); hv_c.Dispose(); }
// Main procedure private void action() { // Local iconic variables // Local control variables HTuple hv_a = new HTuple(), hv_b = new HTuple(); HTuple hv_c = new HTuple(); // Initialize local and output iconic variables hv_a.Dispose(); hv_a = 1; hv_b.Dispose(); hv_b = 2; hv_c.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_c = hv_a + hv_b; } hv_a.Dispose(); hv_b.Dispose(); hv_c.Dispose(); }
// Procedures // External procedures // Chapter: Develop // Short Description: Open a new graphics window that preserves the aspect ratio of the given image. public void dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column, HTuple hv_WidthLimit, HTuple hv_HeightLimit, out HTuple hv_WindowHandle) { // Local iconic variables // Local control variables HTuple hv_MinWidth = new HTuple(), hv_MaxWidth = new HTuple(); HTuple hv_MinHeight = new HTuple(), hv_MaxHeight = new HTuple(); HTuple hv_ResizeFactor = new HTuple(), hv_ImageWidth = new HTuple(); HTuple hv_ImageHeight = new HTuple(), hv_TempWidth = new HTuple(); HTuple hv_TempHeight = new HTuple(), hv_WindowWidth = new HTuple(); HTuple hv_WindowHeight = new HTuple(); // Initialize local and output iconic variables hv_WindowHandle = new HTuple(); //This procedure opens a new graphics window and adjusts the size //such that it fits into the limits specified by WidthLimit //and HeightLimit, but also maintains the correct image aspect ratio. // //If it is impossible to match the minimum and maximum extent requirements //at the same time (f.e. if the image is very long but narrow), //the maximum value gets a higher priority, // //Parse input tuple WidthLimit if ((int)((new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(0))).TupleOr( new HTuple(hv_WidthLimit.TupleLess(0)))) != 0) { hv_MinWidth.Dispose(); hv_MinWidth = 500; hv_MaxWidth.Dispose(); hv_MaxWidth = 800; } else if ((int)(new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual( 1))) != 0) { hv_MinWidth.Dispose(); hv_MinWidth = 0; hv_MaxWidth.Dispose(); hv_MaxWidth = new HTuple(hv_WidthLimit); } else { hv_MinWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_MinWidth = hv_WidthLimit.TupleSelect( 0); } hv_MaxWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_MaxWidth = hv_WidthLimit.TupleSelect( 1); } } //Parse input tuple HeightLimit if ((int)((new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(0))).TupleOr( new HTuple(hv_HeightLimit.TupleLess(0)))) != 0) { hv_MinHeight.Dispose(); hv_MinHeight = 400; hv_MaxHeight.Dispose(); hv_MaxHeight = 600; } else if ((int)(new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual( 1))) != 0) { hv_MinHeight.Dispose(); hv_MinHeight = 0; hv_MaxHeight.Dispose(); hv_MaxHeight = new HTuple(hv_HeightLimit); } else { hv_MinHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_MinHeight = hv_HeightLimit.TupleSelect( 0); } hv_MaxHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_MaxHeight = hv_HeightLimit.TupleSelect( 1); } } // //Test, if window size has to be changed. hv_ResizeFactor.Dispose(); hv_ResizeFactor = 1; hv_ImageWidth.Dispose(); hv_ImageHeight.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight); //First, expand window to the minimum extents (if necessary). if ((int)((new HTuple(hv_MinWidth.TupleGreater(hv_ImageWidth))).TupleOr(new HTuple(hv_MinHeight.TupleGreater( hv_ImageHeight)))) != 0) { hv_ResizeFactor.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ResizeFactor = (((((hv_MinWidth.TupleReal() ) / hv_ImageWidth)).TupleConcat((hv_MinHeight.TupleReal()) / hv_ImageHeight))).TupleMax() ; } } hv_TempWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_TempWidth = hv_ImageWidth * hv_ResizeFactor; } hv_TempHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_TempHeight = hv_ImageHeight * hv_ResizeFactor; } //Then, shrink window to maximum extents (if necessary). if ((int)((new HTuple(hv_MaxWidth.TupleLess(hv_TempWidth))).TupleOr(new HTuple(hv_MaxHeight.TupleLess( hv_TempHeight)))) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_ResizeFactor = hv_ResizeFactor * ((((((hv_MaxWidth.TupleReal() ) / hv_TempWidth)).TupleConcat((hv_MaxHeight.TupleReal()) / hv_TempHeight))).TupleMin() ); hv_ResizeFactor.Dispose(); hv_ResizeFactor = ExpTmpLocalVar_ResizeFactor; } } } hv_WindowWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_WindowWidth = hv_ImageWidth * hv_ResizeFactor; } hv_WindowHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_WindowHeight = hv_ImageHeight * hv_ResizeFactor; } //Resize window HOperatorSet.SetWindowAttr("background_color", "black"); HOperatorSet.OpenWindow(hv_Row, hv_Column, hv_WindowWidth, hv_WindowHeight, 0, "visible", "", out hv_WindowHandle); HDevWindowStack.Push(hv_WindowHandle); if (HDevWindowStack.IsOpen()) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetPart(HDevWindowStack.GetActive(), 0, 0, hv_ImageHeight - 1, hv_ImageWidth - 1); } } hv_MinWidth.Dispose(); hv_MaxWidth.Dispose(); hv_MinHeight.Dispose(); hv_MaxHeight.Dispose(); hv_ResizeFactor.Dispose(); hv_ImageWidth.Dispose(); hv_ImageHeight.Dispose(); hv_TempWidth.Dispose(); hv_TempHeight.Dispose(); hv_WindowWidth.Dispose(); hv_WindowHeight.Dispose(); return; }
// Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_ImageGray, ho_ImageMean; HObject ho_Region, ho_ImageRotate1, ho_Rectangle, ho_ImageReduced; HObject ho_ImagePart; // Local control variables HTuple hv_WindowHandle = new HTuple(), hv_AbsoluteHisto = new HTuple(); HTuple hv_RelativeHisto = new HTuple(), hv_MinThresh = new HTuple(); HTuple hv_MaxThresh = new HTuple(), hv_Area = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Phi3 = new HTuple(), hv_Row1 = new HTuple(); HTuple hv_Column1 = new HTuple(), hv_Row2 = new HTuple(); HTuple hv_Column2 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageGray); HOperatorSet.GenEmptyObj(out ho_ImageMean); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ImageRotate1); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_ImagePart); dev_update_off(); if (HDevWindowStack.IsOpen()) { HOperatorSet.CloseWindow(HDevWindowStack.Pop()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3); } //read_image (Image, 'D:/Work/LCD/LCD Pictures/昆山OK相片/1S20JES0YF07R90PMAL8_white.jpg') ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "D:/Work/LCD/LCD Pictures/昆山OK相片/lineNG_white.jpg"); hv_WindowHandle.Dispose(); dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle); if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } ho_ImageGray.Dispose(); HOperatorSet.Rgb3ToGray(ho_Image, ho_Image, ho_Image, out ho_ImageGray); ho_ImageMean.Dispose(); HOperatorSet.MeanImage(ho_ImageGray, out ho_ImageMean, 9, 9); hv_AbsoluteHisto.Dispose(); hv_RelativeHisto.Dispose(); HOperatorSet.GrayHisto(ho_ImageMean, ho_ImageMean, out hv_AbsoluteHisto, out hv_RelativeHisto); hv_MinThresh.Dispose(); hv_MaxThresh.Dispose(); HOperatorSet.HistoToThresh(hv_RelativeHisto, 20, out hv_MinThresh, out hv_MaxThresh); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageMean, out ho_Region, hv_MaxThresh.TupleSelect( 0), hv_MaxThresh.TupleSelect(1)); } hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_Region, out hv_Area, out hv_Row, out hv_Column); hv_Phi3.Dispose(); HOperatorSet.OrientationRegion(ho_Region, out hv_Phi3); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ImageRotate1.Dispose(); HOperatorSet.RotateImage(ho_ImageMean, out ho_ImageRotate1, -(hv_Phi3.TupleDeg() ), "constant"); } //count_obj (Region, Number) if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { //dev_display (Region) } //dev_clear_obj (Region) using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageRotate1, out ho_Region, hv_MaxThresh.TupleSelect( 0), hv_MaxThresh.TupleSelect(1)); } hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); HOperatorSet.InnerRectangle1(ho_Region, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_ImageRotate1, ho_Rectangle, out ho_ImageReduced); ho_ImagePart.Dispose(); HOperatorSet.CropDomain(ho_ImageReduced, out ho_ImagePart); HOperatorSet.WriteImage(ho_ImagePart, "bmp", 0, "C:/Users/D19040019/Desktop/test.bmp"); ho_Image.Dispose(); ho_ImageGray.Dispose(); ho_ImageMean.Dispose(); ho_Region.Dispose(); ho_ImageRotate1.Dispose(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_ImagePart.Dispose(); hv_WindowHandle.Dispose(); hv_AbsoluteHisto.Dispose(); hv_RelativeHisto.Dispose(); hv_MinThresh.Dispose(); hv_MaxThresh.Dispose(); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Phi3.Dispose(); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); }
public void region_ocr_num_svm(HObject ho_Image, HObject ho_ROI_OCR_01_0, HTuple hv_TextModel, HTuple hv_OcrHandle, out HTuple hv_SymbolNames_OCR_01_0, out HTuple hv_Ocr_Split) { // Local iconic variables HObject ho_TmpObj_Mono, ho_TmpObj_MonoReduced_OCR_01_0; HObject ho_TmpObj_Domain, ho_TmpObj_DomainExpanded, ho_TmpObj_DomainTransformedRaw; HObject ho_TmpObj_DomainTransformed, ho_TmpObj_ImageTransformed; HObject ho_TmpObj_ImageTransformedExpanded, ho_TmpObj_ImageTransformedReduced; HObject ho_Symbols_OCR_01_0; // Local control variables HTuple hv_TmpCtrl_MatrixIdentity = new HTuple(); HTuple hv_TmpCtrl_ClipRegion = new HTuple(), hv_TmpCtrl_Row1 = new HTuple(); HTuple hv_TmpCtrl_Col1 = new HTuple(), hv_TmpCtrl_Row2 = new HTuple(); HTuple hv_TmpCtrl_Col2 = new HTuple(), hv_TmpCtrl_MatrixTranslation = new HTuple(); HTuple hv_TmpCtrl_MatrixComposite = new HTuple(), hv_TmpCtrl_ResultHandle_OCR_01_0 = new HTuple(); HTuple hv_OcrHandle_COPY_INP_TMP = new HTuple(hv_OcrHandle); HTuple hv_TextModel_COPY_INP_TMP = new HTuple(hv_TextModel); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_TmpObj_Mono); HOperatorSet.GenEmptyObj(out ho_TmpObj_MonoReduced_OCR_01_0); HOperatorSet.GenEmptyObj(out ho_TmpObj_Domain); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainExpanded); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainTransformedRaw); HOperatorSet.GenEmptyObj(out ho_TmpObj_DomainTransformed); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformed); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformedExpanded); HOperatorSet.GenEmptyObj(out ho_TmpObj_ImageTransformedReduced); HOperatorSet.GenEmptyObj(out ho_Symbols_OCR_01_0); hv_SymbolNames_OCR_01_0 = new HTuple(); hv_Ocr_Split = new HTuple(); //OCR 01: Code generated by OCR 01 //OCR 01: //OCR 01: Prepare text model //OCR 01: if ((int)(new HTuple(hv_TextModel_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0) { hv_TextModel_COPY_INP_TMP.Dispose(); HOperatorSet.CreateTextModelReader("manual", new HTuple(), out hv_TextModel_COPY_INP_TMP); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_stroke_width", 5); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_fragment_size_min", 5); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_eliminate_border_blobs", "true"); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_base_line_tolerance", 0.2); HOperatorSet.SetTextModelParam(hv_TextModel_COPY_INP_TMP, "manual_max_line_num", 2); } //OCR 01: //OCR 01: Load classifier //OCR 01: if ((int)(new HTuple(hv_OcrHandle_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0) { hv_OcrHandle_COPY_INP_TMP.Dispose(); HOperatorSet.ReadOcrClassSvm("C:/Users/iwake/OneDrive - wake/Desktop/OCR/NumOcrTrainBlck.osc", out hv_OcrHandle_COPY_INP_TMP); } //OCR 01: //OCR 01: Extract symbol regions (segmentation step) //OCR 01: Only consider first channel for color images ho_TmpObj_Mono.Dispose(); HOperatorSet.AccessChannel(ho_Image, out ho_TmpObj_Mono, 1); ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); HOperatorSet.ReduceDomain(ho_TmpObj_Mono, ho_ROI_OCR_01_0, out ho_TmpObj_MonoReduced_OCR_01_0 ); //OCR 01: //OCR 01: Orientation Correction (for consistent border and domain //OCR 01: handling, this is always applied, even with no rotation) //OCR 01: hv_TmpCtrl_MatrixIdentity.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_TmpCtrl_MatrixIdentity); //OCR 01: Apply transformation to image and domain ho_TmpObj_Domain.Dispose(); HOperatorSet.GetDomain(ho_TmpObj_MonoReduced_OCR_01_0, out ho_TmpObj_Domain); hv_TmpCtrl_ClipRegion.Dispose(); HOperatorSet.GetSystem("clip_region", out hv_TmpCtrl_ClipRegion); HOperatorSet.SetSystem("clip_region", "false"); ho_TmpObj_DomainExpanded.Dispose(); HOperatorSet.DilationCircle(ho_TmpObj_Domain, out ho_TmpObj_DomainExpanded, 25); ho_TmpObj_DomainTransformedRaw.Dispose(); HOperatorSet.AffineTransRegion(ho_TmpObj_DomainExpanded, out ho_TmpObj_DomainTransformedRaw, hv_TmpCtrl_MatrixIdentity, "true"); hv_TmpCtrl_Row1.Dispose(); hv_TmpCtrl_Col1.Dispose(); hv_TmpCtrl_Row2.Dispose(); hv_TmpCtrl_Col2.Dispose(); HOperatorSet.SmallestRectangle1(ho_TmpObj_DomainTransformedRaw, out hv_TmpCtrl_Row1, out hv_TmpCtrl_Col1, out hv_TmpCtrl_Row2, out hv_TmpCtrl_Col2); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_TmpCtrl_MatrixTranslation.Dispose(); HOperatorSet.HomMat2dTranslate(hv_TmpCtrl_MatrixIdentity, -hv_TmpCtrl_Row1, -hv_TmpCtrl_Col1, out hv_TmpCtrl_MatrixTranslation); } hv_TmpCtrl_MatrixComposite.Dispose(); HOperatorSet.HomMat2dCompose(hv_TmpCtrl_MatrixTranslation, hv_TmpCtrl_MatrixIdentity, out hv_TmpCtrl_MatrixComposite); ho_TmpObj_DomainTransformed.Dispose(); HOperatorSet.AffineTransRegion(ho_TmpObj_Domain, out ho_TmpObj_DomainTransformed, hv_TmpCtrl_MatrixComposite, "true"); ho_TmpObj_ImageTransformed.Dispose(); HOperatorSet.AffineTransImage(ho_TmpObj_MonoReduced_OCR_01_0, out ho_TmpObj_ImageTransformed, hv_TmpCtrl_MatrixComposite, "constant", "true"); ho_TmpObj_DomainExpanded.Dispose(); HOperatorSet.DilationCircle(ho_TmpObj_Domain, out ho_TmpObj_DomainExpanded, 25); ho_TmpObj_ImageTransformedExpanded.Dispose(); HOperatorSet.ExpandDomainGray(ho_TmpObj_ImageTransformed, out ho_TmpObj_ImageTransformedExpanded, 25); ho_TmpObj_ImageTransformedReduced.Dispose(); HOperatorSet.ReduceDomain(ho_TmpObj_ImageTransformed, ho_TmpObj_DomainTransformed, out ho_TmpObj_ImageTransformedReduced); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); HOperatorSet.CropPart(ho_TmpObj_ImageTransformedReduced, out ho_TmpObj_MonoReduced_OCR_01_0, 0, 0, (hv_TmpCtrl_Col2 - hv_TmpCtrl_Col1) + 1, (hv_TmpCtrl_Row2 - hv_TmpCtrl_Row1) + 1); } HOperatorSet.SetSystem("clip_region", hv_TmpCtrl_ClipRegion); hv_TmpCtrl_ResultHandle_OCR_01_0.Dispose(); HOperatorSet.FindText(ho_TmpObj_MonoReduced_OCR_01_0, hv_TextModel_COPY_INP_TMP, out hv_TmpCtrl_ResultHandle_OCR_01_0); //OCR 01: //OCR 01: Read text (classification step) ho_Symbols_OCR_01_0.Dispose(); HOperatorSet.GetTextObject(out ho_Symbols_OCR_01_0, hv_TmpCtrl_ResultHandle_OCR_01_0, "manual_all_lines"); //dev_display (TmpObj_MonoReduced_OCR_01_0) //dev_set_draw ('fill') //dev_set_colored (3) //dev_display (Symbols_OCR_01_0) hv_SymbolNames_OCR_01_0.Dispose(); HOperatorSet.DoOcrMultiClassSvm(ho_Symbols_OCR_01_0, ho_TmpObj_MonoReduced_OCR_01_0, hv_OcrHandle_COPY_INP_TMP, out hv_SymbolNames_OCR_01_0); hv_Ocr_Split.Dispose(); ocr_split(hv_SymbolNames_OCR_01_0, out hv_Ocr_Split); ho_TmpObj_Mono.Dispose(); ho_TmpObj_MonoReduced_OCR_01_0.Dispose(); ho_TmpObj_Domain.Dispose(); ho_TmpObj_DomainExpanded.Dispose(); ho_TmpObj_DomainTransformedRaw.Dispose(); ho_TmpObj_DomainTransformed.Dispose(); ho_TmpObj_ImageTransformed.Dispose(); ho_TmpObj_ImageTransformedExpanded.Dispose(); ho_TmpObj_ImageTransformedReduced.Dispose(); ho_Symbols_OCR_01_0.Dispose(); hv_OcrHandle_COPY_INP_TMP.Dispose(); hv_TextModel_COPY_INP_TMP.Dispose(); hv_TmpCtrl_MatrixIdentity.Dispose(); hv_TmpCtrl_ClipRegion.Dispose(); hv_TmpCtrl_Row1.Dispose(); hv_TmpCtrl_Col1.Dispose(); hv_TmpCtrl_Row2.Dispose(); hv_TmpCtrl_Col2.Dispose(); hv_TmpCtrl_MatrixTranslation.Dispose(); hv_TmpCtrl_MatrixComposite.Dispose(); hv_TmpCtrl_ResultHandle_OCR_01_0.Dispose(); return; }
private void checkModel(HObject ho_Image1) { HTuple hv_Row = new HTuple(); HTuple hv_Column = new HTuple(); HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_ModelID1 = new HTuple(), hv_ModelID2 = new HTuple(); HTuple hv_ModelID3 = new HTuple(), hv_ModelID4 = new HTuple(); HTuple hv_ModelIDs = new HTuple(), hv_Angle = new HTuple(); HTuple hv_Score = new HTuple(), hv_ModelIndex = new HTuple(); hv_ModelID1.Dispose(); HOperatorSet.ReadShapeModel("f:modelFiles/" + modelList.SelectedItem.ToString() + "/modle1.shm", out hv_ModelID1); hv_ModelID2.Dispose(); HOperatorSet.ReadShapeModel("f:modelFiles/" + modelList.SelectedItem.ToString() + "/modle2.shm", out hv_ModelID2); hv_ModelID3.Dispose(); HOperatorSet.ReadShapeModel("f:modelFiles/" + modelList.SelectedItem.ToString() + "/modle3.shm", out hv_ModelID3); hv_ModelID4.Dispose(); HOperatorSet.ReadShapeModel("f:modelFiles/" + modelList.SelectedItem.ToString() + "/modle4.shm", out hv_ModelID4); hv_ModelIDs.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ModelIDs = new HTuple(); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID1); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID2); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID3); hv_ModelIDs = hv_ModelIDs.TupleConcat(hv_ModelID4); } HOperatorSet.GetImageSize(ho_Image1, out hv_Width, out hv_Height); if (hWindowControl1.HalconWindow.ToString() == "") { return; } HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, hv_Width + 1, hv_Height + 1); HOperatorSet.DispObj(ho_Image1, hWindowControl1.HalconWindow); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); hv_ModelIndex.Dispose(); HOperatorSet.FindShapeModels(ho_Image1, hv_ModelIDs, 0, (new HTuple(360)).TupleRad() , 0.5, 8, 0.5, "least_squares", 0, 0.8, out hv_Row, out hv_Column, out hv_Angle, out hv_Score, out hv_ModelIndex); if ((int)(new HTuple(hv_Score.TupleGreater(0))) != 0) { pictureBox1.BackColor = Color.Green; a++; TrueNum.Text = a + "个"; } else { pictureBox1.BackColor = Color.Red; b++; WrongNum.Text = b + "个"; } c = a + b; allNum.Text = c + "个"; /* ho_Image1.Dispose(); * hv_AcqHandle.Dispose(); * hv_Row.Dispose(); * hv_Column.Dispose(); * hv_ModelID1.Dispose(); * hv_ModelID2.Dispose(); * hv_ModelID3.Dispose(); * hv_ModelID4.Dispose(); * hv_ModelIDs.Dispose(); * hv_Angle.Dispose(); * hv_Score.Dispose(); * hv_ModelIndex.Dispose();*/ }
// Procedures public void mia_sign(HObject ho_Image4, HTuple hv_HeadSignRow, HTuple hv_HeadSignCol, HTuple hv_WindowHandle, HTuple hv_SignWidth, out HTuple hv_sign) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_RoiSign1, ho_RoiSign2, ho_RoiSign3; HObject ho_RoiSign, ho_SignFeat; // Local control variables HTuple hv_SignWidthNormal = new HTuple(), hv_SignScale = new HTuple(); HTuple hv_HeadWidth = new HTuple(), hv_HeadHeight = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_RoiSign1); HOperatorSet.GenEmptyObj(out ho_RoiSign2); HOperatorSet.GenEmptyObj(out ho_RoiSign3); HOperatorSet.GenEmptyObj(out ho_RoiSign); HOperatorSet.GenEmptyObj(out ho_SignFeat); hv_sign = new HTuple(); //----Package //* 无倾斜 //* 数据适配CWDL hv_SignWidthNormal.Dispose(); hv_SignWidthNormal = 2200; hv_SignScale.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SignScale = hv_SignWidth / hv_SignWidthNormal; } hv_HeadWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadWidth = hv_SignScale * 300; } hv_HeadHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadHeight = hv_SignScale * 150; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign1.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign1, hv_HeadSignRow + (0.4 * hv_HeadHeight), hv_HeadSignCol + (0.17 * hv_SignWidth), (new HTuple(0)).TupleRad(), hv_HeadWidth / 2, hv_HeadHeight / 2); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign2.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign2, hv_HeadSignRow + (0.4 * hv_HeadHeight), hv_HeadSignCol + (0.38 * hv_SignWidth), (new HTuple(0)).TupleRad(), hv_HeadWidth / 2, hv_HeadHeight / 2); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign3.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign3, hv_HeadSignRow + (0.4 * hv_HeadHeight), hv_HeadSignCol + (0.62 * hv_SignWidth), (new HTuple(0)).TupleRad(), hv_HeadWidth / 2, hv_HeadHeight / 2); } ho_RoiSign.Dispose(); HOperatorSet.GenEmptyObj(out ho_RoiSign); { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign1, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign2, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign3, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } //concat_obj (RoiSign4, RoiSign, RoiSign) //* Judgement ho_SignFeat.Dispose(); hv_sign.Dispose(); image_judge_sign_judge(ho_RoiSign, ho_Image4, out ho_SignFeat, out hv_sign); //** Display HOperatorSet.DispObj(ho_SignFeat, hv_ExpDefaultWinHandle); //stop () ho_RoiSign1.Dispose(); ho_RoiSign2.Dispose(); ho_RoiSign3.Dispose(); ho_RoiSign.Dispose(); ho_SignFeat.Dispose(); hv_SignWidthNormal.Dispose(); hv_SignScale.Dispose(); hv_HeadWidth.Dispose(); hv_HeadHeight.Dispose(); return; }
/// <summary> /// 显示条形码 /// </summary> /// <param name="hv_WindowHandle"></param> /// <param name="hv_Size"></param> /// <param name="hv_Font"></param> /// <param name="hv_Bold"></param> /// <param name="hv_Slant"></param> // Chapter: Graphics / Text 图形/文本 // Short Description: Set font independent of OS 设置独立于操作系统的字体 public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant) { // Local iconic variables // Local control variables HTuple hv_OS = new HTuple(), hv_Fonts = new HTuple(); HTuple hv_Style = new HTuple(), hv_Exception = new HTuple(); HTuple hv_AvailableFonts = new HTuple(), hv_Fdx = new HTuple(); HTuple hv_Indices = new HTuple(); HTuple hv_Font_COPY_INP_TMP = new HTuple(hv_Font); HTuple hv_Size_COPY_INP_TMP = new HTuple(hv_Size); // Initialize local and output iconic variables //This procedure sets the text font of the current window with //the specified attributes. // //Input parameters: //WindowHandle: The graphics window for which the font will be set //Size: The font size. If Size=-1, the default of 16 is used. //Bold: If set to 'true', a bold font is used //Slant: If set to 'true', a slanted font is used // hv_OS.Dispose(); HOperatorSet.GetSystem("operating_system", out hv_OS); if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0) { hv_Size_COPY_INP_TMP.Dispose(); hv_Size_COPY_INP_TMP = 16; } if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0) { //Restore previous behaviour using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Size = ((1.13677 * hv_Size_COPY_INP_TMP)).TupleInt() ; hv_Size_COPY_INP_TMP.Dispose(); hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size; } } } else { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Size = hv_Size_COPY_INP_TMP.TupleInt() ; hv_Size_COPY_INP_TMP.Dispose(); hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size; } } } if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))) != 0) { hv_Fonts.Dispose(); hv_Fonts = new HTuple(); hv_Fonts[0] = "Courier"; hv_Fonts[1] = "Courier 10 Pitch"; hv_Fonts[2] = "Courier New"; hv_Fonts[3] = "CourierNew"; hv_Fonts[4] = "Liberation Mono"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0) { hv_Fonts.Dispose(); hv_Fonts = new HTuple(); hv_Fonts[0] = "Consolas"; hv_Fonts[1] = "Menlo"; hv_Fonts[2] = "Courier"; hv_Fonts[3] = "Courier 10 Pitch"; hv_Fonts[4] = "FreeMono"; hv_Fonts[5] = "Liberation Mono"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Fonts.Dispose(); hv_Fonts = new HTuple(); hv_Fonts[0] = "Luxi Sans"; hv_Fonts[1] = "DejaVu Sans"; hv_Fonts[2] = "FreeSans"; hv_Fonts[3] = "Arial"; hv_Fonts[4] = "Liberation Sans"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Fonts.Dispose(); hv_Fonts = new HTuple(); hv_Fonts[0] = "Times New Roman"; hv_Fonts[1] = "Luxi Serif"; hv_Fonts[2] = "DejaVu Serif"; hv_Fonts[3] = "FreeSerif"; hv_Fonts[4] = "Utopia"; hv_Fonts[5] = "Liberation Serif"; } else { hv_Fonts.Dispose(); hv_Fonts = new HTuple(hv_Font_COPY_INP_TMP); } hv_Style.Dispose(); hv_Style = ""; if ((int)(new HTuple(hv_Bold.TupleEqual("true"))) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Style = hv_Style + "Bold"; hv_Style.Dispose(); hv_Style = ExpTmpLocalVar_Style; } } } else if ((int)(new HTuple(hv_Bold.TupleNotEqual("false"))) != 0) { hv_Exception.Dispose(); hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant.TupleEqual("true"))) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Style = hv_Style + "Italic"; hv_Style.Dispose(); hv_Style = ExpTmpLocalVar_Style; } } } else if ((int)(new HTuple(hv_Slant.TupleNotEqual("false"))) != 0) { hv_Exception.Dispose(); hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Style.TupleEqual(""))) != 0) { hv_Style.Dispose(); hv_Style = "Normal"; } hv_AvailableFonts.Dispose(); HOperatorSet.QueryFont(hv_WindowHandle, out hv_AvailableFonts); hv_Font_COPY_INP_TMP.Dispose(); hv_Font_COPY_INP_TMP = ""; for (hv_Fdx = 0; (int)hv_Fdx <= (int)((new HTuple(hv_Fonts.TupleLength())) - 1); hv_Fdx = (int)hv_Fdx + 1) { hv_Indices.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Indices = hv_AvailableFonts.TupleFind( hv_Fonts.TupleSelect(hv_Fdx)); } if ((int)(new HTuple((new HTuple(hv_Indices.TupleLength())).TupleGreater(0))) != 0) { if ((int)(new HTuple(((hv_Indices.TupleSelect(0))).TupleGreaterEqual(0))) != 0) { hv_Font_COPY_INP_TMP.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect( hv_Fdx); } break; } } } if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(""))) != 0) { throw new HalconException("Wrong value of control parameter Font"); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Font = (((hv_Font_COPY_INP_TMP + "-") + hv_Style) + "-") + hv_Size_COPY_INP_TMP; hv_Font_COPY_INP_TMP.Dispose(); hv_Font_COPY_INP_TMP = ExpTmpLocalVar_Font; } } HOperatorSet.SetFont(hv_WindowHandle, hv_Font_COPY_INP_TMP); hv_Font_COPY_INP_TMP.Dispose(); hv_Size_COPY_INP_TMP.Dispose(); hv_OS.Dispose(); hv_Fonts.Dispose(); hv_Style.Dispose(); hv_Exception.Dispose(); hv_AvailableFonts.Dispose(); hv_Fdx.Dispose(); hv_Indices.Dispose(); return; }
// Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_ModelRegion, ho_TemplateImage; HObject ho_ModelContours, ho_RectifiedImage = null, ho_Regions = null; HObject ho_ConnectedRegions = null, ho_SelectedRegions = null; HObject ho_Contours = null, ho_Regions1 = null, ho_RegionLines = null; // Local control variables HTuple hv_ModelID = new HTuple(), hv_ModelRegionArea = new HTuple(); HTuple hv_RefRow = new HTuple(), hv_RefColumn = new HTuple(); HTuple hv_TestImages = new HTuple(), hv_T = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Angle = new HTuple(), hv_Score = new HTuple(); HTuple hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple(); HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple(); HTuple hv_Radius = new HTuple(), hv_MetrologyHandle = new HTuple(); HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_Index = new HTuple(), hv_Row3 = new HTuple(); HTuple hv_Column3 = new HTuple(), hv_Parameter = new HTuple(); HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_MetrologyHandle1 = new HTuple(); HTuple hv_Index1 = new HTuple(), hv_Parameter1 = new HTuple(); HTuple hv_SmlC = new HTuple(), hv_SR = new HTuple(), hv_SC = new HTuple(); HTuple hv_BR = new HTuple(), hv_BC = new HTuple(), hv_Distance = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ModelRegion); HOperatorSet.GenEmptyObj(out ho_TemplateImage); HOperatorSet.GenEmptyObj(out ho_ModelContours); HOperatorSet.GenEmptyObj(out ho_RectifiedImage); HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_Regions1); HOperatorSet.GenEmptyObj(out ho_RegionLines); // //Matching 01: ************************************************ //Matching 01: BEGIN of generated code for model initialization //Matching 01: ************************************************ HOperatorSet.SetSystem("border_shape_models", "false"); // //Matching 01: Obtain the model image ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "C:/Users/Chanru/Desktop/Class/bd/bd1.png"); // //Matching 01: Build the ROI from basic regions ho_ModelRegion.Dispose(); HOperatorSet.GenRectangle1(out ho_ModelRegion, 445.809, 637.592, 801.311, 1070.62); // //Matching 01: Reduce the model template ho_TemplateImage.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_ModelRegion, out ho_TemplateImage); // //Matching 01: Create the shape model hv_ModelID.Dispose(); HOperatorSet.CreateShapeModel(ho_TemplateImage, 6, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), (new HTuple(0.4233)).TupleRad(), (new HTuple("point_reduction_medium")).TupleConcat( "no_pregeneration"), "use_polarity", ((new HTuple(10)).TupleConcat(14)).TupleConcat( 35), 3, out hv_ModelID); // //Matching 01: Get the model contour for transforming it later into the image ho_ModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelID, 1); // //Matching 01: Get the reference position hv_ModelRegionArea.Dispose(); hv_RefRow.Dispose(); hv_RefColumn.Dispose(); HOperatorSet.AreaCenter(ho_ModelRegion, out hv_ModelRegionArea, out hv_RefRow, out hv_RefColumn); // //Matching 01: END of generated code for model initialization //Matching 01: * * * * * * * * * * * * * * * * * * * * * * * //Matching 01: BEGIN of generated code for model application // //Matching 01: Loop over all specified test images hv_TestImages.Dispose(); hv_TestImages = new HTuple(); hv_TestImages[0] = "C:/Users/Chanru/Desktop/Class/bd/bd1.png"; hv_TestImages[1] = "C:/Users/Chanru/Desktop/Class/bd/bd10.png"; hv_TestImages[2] = "C:/Users/Chanru/Desktop/Class/bd/bd2.png"; hv_TestImages[3] = "C:/Users/Chanru/Desktop/Class/bd/bd3.png"; hv_TestImages[4] = "C:/Users/Chanru/Desktop/Class/bd/bd4.png"; hv_TestImages[5] = "C:/Users/Chanru/Desktop/Class/bd/bd5.png"; hv_TestImages[6] = "C:/Users/Chanru/Desktop/Class/bd/bd6.png"; hv_TestImages[7] = "C:/Users/Chanru/Desktop/Class/bd/bd7.png"; hv_TestImages[8] = "C:/Users/Chanru/Desktop/Class/bd/bd8.png"; hv_TestImages[9] = "C:/Users/Chanru/Desktop/Class/bd/bd9.png"; for (hv_T = 0; (int)hv_T <= 9; hv_T = (int)hv_T + 1) { // //Matching 01: Obtain the test image ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, hv_TestImages.TupleSelect(hv_T)); // //Matching 01: Find the model hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_ModelID, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.5, 0, 0.5, "least_squares", (new HTuple(6)).TupleConcat( 1), 0.75, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); // //Matching 01: Code for rectification of the image //Matching 01: Calculate an inverse hom_mat2d for each of the matching results for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Score.TupleLength())) - 1); hv_I = (int)hv_I + 1) { hv_RectificationHomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_RectificationHomMat2D); { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dTranslate(hv_RectificationHomMat2D, hv_RefRow - (hv_Row.TupleSelect( hv_I)), hv_RefColumn - (hv_Column.TupleSelect(hv_I)), out ExpTmpOutVar_0); hv_RectificationHomMat2D.Dispose(); hv_RectificationHomMat2D = ExpTmpOutVar_0; } { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dRotate(hv_RectificationHomMat2D, -(hv_Angle.TupleSelect( hv_I)), hv_RefRow, hv_RefColumn, out ExpTmpOutVar_0); hv_RectificationHomMat2D.Dispose(); hv_RectificationHomMat2D = ExpTmpOutVar_0; } ho_RectifiedImage.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_RectifiedImage, hv_RectificationHomMat2D, "constant", "false"); // //Matching 01: Insert your code using the rectified image here ho_Regions.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_Regions, 99, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 150, 800); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Radius.Dispose(); HOperatorSet.SmallestCircle(ho_SelectedRegions, out hv_Row1, out hv_Column1, out hv_Radius); hv_MetrologyHandle.Dispose(); HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle); hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_RectifiedImage, out hv_Width, out hv_Height); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle, hv_Width, hv_Height); hv_Index.Dispose(); HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row1, hv_Column1, hv_Radius, 20, 5, 1, 30, "num_measures", 30, out hv_Index); HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle); ho_Contours.Dispose(); hv_Row3.Dispose(); hv_Column3.Dispose(); HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours, hv_MetrologyHandle, "all", "all", out hv_Row3, out hv_Column3); hv_Parameter.Dispose(); HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter); //********* ho_Regions1.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_Regions1, 22, 78); hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Radius1.Dispose(); HOperatorSet.SmallestCircle(ho_Regions1, out hv_Row2, out hv_Column2, out hv_Radius1); hv_MetrologyHandle1.Dispose(); HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle1); HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle1, hv_Width, hv_Height); hv_Index1.Dispose(); HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle1, hv_Row2, hv_Column2, hv_Radius1, 20, 5, 1, 30, new HTuple(), new HTuple(), out hv_Index1); HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle1); hv_Parameter1.Dispose(); HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle1, "all", "all", "result_type", "all_param", out hv_Parameter1); //******* hv_SmlC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SmlC = HTuple.TupleGenSequence( 0, (new HTuple(hv_Parameter.TupleLength())) - 1, 3); } hv_SR.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SR = hv_Parameter.TupleSelect( hv_SmlC); } hv_SC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SC = hv_Parameter.TupleSelect( hv_SmlC + 1); } hv_BR.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_BR = (hv_SR * 0) + (hv_Parameter1.TupleSelect( 0)); } hv_BC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_BC = (hv_SC * 0) + (hv_Parameter1.TupleSelect( 1)); } hv_Distance.Dispose(); HOperatorSet.DistancePp(hv_SR, hv_SC, hv_BR, hv_BC, out hv_Distance); if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_RectifiedImage, HDevWindowStack.GetActive()); } ho_RegionLines.Dispose(); HOperatorSet.GenRegionLine(out ho_RegionLines, hv_SR, hv_SC, hv_BR, hv_BC); // stop(...); only in hdevelop } } // //Matching 01: ******************************************* //Matching 01: END of generated code for model application //Matching 01: ******************************************* // ho_Image.Dispose(); ho_ModelRegion.Dispose(); ho_TemplateImage.Dispose(); ho_ModelContours.Dispose(); ho_RectifiedImage.Dispose(); ho_Regions.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Contours.Dispose(); ho_Regions1.Dispose(); ho_RegionLines.Dispose(); hv_ModelID.Dispose(); hv_ModelRegionArea.Dispose(); hv_RefRow.Dispose(); hv_RefColumn.Dispose(); hv_TestImages.Dispose(); hv_T.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); hv_I.Dispose(); hv_RectificationHomMat2D.Dispose(); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Radius.Dispose(); hv_MetrologyHandle.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); hv_Index.Dispose(); hv_Row3.Dispose(); hv_Column3.Dispose(); hv_Parameter.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Radius1.Dispose(); hv_MetrologyHandle1.Dispose(); hv_Index1.Dispose(); hv_Parameter1.Dispose(); hv_SmlC.Dispose(); hv_SR.Dispose(); hv_SC.Dispose(); hv_BR.Dispose(); hv_BC.Dispose(); hv_Distance.Dispose(); }
// Procedures public void image_get_bar(HObject ho_Image, out HObject ho_SymbolRegions, HTuple hv_BarCodeHandle, HTuple hv_WindowHandle, out HTuple hv_DecodedDataStrings, out HTuple hv_someitem) { // Local iconic variables HObject ho_ObjectSelected = null; // Local control variables HTuple hv_BarWidth = new HTuple(), hv_BarHeight = new HTuple(); HTuple hv_CodeTypes = new HTuple(), hv_BarIndex = new HTuple(); HTuple hv_BarcodeArea = new HTuple(), hv_BarcodeRow = new HTuple(); HTuple hv_BarcodeColumn = new HTuple(), hv_BarRatio = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); hv_DecodedDataStrings = new HTuple(); hv_someitem = new HTuple(); // //Use autodiscrimination to decode any of the bar code types //supported by HALCON (except PharmaCode) or determine the bar //code type of unknown bar codes // //* INIT CONST //BarWidth := 800 //BarHeight := 100 hv_CodeTypes.Dispose(); hv_CodeTypes = "Code 128"; //CodeTypes := ['auto'] //read_bar_code_model ('C:/Users/iwake/OneDrive - wake/Desktop/HalconPractise/HalconProj/Barcode/BarCodeHandle.bcm', BarCodeHandle) //read_bar_code_model ('BarCodeHandle.bcm', BarCodeHandle) //set_bar_code_param (BarCodeHandle, 'check_char', 'present') // //Set display defaults //get_image_size (Image, Width, Height) // //Find and decode bar codes. Measure the time needed. ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); HOperatorSet.FindBarCode(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, hv_CodeTypes, out hv_DecodedDataStrings); //get_bar_code_result (BarCodeHandle, 'all', 'someitem', someitem) //* DISPLAY BARCODE set_display_font(hv_ExpDefaultWinHandle, 14, "mono", "true", "false"); HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin"); HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 3); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "forest green"); HOperatorSet.DispObj(ho_SymbolRegions, hv_ExpDefaultWinHandle); for (hv_BarIndex = 1; (int)hv_BarIndex <= (int)(new HTuple(hv_DecodedDataStrings.TupleLength() )); hv_BarIndex = (int)hv_BarIndex + 1) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SymbolRegions, out ho_ObjectSelected, hv_BarIndex); hv_BarcodeArea.Dispose(); hv_BarcodeRow.Dispose(); hv_BarcodeColumn.Dispose(); HOperatorSet.AreaCenter(ho_SymbolRegions, out hv_BarcodeArea, out hv_BarcodeRow, out hv_BarcodeColumn); hv_BarHeight.Dispose(); hv_BarWidth.Dispose(); hv_BarRatio.Dispose(); HOperatorSet.HeightWidthRatio(ho_ObjectSelected, out hv_BarHeight, out hv_BarWidth, out hv_BarRatio); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_BarcodeRow - hv_BarHeight, hv_BarcodeColumn - (0.5 * hv_BarWidth)); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_DecodedDataStrings.TupleSelect( hv_BarIndex - 1)); } } hv_someitem.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_someitem = new HTuple(); hv_someitem = hv_someitem.TupleConcat(hv_BarcodeRow, hv_BarcodeColumn); } ho_ObjectSelected.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_CodeTypes.Dispose(); hv_BarIndex.Dispose(); hv_BarcodeArea.Dispose(); hv_BarcodeRow.Dispose(); hv_BarcodeColumn.Dispose(); hv_BarRatio.Dispose(); return; }
// Main procedure private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_InfoModelContours, ho_SignModelContours; HObject ho_Image = null, ho_SymbolRegions = null, ho_ROI_OCR_01_0 = null; HObject ho_ObjectSelected = null, ho_InfoTransContours = null; HObject ho_SignTransContours = null; // Local control variables HTuple hv_BarWidth = new HTuple(), hv_BarHeight = new HTuple(); HTuple hv_BarCodeHandle = new HTuple(), hv_InfoModel = new HTuple(); HTuple hv_SignModel = new HTuple(), hv_WindowHandle = new HTuple(); //HTuple hv_AcqHandle = new HTuple(), hv_InfoRow = new HTuple(); HTuple hv_InfoRow = new HTuple(); HTuple hv_InfoColumn = new HTuple(), hv_InfoAngle = new HTuple(); HTuple hv_InfoScore = new HTuple(), hv_DecodedDataStrings = new HTuple(); HTuple hv_someitem = new HTuple(), hv_SignRow = new HTuple(); HTuple hv_SignColumn = new HTuple(), hv_SignAngle = new HTuple(); HTuple hv_SignScore = new HTuple(), hv_SymbolNames_OCR_01_0 = new HTuple(); HTuple hv_Ocr_Split = new HTuple(), hv_Area = new HTuple(); HTuple hv_IDRow = new HTuple(), hv_IDColumn = new HTuple(); HTuple hv_IDRow1 = new HTuple(), hv_IDColumn1 = new HTuple(); HTuple hv_IDRow2 = new HTuple(), hv_IDColumn2 = new HTuple(); HTuple hv_IDHeight = new HTuple(), hv_IDWidth = new HTuple(); HTuple hv_IDRatio = new HTuple(), hv_BarIndex = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_InfoHomMat2D = new HTuple(), hv_SignHomMat2D = new HTuple(); HTuple hv_Exception = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_InfoModelContours); HOperatorSet.GenEmptyObj(out ho_SignModelContours); HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ROI_OCR_01_0); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_InfoTransContours); HOperatorSet.GenEmptyObj(out ho_SignTransContours); try { //*** //** INIT //* INIT CONST hv_BarWidth.Dispose(); hv_BarWidth = 800; hv_BarHeight.Dispose(); hv_BarHeight = 100; //* INIT IMAGE //ImageFiles := [] //ImageFiles[0] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (1).bmp' //ImageFiles[1] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (2).bmp' //ImageFiles[2] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (3).bmp' //ImageFiles[3] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (4).bmp' //ImageFiles[4] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (5).bmp' //ImageFiles[5] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (6).bmp' //ImageFiles[6] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (7).bmp' //ImageFiles[7] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (8).bmp' //ImageFiles[8] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (9).bmp' //ImageFiles[9] := 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/CaliInvV1 (10).bmp' //tuple_length (ImageFiles, Length) //* INIT BARCODE hv_BarCodeHandle.Dispose(); HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true"); //* INIT LOC //* Info: hv_InfoModel.Dispose(); HOperatorSet.ReadShapeModel("C:/Users/iwake/OneDrive - wake/Desktop/Localization/InvV1CaliInfo.shm", out hv_InfoModel); ho_InfoModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_InfoModelContours, hv_InfoModel, 1); //* Sign hv_SignModel.Dispose(); HOperatorSet.ReadShapeModel("C:/Users/iwake/OneDrive - wake/Desktop/Localization/InvV1CaliSign.shm", out hv_SignModel); ho_SignModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_SignModelContours, hv_SignModel, 1); //*** //** DISPLAY //* DISPLAY INIT dev_update_off(); //dev_close_window(...); //dev_open_window(...); //*** //** LOOP //Image Acquisition 01: Code generated by Image Acquisition 01 hv_AcqHandle.Dispose(); HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", "c42f90f2b7fa_Hikvision_MVCE12010GM", 0, -1, out hv_AcqHandle); while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle); { HObject ExpTmpOutVar_0; image_cali_map(ho_Image, out ExpTmpOutVar_0, new HTuple(), new HTuple()); ho_Image.Dispose(); ho_Image = ExpTmpOutVar_0; HOperatorSet.DispObj(ho_Image, hv_ExpImageRawWinHandle); } try { //** PRE using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_InfoModel, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat( 1), 0.6, out hv_InfoRow, out hv_InfoColumn, out hv_InfoAngle, out hv_InfoScore); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HObject ExpTmpOutVar_0; HOperatorSet.RotateImage(ho_Image, out ExpTmpOutVar_0, ((-hv_InfoAngle)).TupleDeg() , "constant"); ho_Image.Dispose(); ho_Image = ExpTmpOutVar_0; } HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle); //** RECOGNITION //* BARCODE ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, out hv_DecodedDataStrings, out hv_someitem); //* LOC //* Info: using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_InfoModel, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat( 1), 0.7, out hv_InfoRow, out hv_InfoColumn, out hv_InfoAngle, out hv_InfoScore); } //* Sign using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_SignModel, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat( 1), 0.7, out hv_SignRow, out hv_SignColumn, out hv_SignAngle, out hv_SignScore); } //* Ocr using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ROI_OCR_01_0.Dispose(); HOperatorSet.GenRectangle2(out ho_ROI_OCR_01_0, hv_InfoRow + 70, hv_InfoColumn - 700, hv_InfoAngle, 100, 30); } hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); region_ocr_num_svm(ho_Image, ho_ROI_OCR_01_0, new HTuple(), new HTuple(), out hv_SymbolNames_OCR_01_0, out hv_Ocr_Split); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); HOperatorSet.AreaCenter(ho_ROI_OCR_01_0, out hv_Area, out hv_IDRow, out hv_IDColumn); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); HOperatorSet.SmallestRectangle1(ho_ROI_OCR_01_0, out hv_IDRow1, out hv_IDColumn1, out hv_IDRow2, out hv_IDColumn2); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); HOperatorSet.HeightWidthRatio(ho_ROI_OCR_01_0, out hv_IDHeight, out hv_IDWidth, out hv_IDRatio); //** DISPLAY //* DISPLAY BARCODE set_display_font(hv_ExpDefaultWinHandle, 14, "mono", "true", "false"); HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin"); HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 3); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "forest green"); HOperatorSet.DispObj(ho_SymbolRegions, hv_ExpDefaultWinHandle); for (hv_BarIndex = 1; (int)hv_BarIndex <= (int)(new HTuple(hv_DecodedDataStrings.TupleLength() )); hv_BarIndex = (int)hv_BarIndex + 1) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SymbolRegions, out ho_ObjectSelected, hv_BarIndex); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_Row - hv_BarHeight, hv_Column - (0.25 * hv_BarWidth)); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_DecodedDataStrings.TupleSelect( hv_BarIndex - 1)); } } //* DISPLAY LOC HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 1); //* Info: hv_InfoHomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_InfoHomMat2D); { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dRotate(hv_InfoHomMat2D, hv_InfoAngle, 0, 0, out ExpTmpOutVar_0); hv_InfoHomMat2D.Dispose(); hv_InfoHomMat2D = ExpTmpOutVar_0; } { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dTranslate(hv_InfoHomMat2D, hv_InfoRow, hv_InfoColumn, out ExpTmpOutVar_0); hv_InfoHomMat2D.Dispose(); hv_InfoHomMat2D = ExpTmpOutVar_0; } ho_InfoTransContours.Dispose(); HOperatorSet.AffineTransContourXld(ho_InfoModelContours, out ho_InfoTransContours, hv_InfoHomMat2D); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); HOperatorSet.DispObj(ho_InfoTransContours, hv_ExpDefaultWinHandle); //* Ocr using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.DispText(hv_ExpDefaultWinHandle, hv_Ocr_Split, "image", hv_IDRow1 + hv_IDHeight, hv_IDColumn1, "blue", new HTuple(), new HTuple()); } //* Sign hv_SignHomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_SignHomMat2D); { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dRotate(hv_SignHomMat2D, hv_SignAngle, 0, 0, out ExpTmpOutVar_0); hv_SignHomMat2D.Dispose(); hv_SignHomMat2D = ExpTmpOutVar_0; } { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dTranslate(hv_SignHomMat2D, hv_SignRow, hv_SignColumn, out ExpTmpOutVar_0); hv_SignHomMat2D.Dispose(); hv_SignHomMat2D = ExpTmpOutVar_0; } ho_SignTransContours.Dispose(); HOperatorSet.AffineTransContourXld(ho_SignModelContours, out ho_SignTransContours, hv_SignHomMat2D); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green"); HOperatorSet.DispObj(ho_SignTransContours, hv_ExpDefaultWinHandle); //stop () } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); } } HOperatorSet.CloseFramegrabber(hv_AcqHandle); } catch (HalconException HDevExpDefaultException) { ho_InfoModelContours.Dispose(); ho_SignModelContours.Dispose(); ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_ROI_OCR_01_0.Dispose(); ho_ObjectSelected.Dispose(); ho_InfoTransContours.Dispose(); ho_SignTransContours.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_BarCodeHandle.Dispose(); hv_InfoModel.Dispose(); hv_SignModel.Dispose(); hv_WindowHandle.Dispose(); hv_AcqHandle.Dispose(); hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_InfoHomMat2D.Dispose(); hv_SignHomMat2D.Dispose(); hv_Exception.Dispose(); throw HDevExpDefaultException; } ho_InfoModelContours.Dispose(); ho_SignModelContours.Dispose(); ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_ROI_OCR_01_0.Dispose(); ho_ObjectSelected.Dispose(); ho_InfoTransContours.Dispose(); ho_SignTransContours.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_BarCodeHandle.Dispose(); hv_InfoModel.Dispose(); hv_SignModel.Dispose(); hv_WindowHandle.Dispose(); hv_AcqHandle.Dispose(); hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_InfoHomMat2D.Dispose(); hv_SignHomMat2D.Dispose(); hv_Exception.Dispose(); }
public void I40GetBaseRectsAndCreateNewModel(HObject ho_Modelright, HTuple hv_ModelID, out HTuple hv_ModelID1, out HTuple hv_rowVRect, out HTuple hv_colVRect, out HTuple hv_angleVRect, out HTuple hv_len1VRect, out HTuple hv_len2VRect, out HTuple hv_rowHRect, out HTuple hv_colHRect, out HTuple hv_angleHRect, out HTuple hv_len1HRect, out HTuple hv_len2HRect, out HTuple hv_RowNew, out HTuple hv_ColNew, out HTuple hv_RadianNew) { // Local iconic variables HObject ho_ROI_0, ho_ImageReduced, ho_Rectangle; HObject ho_ROI_NewModelArea, ho_ImageReduced1; // Local control variables HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Angle = new HTuple(), hv_Score = new HTuple(); HTuple hv_ScoreNew = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ROI_0); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ROI_NewModelArea); HOperatorSet.GenEmptyObj(out ho_ImageReduced1); hv_ModelID1 = new HTuple(); hv_rowVRect = new HTuple(); hv_colVRect = new HTuple(); hv_angleVRect = new HTuple(); hv_len1VRect = new HTuple(); hv_len2VRect = new HTuple(); hv_rowHRect = new HTuple(); hv_colHRect = new HTuple(); hv_angleHRect = new HTuple(); hv_len1HRect = new HTuple(); hv_len2HRect = new HTuple(); hv_RowNew = new HTuple(); hv_ColNew = new HTuple(); hv_RadianNew = new HTuple(); ho_ROI_0.Dispose(); HOperatorSet.GenRectangle1(out ho_ROI_0, 56.831, 111.206, 465.524, 1574.75); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Modelright, ho_ROI_0, out ho_ImageReduced); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); HOperatorSet.FindShapeModel(ho_ImageReduced, hv_ModelID, -0.39, 0.79, 0.2, 1, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row - 50, hv_Column - 500, hv_Row + 50, hv_Column + 500); } //create real-time shape model ho_ROI_NewModelArea.Dispose(); HOperatorSet.GenRectangle1(out ho_ROI_NewModelArea, 147.251, 517.11, 284.314, 1430.32); ho_ImageReduced1.Dispose(); HOperatorSet.ReduceDomain(ho_Modelright, ho_ROI_NewModelArea, out ho_ImageReduced1 ); hv_ModelID1.Dispose(); HOperatorSet.CreateShapeModel(ho_ImageReduced1, "auto", -0.39, 0.79, "auto", "auto", "use_polarity", "auto", "auto", out hv_ModelID1); hv_RowNew.Dispose(); hv_ColNew.Dispose(); hv_RadianNew.Dispose(); hv_ScoreNew.Dispose(); HOperatorSet.FindShapeModel(ho_ImageReduced1, hv_ModelID1, -0.39, 0.79, 0.5, 1, 0.5, "least_squares", 0, 0.9, out hv_RowNew, out hv_ColNew, out hv_RadianNew, out hv_ScoreNew); hv_rowVRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_rowVRect = hv_Row + 394; } hv_colVRect.Dispose(); hv_colVRect = new HTuple(hv_Column); hv_angleVRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_angleVRect = (new HTuple(-90)).TupleRad() ; } hv_len1VRect.Dispose(); hv_len1VRect = 20; hv_len2VRect.Dispose(); hv_len2VRect = 380; hv_colHRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_colHRect = hv_Column - 550; } hv_rowHRect.Dispose(); hv_rowHRect = new HTuple(hv_Row); hv_angleHRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_angleHRect = (new HTuple(-180)).TupleRad() ; } hv_len1HRect.Dispose(); hv_len1HRect = 20; hv_len2HRect.Dispose(); hv_len2HRect = 80; ho_ROI_0.Dispose(); ho_ImageReduced.Dispose(); ho_Rectangle.Dispose(); ho_ROI_NewModelArea.Dispose(); ho_ImageReduced1.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); hv_ScoreNew.Dispose(); return; }
public void region_judge_sign(HObject ho_Image4, out HObject ho_EDGE, HTuple hv_HeadSignScale, HTuple hv_HeadSignRow, HTuple hv_HeadSignCol, HTuple hv_HeadPhi, HTuple hv_WindowHandle, out HTuple hv_sign) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_ROI_0, ho_RoiSign1, ho_RoiSign2; HObject ho_RoiSign3, ho_RoiSign4, ho_RoiSign, ho_GrayImage; HObject ho_ObjectSelected = null, ho_ImageReduced = null, ho_Edges = null; // Local control variables HTuple hv_HeadWidth = new HTuple(), hv_HeadHeight = new HTuple(); HTuple hv_RoiSignScale = new HTuple(), hv_RoiSignWidth = new HTuple(); HTuple hv_RoiSignHeight = new HTuple(), hv_Rows = new HTuple(); HTuple hv_Columns = new HTuple(), hv_Index = new HTuple(); HTuple hv_Length = new HTuple(), hv_Length1 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_EDGE); HOperatorSet.GenEmptyObj(out ho_ROI_0); HOperatorSet.GenEmptyObj(out ho_RoiSign1); HOperatorSet.GenEmptyObj(out ho_RoiSign2); HOperatorSet.GenEmptyObj(out ho_RoiSign3); HOperatorSet.GenEmptyObj(out ho_RoiSign4); HOperatorSet.GenEmptyObj(out ho_RoiSign); HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Edges); hv_sign = new HTuple(); //----Package hv_HeadWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadWidth = hv_HeadSignScale * 1647; } hv_HeadHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadHeight = hv_HeadSignScale * 73; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ROI_0.Dispose(); HOperatorSet.GenRectangle2(out ho_ROI_0, hv_HeadSignRow, hv_HeadSignCol, hv_HeadPhi, hv_HeadWidth / 2, hv_HeadHeight / 2); } //* RoiSign hv_RoiSignScale.Dispose(); hv_RoiSignScale = 0.7; hv_RoiSignWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_RoiSignWidth = (hv_RoiSignScale * hv_HeadWidth) / 4; } hv_RoiSignHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_RoiSignHeight = hv_RoiSignScale * hv_HeadHeight; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign1.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign1, hv_HeadSignRow + hv_HeadHeight, hv_HeadSignCol - (0.175 * hv_HeadWidth), (new HTuple(0)).TupleRad(), hv_RoiSignWidth / 2, hv_RoiSignHeight / 2); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign2.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign2, hv_HeadSignRow + (3 * hv_HeadHeight), hv_HeadSignCol - (0.175 * hv_HeadWidth), (new HTuple(0)).TupleRad(), hv_RoiSignWidth / 2, hv_RoiSignHeight / 2); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign3.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign3, hv_HeadSignRow + hv_HeadHeight, hv_HeadSignCol + (0.355 * hv_HeadWidth), (new HTuple(0)).TupleRad(), hv_RoiSignWidth / 2, hv_RoiSignHeight / 2); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RoiSign4.Dispose(); HOperatorSet.GenRectangle2(out ho_RoiSign4, hv_HeadSignRow + (3 * hv_HeadHeight), hv_HeadSignCol + (0.355 * hv_HeadWidth), (new HTuple(0)).TupleRad(), hv_RoiSignWidth / 2, hv_RoiSignHeight / 2); } ho_RoiSign.Dispose(); HOperatorSet.GenEmptyObj(out ho_RoiSign); { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign1, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign2, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign3, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_RoiSign4, ho_RoiSign, out ExpTmpOutVar_0); ho_RoiSign.Dispose(); ho_RoiSign = ExpTmpOutVar_0; } //** Porg //* Pre ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(ho_Image4, out ho_GrayImage); hv_Rows.Dispose(); hv_Columns.Dispose(); HOperatorSet.GetRegionConvex(ho_ROI_0, out hv_Rows, out hv_Columns); ho_EDGE.Dispose(); HOperatorSet.GenEmptyObj(out ho_EDGE); //* Judgement for (hv_Index = 1; (int)hv_Index <= 4; hv_Index = (int)hv_Index + 1) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_RoiSign, out ho_ObjectSelected, hv_Index); //截取对应区域图片 ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image4, ho_ObjectSelected, out ho_ImageReduced ); //区域图片映射为轮廓 ho_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_Edges, "canny", 1, 20, 40); { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_Edges, ho_EDGE, out ExpTmpOutVar_0); ho_EDGE.Dispose(); ho_EDGE = ExpTmpOutVar_0; } //得到轮廓长度数组 hv_Length.Dispose(); HOperatorSet.LengthXld(ho_Edges, out hv_Length); //云团数目大于五则有签字 hv_Length1.Dispose(); HOperatorSet.TupleLength(hv_Length, out hv_Length1); if ((int)(new HTuple(hv_Length1.TupleGreater(5))) != 0) { if (hv_sign == null) { hv_sign = new HTuple(); } hv_sign[hv_Index - 1] = 1; } else { if (hv_sign == null) { hv_sign = new HTuple(); } hv_sign[hv_Index - 1] = 0; } } //** Display //disp_obj (EDGE, WindowHandle) //stop () ho_ROI_0.Dispose(); ho_RoiSign1.Dispose(); ho_RoiSign2.Dispose(); ho_RoiSign3.Dispose(); ho_RoiSign4.Dispose(); ho_RoiSign.Dispose(); ho_GrayImage.Dispose(); ho_ObjectSelected.Dispose(); ho_ImageReduced.Dispose(); ho_Edges.Dispose(); hv_HeadWidth.Dispose(); hv_HeadHeight.Dispose(); hv_RoiSignScale.Dispose(); hv_RoiSignWidth.Dispose(); hv_RoiSignHeight.Dispose(); hv_Rows.Dispose(); hv_Columns.Dispose(); hv_Index.Dispose(); hv_Length.Dispose(); hv_Length1.Dispose(); return; }
// Procedures public void mia_cwdl(HObject ho_Image, HTuple hv_WindowHandle, HTuple hv_signLocRightX, HTuple hv_signLocLeftX, HTuple hv_signLocRightY, HTuple hv_signLocLeftY, out HTuple hv_DecodedDataStrings, out HTuple hv_sign) { // Local iconic variables HObject ho_SymbolRegions, ho_ImageAffineTrans; // Local control variables HTuple hv_BarCodeHandle = new HTuple(), hv_someitem = new HTuple(); HTuple hv_SignWidth = new HTuple(), hv_HeadSignScale = new HTuple(); HTuple hv_HeadSignRow = new HTuple(), hv_HeadSignCol = new HTuple(); HTuple hv_Phi = new HTuple(), hv_HomMat2D = new HTuple(); HTuple hv_HomMat2DRotate = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ImageAffineTrans); hv_DecodedDataStrings = new HTuple(); hv_sign = new HTuple(); //*** //** INIT //* INIT BARCODE hv_BarCodeHandle.Dispose(); HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true"); //** RECOGNITION //* BARCODE ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, hv_WindowHandle, out hv_DecodedDataStrings, out hv_someitem); //* Sign //* 制单人: 1120 186 signLocLeftX signLocLeftY //* 科室收货人 1110 2400 signLocRightX signLocRightY //signLocLeftX := 1120 //signLocLeftY := 186 //signLocRightX := 1110 //signLocRightY := 2400 hv_SignWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SignWidth = hv_signLocRightY - hv_signLocLeftY; } hv_HeadSignScale.Dispose(); hv_HeadSignScale = 1; hv_HeadSignRow.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadSignRow = (hv_signLocLeftX + hv_signLocRightX) / 2; } hv_HeadSignCol.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HeadSignCol = (hv_signLocLeftY + hv_signLocRightY) / 2; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Phi.Dispose(); HOperatorSet.TupleAtan2(hv_signLocRightX - hv_signLocLeftX, hv_signLocRightY - hv_signLocLeftY, out hv_Phi); } hv_HomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_HomMat2D); hv_HomMat2DRotate.Dispose(); HOperatorSet.HomMat2dRotate(hv_HomMat2D, hv_Phi, hv_HeadSignRow, hv_HeadSignCol, out hv_HomMat2DRotate); ho_ImageAffineTrans.Dispose(); HOperatorSet.AffineTransImage(ho_Image, out ho_ImageAffineTrans, hv_HomMat2DRotate, "constant", "false"); hv_sign.Dispose(); mia_sign(ho_ImageAffineTrans, hv_HeadSignRow, hv_HeadSignCol, hv_WindowHandle, hv_SignWidth, out hv_sign); ho_SymbolRegions.Dispose(); ho_ImageAffineTrans.Dispose(); hv_BarCodeHandle.Dispose(); hv_someitem.Dispose(); hv_SignWidth.Dispose(); hv_HeadSignScale.Dispose(); hv_HeadSignRow.Dispose(); hv_HeadSignCol.Dispose(); hv_Phi.Dispose(); hv_HomMat2D.Dispose(); hv_HomMat2DRotate.Dispose(); return; }
public static void list_image_files(HTuple hv_ImageDirectory, HTuple hv_Extensions, HTuple hv_Options, out HTuple hv_ImageFiles) { // Local iconic variables // Local control variables HTuple hv_ImageDirectoryIndex = new HTuple(); HTuple hv_ImageFilesTmp = new HTuple(), hv_CurrentImageDirectory = new HTuple(); HTuple hv_HalconImages = new HTuple(), hv_OS = new HTuple(); HTuple hv_Directories = new HTuple(), hv_Index = new HTuple(); HTuple hv_Length = new HTuple(), hv_NetworkDrive = new HTuple(); HTuple hv_Substring = new HTuple(), hv_FileExists = new HTuple(); HTuple hv_AllFiles = new HTuple(), hv_i = new HTuple(); HTuple hv_Selection = new HTuple(); HTuple hv_Extensions_COPY_INP_TMP = new HTuple(hv_Extensions); // Initialize local and output iconic variables hv_ImageFiles = new HTuple(); //This procedure returns all files in a given directory //with one of the suffixes specified in Extensions. // //Input parameters: //ImageDirectory: Directory or a tuple of directories with images. // If a directory is not found locally, the respective directory // is searched under %HALCONIMAGES%/ImageDirectory. // See the Installation Guide for further information // in case %HALCONIMAGES% is not set. //Extensions: A string tuple containing the extensions to be found // e.g. ['png','tif',jpg'] or others //If Extensions is set to 'default' or the empty string '', // all image suffixes supported by HALCON are used. //Options: as in the operator list_files, except that the 'files' // option is always used. Note that the 'directories' option // has no effect but increases runtime, because only files are // returned. // //Output parameter: //ImageFiles: A tuple of all found image file names // if ((int)((new HTuple((new HTuple(hv_Extensions_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Extensions_COPY_INP_TMP.TupleEqual(""))))).TupleOr(new HTuple(hv_Extensions_COPY_INP_TMP.TupleEqual( "default")))) != 0) { hv_Extensions_COPY_INP_TMP.Dispose(); hv_Extensions_COPY_INP_TMP = new HTuple(); hv_Extensions_COPY_INP_TMP[0] = "ima"; hv_Extensions_COPY_INP_TMP[1] = "tif"; hv_Extensions_COPY_INP_TMP[2] = "tiff"; hv_Extensions_COPY_INP_TMP[3] = "gif"; hv_Extensions_COPY_INP_TMP[4] = "bmp"; hv_Extensions_COPY_INP_TMP[5] = "jpg"; hv_Extensions_COPY_INP_TMP[6] = "jpeg"; hv_Extensions_COPY_INP_TMP[7] = "jp2"; hv_Extensions_COPY_INP_TMP[8] = "jxr"; hv_Extensions_COPY_INP_TMP[9] = "png"; hv_Extensions_COPY_INP_TMP[10] = "pcx"; hv_Extensions_COPY_INP_TMP[11] = "ras"; hv_Extensions_COPY_INP_TMP[12] = "xwd"; hv_Extensions_COPY_INP_TMP[13] = "pbm"; hv_Extensions_COPY_INP_TMP[14] = "pnm"; hv_Extensions_COPY_INP_TMP[15] = "pgm"; hv_Extensions_COPY_INP_TMP[16] = "ppm"; // } hv_ImageFiles.Dispose(); hv_ImageFiles = new HTuple(); //Loop through all given image directories. for (hv_ImageDirectoryIndex = 0; (int)hv_ImageDirectoryIndex <= (int)((new HTuple(hv_ImageDirectory.TupleLength() )) - 1); hv_ImageDirectoryIndex = (int)hv_ImageDirectoryIndex + 1) { hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = new HTuple(); hv_CurrentImageDirectory.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_CurrentImageDirectory = hv_ImageDirectory.TupleSelect( hv_ImageDirectoryIndex); } if ((int)(new HTuple(hv_CurrentImageDirectory.TupleEqual(""))) != 0) { hv_CurrentImageDirectory.Dispose(); hv_CurrentImageDirectory = "."; } hv_HalconImages.Dispose(); HOperatorSet.GetSystem("image_dir", out hv_HalconImages); hv_OS.Dispose(); HOperatorSet.GetSystem("operating_system", out hv_OS); if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_HalconImages = hv_HalconImages.TupleSplit( ";"); hv_HalconImages.Dispose(); hv_HalconImages = ExpTmpLocalVar_HalconImages; } } } else { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_HalconImages = hv_HalconImages.TupleSplit( ":"); hv_HalconImages.Dispose(); hv_HalconImages = ExpTmpLocalVar_HalconImages; } } } hv_Directories.Dispose(); hv_Directories = new HTuple(hv_CurrentImageDirectory); for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_HalconImages.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_Directories = hv_Directories.TupleConcat( ((hv_HalconImages.TupleSelect(hv_Index)) + "/") + hv_CurrentImageDirectory); hv_Directories.Dispose(); hv_Directories = ExpTmpLocalVar_Directories; } } } hv_Length.Dispose(); HOperatorSet.TupleStrlen(hv_Directories, out hv_Length); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_NetworkDrive.Dispose(); HOperatorSet.TupleGenConst(new HTuple(hv_Length.TupleLength()), 0, out hv_NetworkDrive); } if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0) { for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { if ((int)(new HTuple(((((hv_Directories.TupleSelect(hv_Index))).TupleStrlen() )).TupleGreater(1))) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Substring.Dispose(); HOperatorSet.TupleStrFirstN(hv_Directories.TupleSelect(hv_Index), 1, out hv_Substring); } if ((int)((new HTuple(hv_Substring.TupleEqual("//"))).TupleOr(new HTuple(hv_Substring.TupleEqual( "\\\\")))) != 0) { if (hv_NetworkDrive == null) { hv_NetworkDrive = new HTuple(); } hv_NetworkDrive[hv_Index] = 1; } } } } hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = new HTuple(); for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Directories.TupleLength() )) - 1); hv_Index = (int)hv_Index + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_FileExists.Dispose(); HOperatorSet.FileExists(hv_Directories.TupleSelect(hv_Index), out hv_FileExists); } if ((int)(hv_FileExists) != 0) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_AllFiles.Dispose(); HOperatorSet.ListFiles(hv_Directories.TupleSelect(hv_Index), (new HTuple("files")).TupleConcat( hv_Options), out hv_AllFiles); } hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = new HTuple(); for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Extensions_COPY_INP_TMP.TupleLength() )) - 1); hv_i = (int)hv_i + 1) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Selection.Dispose(); HOperatorSet.TupleRegexpSelect(hv_AllFiles, (((".*" + (hv_Extensions_COPY_INP_TMP.TupleSelect( hv_i))) + "$")).TupleConcat("ignore_case"), out hv_Selection); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_ImageFilesTmp = hv_ImageFilesTmp.TupleConcat( hv_Selection); hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = ExpTmpLocalVar_ImageFilesTmp; } } } { HTuple ExpTmpOutVar_0; HOperatorSet.TupleRegexpReplace(hv_ImageFilesTmp, (new HTuple("\\\\")).TupleConcat( "replace_all"), "/", out ExpTmpOutVar_0); hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = ExpTmpOutVar_0; } if ((int)(hv_NetworkDrive.TupleSelect(hv_Index)) != 0) { { HTuple ExpTmpOutVar_0; HOperatorSet.TupleRegexpReplace(hv_ImageFilesTmp, (new HTuple("//")).TupleConcat( "replace_all"), "/", out ExpTmpOutVar_0); hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = ExpTmpOutVar_0; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_ImageFilesTmp = "/" + hv_ImageFilesTmp; hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = ExpTmpLocalVar_ImageFilesTmp; } } } else { { HTuple ExpTmpOutVar_0; HOperatorSet.TupleRegexpReplace(hv_ImageFilesTmp, (new HTuple("//")).TupleConcat( "replace_all"), "/", out ExpTmpOutVar_0); hv_ImageFilesTmp.Dispose(); hv_ImageFilesTmp = ExpTmpOutVar_0; } } break; } } //Concatenate the output image paths. using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_ImageFiles = hv_ImageFiles.TupleConcat( hv_ImageFilesTmp); hv_ImageFiles.Dispose(); hv_ImageFiles = ExpTmpLocalVar_ImageFiles; } } } hv_Extensions_COPY_INP_TMP.Dispose(); hv_ImageDirectoryIndex.Dispose(); hv_ImageFilesTmp.Dispose(); hv_CurrentImageDirectory.Dispose(); hv_HalconImages.Dispose(); hv_OS.Dispose(); hv_Directories.Dispose(); hv_Index.Dispose(); hv_Length.Dispose(); hv_NetworkDrive.Dispose(); hv_Substring.Dispose(); hv_FileExists.Dispose(); hv_AllFiles.Dispose(); hv_i.Dispose(); hv_Selection.Dispose(); return; }
public void image_cali_map(HObject ho_Image, out HObject ho_TmpObj_RectifiedImage, HTuple hv_CameraParameters, HTuple hv_CameraPose) { // Local iconic variables HObject ho_TmpObj_RectificationMap; // Local control variables HTuple hv_TmpCtrl_RectificationWidth = new HTuple(); HTuple hv_TmpCtrl_RectificationPose = new HTuple(); HTuple hv_CameraParameters_COPY_INP_TMP = new HTuple(hv_CameraParameters); HTuple hv_CameraPose_COPY_INP_TMP = new HTuple(hv_CameraPose); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_TmpObj_RectifiedImage); HOperatorSet.GenEmptyObj(out ho_TmpObj_RectificationMap); //* GEN CALIDATA //Calibration 01: Code generated by Calibration 01 if ((int)((new HTuple(hv_CameraParameters_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_CameraPose_COPY_INP_TMP.TupleEqual(new HTuple())))) != 0) { hv_CameraParameters_COPY_INP_TMP.Dispose(); hv_CameraParameters_COPY_INP_TMP = new HTuple(); hv_CameraParameters_COPY_INP_TMP[0] = "area_scan_division"; hv_CameraParameters_COPY_INP_TMP[1] = 0.0395393; hv_CameraParameters_COPY_INP_TMP[2] = 29.5225; hv_CameraParameters_COPY_INP_TMP[3] = 2.3103e-006; hv_CameraParameters_COPY_INP_TMP[4] = 2.4e-006; hv_CameraParameters_COPY_INP_TMP[5] = 1969.65; hv_CameraParameters_COPY_INP_TMP[6] = 5753.85; hv_CameraParameters_COPY_INP_TMP[7] = 4024; hv_CameraParameters_COPY_INP_TMP[8] = 3036; hv_CameraPose_COPY_INP_TMP.Dispose(); hv_CameraPose_COPY_INP_TMP = new HTuple(); hv_CameraPose_COPY_INP_TMP[0] = 0.00207285; hv_CameraPose_COPY_INP_TMP[1] = -0.111611; hv_CameraPose_COPY_INP_TMP[2] = 0.434522; hv_CameraPose_COPY_INP_TMP[3] = 13.3656; hv_CameraPose_COPY_INP_TMP[4] = 0.504334; hv_CameraPose_COPY_INP_TMP[5] = 90.2621; hv_CameraPose_COPY_INP_TMP[6] = 0; } //Calibration 01: Sample code generated by Calibration 01 //Calibration 01: For demonstration purposes, we use the calibration //Calibration 01: plate itself as sample object. //Calibration 01: Therefore, we load the reference image //read_image (Image, 'C:/Users/iwake/OneDrive - wake/Desktop/HalconPractise/HalconProj/Cali/image_02.png') //Calibration 01: Extract plate data from the image //TmpCtrl_PlateDescription := 'C:/Program Files/MVTec/HALCON-18.11-Steady/calib/caltab_30mm.descr' //TmpCtrl_FindCalObjParNames := ['gap_tolerance','alpha','skip_find_caltab'] //TmpCtrl_FindCalObjParValues := [1,1,'false'] //Calibration 01: Create calibration model for managing calibration data //create_calib_data ('calibration_object', 1, 1, CalibHandle) //set_calib_data_cam_param (CalibHandle, 0, [], CameraParameters) //set_calib_data_calib_object (CalibHandle, 0, TmpCtrl_PlateDescription) //find_calib_object (Image, CalibHandle, 0, 0, 0, TmpCtrl_FindCalObjParNames, TmpCtrl_FindCalObjParValues) //get_calib_data_observ_points (CalibHandle, 0, 0, 0, TmpCtrl_MarkRows, TmpCtrl_MarkColumns, TmpCtrl_Ind, CameraPose) //Calibration 01: Using the calibration plate as test object, the marks actually //Calibration 01: lie above the corrected measurement plane. Therefore, we 'uncorrect' //Calibration 01: the plane of measurement by the plate thickness here. //set_origin_pose (CameraPose, 0.0, 0.0, 0, CameraPose) //read_image (Image, 'C:/Users/iwake/OneDrive - wake/Desktop/Localization/Images/Inv/InvV1 (4).jpg') //Calibration 01: ********************************************************** //Calibration 01: Sample Task: Image Rectification //Calibration 01: ********************************************************** //Calibration 01: Choose the desired width of the visible area in world coordinates [mm] hv_TmpCtrl_RectificationWidth.Dispose(); hv_TmpCtrl_RectificationWidth = 75; //Calibration 01: Convert to [m] using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_TmpCtrl_RectificationWidth = hv_TmpCtrl_RectificationWidth / 1000.0; hv_TmpCtrl_RectificationWidth.Dispose(); hv_TmpCtrl_RectificationWidth = ExpTmpLocalVar_TmpCtrl_RectificationWidth; } } //Calibration 01: Adjust origin so the plate is roughly centered //* ATTENTION 参数从-0.5 -0.4 改成了-0.5 -0.6 using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_TmpCtrl_RectificationPose.Dispose(); HOperatorSet.SetOriginPose(hv_CameraPose_COPY_INP_TMP, -0.5 * hv_TmpCtrl_RectificationWidth, -0.6 * hv_TmpCtrl_RectificationWidth, 0, out hv_TmpCtrl_RectificationPose); } //Calibration 01: Generate the rectification map using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TmpObj_RectificationMap.Dispose(); HOperatorSet.GenImageToWorldPlaneMap(out ho_TmpObj_RectificationMap, hv_CameraParameters_COPY_INP_TMP, hv_TmpCtrl_RectificationPose, 4024, 3036, 3036, 4024, hv_TmpCtrl_RectificationWidth / 3036, "bilinear"); } //gen_image_to_world_plane_map (TmpObj_RectificationMap, CameraParameters, TmpCtrl_RectificationPose, 4024, 3036, 3036, 4024, 0.8*TmpCtrl_RectificationWidth / 3036, 'bilinear') //Calibration 01: Now, images can be rectified using the rectification map ho_TmpObj_RectifiedImage.Dispose(); HOperatorSet.MapImage(ho_Image, ho_TmpObj_RectificationMap, out ho_TmpObj_RectifiedImage ); //stop () ho_TmpObj_RectificationMap.Dispose(); hv_CameraParameters_COPY_INP_TMP.Dispose(); hv_CameraPose_COPY_INP_TMP.Dispose(); hv_TmpCtrl_RectificationWidth.Dispose(); hv_TmpCtrl_RectificationPose.Dispose(); return; }
// Main procedure private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_SignModelContours, ho_Image = null; HObject ho_SymbolRegions = null, ho_ROI_OCR_01_0 = null, ho_EDGE = null; HObject ho_ObjectSelected = null, ho_SignTransContours = null; // Local control variables HTuple hv_BarWidth = new HTuple(), hv_BarHeight = new HTuple(); HTuple hv_BarCodeHandle = new HTuple(), hv_SignModel = new HTuple(); HTuple hv_AcqHandle = new HTuple(); HTuple hv_InfoRow = new HTuple(), hv_InfoColumn = new HTuple(); HTuple hv_InfoAngle = new HTuple(), hv_InfoScore = new HTuple(); HTuple hv_DecodedDataStrings = new HTuple(), hv_someitem = new HTuple(); HTuple hv_SignRow = new HTuple(), hv_SignColumn = new HTuple(); HTuple hv_SignAngle = new HTuple(), hv_SignScore = new HTuple(); HTuple hv_SymbolNames_OCR_01_0 = new HTuple(), hv_Ocr_Split = new HTuple(); HTuple hv_Area = new HTuple(), hv_IDRow = new HTuple(); HTuple hv_IDColumn = new HTuple(), hv_IDRow1 = new HTuple(); HTuple hv_IDColumn1 = new HTuple(), hv_IDRow2 = new HTuple(); HTuple hv_IDColumn2 = new HTuple(), hv_IDHeight = new HTuple(); HTuple hv_IDWidth = new HTuple(), hv_IDRatio = new HTuple(); HTuple hv_HeadSignScale = new HTuple(), hv_HeadSignRow = new HTuple(); HTuple hv_HeadSignCol = new HTuple(), hv_HeadPhi = new HTuple(); HTuple hv_sign = new HTuple(), hv_BarIndex = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_SignHomMat2D = new HTuple(), hv_Exception = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SignModelContours); HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ROI_OCR_01_0); HOperatorSet.GenEmptyObj(out ho_EDGE); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); HOperatorSet.GenEmptyObj(out ho_SignTransContours); try { //*** //** INIT //* INIT CONST hv_BarWidth.Dispose(); hv_BarWidth = 800; hv_BarHeight.Dispose(); hv_BarHeight = 100; //* INIT IMAGE //* INIT BARCODE hv_BarCodeHandle.Dispose(); HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true"); //* INIT LOC //* Info: //read_shape_model ('C:/Users/iwake/OneDrive - wake/Desktop/Localization/InvV1CaliInfo.shm', InfoModel) //get_shape_model_contours (InfoModelContours, InfoModel, 1) //* Sign hv_SignModel.Dispose(); HOperatorSet.ReadShapeModel("C:/Users/zhang-sh/source/repos/repo/Model/file/InvV1CaliSign.shm", out hv_SignModel); ho_SignModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_SignModelContours, hv_SignModel, 1); //*** //** DISPLAY //* DISPLAY INIT hDevelo.dev_update_off(); if (HDevWindowStack.IsOpen()) { HOperatorSet.CloseWindow(HDevWindowStack.Pop()); } HOperatorSet.SetWindowAttr("background_color", "black"); //HOperatorSet.OpenWindow(30, 0, 800, 1500, 0, "visible", "", out hv_WindowHandle); HDevWindowStack.Push(hv_ExpDefaultWinHandle); //*** //** LOOP //Image Acquisition 01: Code generated by Image Acquisition 01 hv_AcqHandle.Dispose(); hv_AcqHandle = acqHandle; while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle); { HObject ExpTmpOutVar_0; hDevelo.image_cali_map(ho_Image, out ExpTmpOutVar_0, new HTuple(), new HTuple()); ho_Image.Dispose(); ho_Image = ExpTmpOutVar_0; HOperatorSet.DispObj(ho_Image, hv_ExpImageRawWinHandle); } try { //** PRE using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_SignModel, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat( 1), 0.6, out hv_InfoRow, out hv_InfoColumn, out hv_InfoAngle, out hv_InfoScore); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HObject ExpTmpOutVar_0; HOperatorSet.RotateImage(ho_Image, out ExpTmpOutVar_0, ((-hv_InfoAngle)).TupleDeg() , "constant"); ho_Image.Dispose(); ho_Image = ExpTmpOutVar_0; } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } //** RECOGNITION //* BARCODE ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hDevelo.image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, out hv_DecodedDataStrings, out hv_someitem); //* LOC //* Info: //find_shape_model (Image, InfoModel, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [7,1], 0.7, InfoRow, InfoColumn, InfoAngle, InfoScore) //* HaedSign using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); HOperatorSet.FindShapeModel(ho_Image, hv_SignModel, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat( 1), 0.7, out hv_SignRow, out hv_SignColumn, out hv_SignAngle, out hv_SignScore); } //* Ocr using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_ROI_OCR_01_0.Dispose(); HOperatorSet.GenRectangle2(out ho_ROI_OCR_01_0, hv_InfoRow + 70, hv_InfoColumn - 700, hv_InfoAngle, 100, 30); } hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); hDevelo.region_ocr_num_svm(ho_Image, ho_ROI_OCR_01_0, new HTuple(), new HTuple(), out hv_SymbolNames_OCR_01_0, out hv_Ocr_Split); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); HOperatorSet.AreaCenter(ho_ROI_OCR_01_0, out hv_Area, out hv_IDRow, out hv_IDColumn); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); HOperatorSet.SmallestRectangle1(ho_ROI_OCR_01_0, out hv_IDRow1, out hv_IDColumn1, out hv_IDRow2, out hv_IDColumn2); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); HOperatorSet.HeightWidthRatio(ho_ROI_OCR_01_0, out hv_IDHeight, out hv_IDWidth, out hv_IDRatio); //* Sign hv_HeadSignScale.Dispose(); hv_HeadSignScale = 1; hv_HeadSignRow.Dispose(); hv_HeadSignRow = new HTuple(hv_SignRow); hv_HeadSignCol.Dispose(); hv_HeadSignCol = new HTuple(hv_SignColumn); hv_HeadPhi.Dispose(); hv_HeadPhi = new HTuple(hv_SignAngle); ho_EDGE.Dispose(); hv_sign.Dispose(); hDevelo.region_judge_sign(ho_Image, out ho_EDGE, hv_HeadSignScale, hv_HeadSignRow, hv_HeadSignCol, hv_HeadPhi, hv_ExpDefaultWinHandle, out hv_sign); //** DISPLAY //* DISPLAY BARCODE 显示条形码 hDevelo.set_display_font(hv_ExpDefaultWinHandle, 14, "mono", "true", "false"); if (HDevWindowStack.IsOpen()) { HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "forest green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SymbolRegions, HDevWindowStack.GetActive()); } for (hv_BarIndex = 1; (int)hv_BarIndex <= (int)(new HTuple(hv_DecodedDataStrings.TupleLength() )); hv_BarIndex = (int)hv_BarIndex + 1) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SymbolRegions, out ho_ObjectSelected, hv_BarIndex); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_Row - hv_BarHeight, hv_Column - (0.25 * hv_BarWidth)); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_DecodedDataStrings.TupleSelect( hv_BarIndex - 1)); } } //* DISPLAY LOC if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1); } //* Info: //hom_mat2d_identity (InfoHomMat2D) //hom_mat2d_rotate (InfoHomMat2D, InfoAngle, 0, 0, InfoHomMat2D) //hom_mat2d_translate (InfoHomMat2D, InfoRow, InfoColumn, InfoHomMat2D) //affine_trans_contour_xld (InfoModelContours, InfoTransContours, InfoHomMat2D) if (HDevWindowStack.IsOpen()) { //dev_set_color ('green') } if (HDevWindowStack.IsOpen()) { //dev_display (InfoTransContours) } //* Ocr if (HDevWindowStack.IsOpen()) { //dev_disp_text (Ocr_Split, 'image', IDRow1 + IDHeight, IDColumn1, 'blue', [], []) } //* HeadSign hv_SignHomMat2D.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_SignHomMat2D); { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dRotate(hv_SignHomMat2D, hv_SignAngle, 0, 0, out ExpTmpOutVar_0); hv_SignHomMat2D.Dispose(); hv_SignHomMat2D = ExpTmpOutVar_0; } { HTuple ExpTmpOutVar_0; HOperatorSet.HomMat2dTranslate(hv_SignHomMat2D, hv_SignRow, hv_SignColumn, out ExpTmpOutVar_0); hv_SignHomMat2D.Dispose(); hv_SignHomMat2D = ExpTmpOutVar_0; } ho_SignTransContours.Dispose(); HOperatorSet.AffineTransContourXld(ho_SignModelContours, out ho_SignTransContours, hv_SignHomMat2D); if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SignTransContours, HDevWindowStack.GetActive() ); } //* Sign if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColored(HDevWindowStack.GetActive(), 12); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_EDGE, HDevWindowStack.GetActive()); } //dump_window_image (ImageResult, WindowHandle) //stop () } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); } } HOperatorSet.CloseFramegrabber(hv_AcqHandle); } catch (HalconException HDevExpDefaultException) { ho_SignModelContours.Dispose(); ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_ROI_OCR_01_0.Dispose(); ho_EDGE.Dispose(); ho_ObjectSelected.Dispose(); ho_SignTransContours.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_BarCodeHandle.Dispose(); hv_SignModel.Dispose(); hv_ExpImageRawWinHandle.Dispose(); hv_ExpDefaultWinHandle.Dispose(); hv_AcqHandle.Dispose(); hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); hv_HeadSignScale.Dispose(); hv_HeadSignRow.Dispose(); hv_HeadSignCol.Dispose(); hv_HeadPhi.Dispose(); hv_sign.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_SignHomMat2D.Dispose(); hv_Exception.Dispose(); throw HDevExpDefaultException; } ho_SignModelContours.Dispose(); ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_ROI_OCR_01_0.Dispose(); ho_EDGE.Dispose(); ho_ObjectSelected.Dispose(); ho_SignTransContours.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_BarCodeHandle.Dispose(); hv_SignModel.Dispose(); hv_ExpImageRawWinHandle.Dispose(); hv_ExpDefaultWinHandle.Dispose(); hv_AcqHandle.Dispose(); hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose(); hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose(); hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose(); hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose(); hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose(); hv_HeadSignScale.Dispose(); hv_HeadSignRow.Dispose(); hv_HeadSignCol.Dispose(); hv_HeadPhi.Dispose(); hv_sign.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_SignHomMat2D.Dispose(); hv_Exception.Dispose(); }
// Main procedure private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_Image = null, ho_SymbolXLDs = null; HObject ho_SymbolRegions = null, ho_ObjectSelected = null; // Local control variables HTuple hv_BarWidth = new HTuple(), hv_BarHeight = new HTuple(); HTuple hv_DataCodeHandle = new HTuple(), hv_BarCodeHandle = new HTuple(); HTuple hv_WindowHandle = new HTuple(), hv_AcqHandle = new HTuple(); HTuple hv_ResultHandles = new HTuple(), hv_DecodedDataStrings = new HTuple(); HTuple hv_someitem = new HTuple(), hv_Area = new HTuple(); HTuple hv_BarIndex = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Exception = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_SymbolXLDs); HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_ObjectSelected); try { //*** //** INIT //* INIT CONST hv_BarWidth.Dispose(); hv_BarWidth = 800; hv_BarHeight.Dispose(); hv_BarHeight = 100; //* INIT IMAGE //* INIT DATACODE hv_DataCodeHandle.Dispose(); HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", new HTuple(), new HTuple(), out hv_DataCodeHandle); //* INIT BARCODE hv_BarCodeHandle.Dispose(); HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true"); //* INIT LOC //* Info: //read_shape_model ('C:/Users/iwake/OneDrive - wake/Desktop/Localization/InvV1CaliInfo.shm', InfoModel) //get_shape_model_contours (InfoModelContours, InfoModel, 1) //* Sign //read_shape_model ('C:/Users/iwake/OneDrive - wake/Desktop/Localization/InvV1CaliSign.shm', SignModel) //get_shape_model_contours (SignModelContours, SignModel, 1) //*** //** DISPLAY //* DISPLAY INIT hDevelo.dev_update_off(); if (HDevWindowStack.IsOpen()) { HOperatorSet.CloseWindow(HDevWindowStack.Pop()); } HOperatorSet.SetWindowAttr("background_color", "black"); //HOperatorSet.OpenWindow(30, 0, 800, 1500, 0, "visible", "", out hv_WindowHandle); HDevWindowStack.Push(hv_ExpDefaultWinHandle); //*** //** LOOP //Image Acquisition 01: Code generated by Image Acquisition 01 hv_AcqHandle.Dispose(); hv_AcqHandle = acqHandle; while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle); { HObject ExpTmpOutVar_0; hDevelo.image_cali_map(ho_Image, out ExpTmpOutVar_0, new HTuple(), new HTuple()); ho_Image.Dispose(); ho_Image = ExpTmpOutVar_0; HOperatorSet.DispObj(ho_Image, hv_ExpImageRawWinHandle); } try { //** PRE //find_shape_model (Image, SignModel, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [7,1], 0.6, InfoRow, InfoColumn, InfoAngle, InfoScore) //rotate_image (Image, Image, deg(-InfoAngle), 'constant') if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } //** RECOGNITION //* DataCode ho_SymbolXLDs.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose(); HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle, "stop_after_result_num", 3, out hv_ResultHandles, out hv_DecodedDataStrings); hDevelo.image_display_datacode(ho_SymbolXLDs, hv_ResultHandles, hv_WindowHandle, hv_DecodedDataStrings, hv_DataCodeHandle); //* BARCODE ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hDevelo.image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, out hv_DecodedDataStrings, out hv_someitem); //* LOC //* Info: //find_shape_model (Image, InfoModel, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [7,1], 0.7, InfoRow, InfoColumn, InfoAngle, InfoScore) //* HaedSign //find_shape_model (Image, SignModel, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [7,1], 0.7, SignRow, SignColumn, SignAngle, SignScore) //* Ocr //gen_rectangle2 (ROI_OCR_01_0, InfoRow + 70, InfoColumn - 700, InfoAngle, 100, 30) //region_ocr_num_svm (Image, ROI_OCR_01_0, [], [], SymbolNames_OCR_01_0, Ocr_Split) //area_center (ROI_OCR_01_0, Area, IDRow, IDColumn) //smallest_rectangle1 (ROI_OCR_01_0, IDRow1, IDColumn1, IDRow2, IDColumn2) //height_width_ratio (ROI_OCR_01_0, IDHeight, IDWidth, IDRatio) //* Sign //HeadSignScale := 1 //HeadSignRow := SignRow //HeadSignCol := SignColumn //HeadPhi := SignAngle //region_judge_sign (Image, EDGE, HeadSignScale, HeadSignRow, HeadSignCol, HeadPhi, WindowHandle, sign) //** DISPLAY //* DISPLAY BARCODE hDevelo.set_display_font(hv_WindowHandle, 14, "mono", "true", "false"); if (HDevWindowStack.IsOpen()) { HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "forest green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_SymbolRegions, HDevWindowStack.GetActive()); } for (hv_BarIndex = 1; (int)hv_BarIndex <= (int)(new HTuple(hv_DecodedDataStrings.TupleLength() )); hv_BarIndex = (int)hv_BarIndex + 1) { ho_ObjectSelected.Dispose(); HOperatorSet.SelectObj(ho_SymbolRegions, out ho_ObjectSelected, hv_BarIndex); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.SetTposition(hv_WindowHandle, hv_Row - hv_BarHeight, hv_Column - (0.25 * hv_BarWidth)); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { HOperatorSet.WriteString(hv_WindowHandle, hv_DecodedDataStrings.TupleSelect( hv_BarIndex - 1)); } } //* DISPLAY LOC if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1); } //* Info: //hom_mat2d_identity (InfoHomMat2D) //hom_mat2d_rotate (InfoHomMat2D, InfoAngle, 0, 0, InfoHomMat2D) //hom_mat2d_translate (InfoHomMat2D, InfoRow, InfoColumn, InfoHomMat2D) //affine_trans_contour_xld (InfoModelContours, InfoTransContours, InfoHomMat2D) if (HDevWindowStack.IsOpen()) { //dev_set_color ('green') } if (HDevWindowStack.IsOpen()) { //dev_display (InfoTransContours) } //* Ocr if (HDevWindowStack.IsOpen()) { //dev_disp_text (Ocr_Split, 'image', IDRow1 + IDHeight, IDColumn1, 'blue', [], []) } //* HeadSign //hom_mat2d_identity (SignHomMat2D) //hom_mat2d_rotate (SignHomMat2D, SignAngle, 0, 0, SignHomMat2D) //hom_mat2d_translate (SignHomMat2D, SignRow, SignColumn, SignHomMat2D) //affine_trans_contour_xld (SignModelContours, SignTransContours, SignHomMat2D) if (HDevWindowStack.IsOpen()) { //dev_set_color ('green') } if (HDevWindowStack.IsOpen()) { //dev_display (SignTransContours) } //* Sign if (HDevWindowStack.IsOpen()) { //dev_set_colored (12) } if (HDevWindowStack.IsOpen()) { //dev_display (EDGE) } //dump_window_image (ImageResult, WindowHandle) //stop () } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); } } HOperatorSet.CloseFramegrabber(hv_AcqHandle); } catch (HalconException HDevExpDefaultException) { ho_Image.Dispose(); ho_SymbolXLDs.Dispose(); ho_SymbolRegions.Dispose(); ho_ObjectSelected.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_DataCodeHandle.Dispose(); hv_BarCodeHandle.Dispose(); hv_WindowHandle.Dispose(); hv_AcqHandle.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_Area.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Exception.Dispose(); throw HDevExpDefaultException; } ho_Image.Dispose(); ho_SymbolXLDs.Dispose(); ho_SymbolRegions.Dispose(); ho_ObjectSelected.Dispose(); hv_BarWidth.Dispose(); hv_BarHeight.Dispose(); hv_DataCodeHandle.Dispose(); hv_BarCodeHandle.Dispose(); hv_WindowHandle.Dispose(); hv_AcqHandle.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose(); hv_Area.Dispose(); hv_BarIndex.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Exception.Dispose(); }
// Procedures public void region_get_corner(HObject ho_Image, HObject ho_Rectangle, HTuple hv_WindowHandle, out HTuple hv_Rows, out HTuple hv_Cols) { // Local iconic variables HObject ho_RegionsLine3 = null, ho_RegionIntersection = null; // Local control variables HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_LengthDiagonal = new HTuple(), hv_HalfDiagonal = new HTuple(); HTuple hv_Polarity = new HTuple(), hv_Index = new HTuple(); HTuple hv_RegionIntersectionArea = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_RegionsLine3); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); hv_Rows = new HTuple(); hv_Cols = new HTuple(); //* Gen Line In Loop and juage cross hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_LengthDiagonal.Dispose(); HOperatorSet.TupleSqrt((hv_Width * hv_Width) + (hv_Height * hv_Height), out hv_LengthDiagonal); } hv_HalfDiagonal.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HalfDiagonal = hv_LengthDiagonal / 2; } //PolarityDegree := 1 //PolarityLength := 1 //Polarity := 3 hv_Rows.Dispose(); hv_Rows = new HTuple(); hv_Cols.Dispose(); hv_Cols = new HTuple(); for (hv_Polarity = 1; (int)hv_Polarity <= 4; hv_Polarity = (int)hv_Polarity + 1) { if ((int)(new HTuple(hv_Polarity.TupleEqual(1))) != 0) { HTuple end_val11 = hv_HalfDiagonal; HTuple step_val11 = 1; for (hv_Index = 0; hv_Index.Continue(end_val11, step_val11); hv_Index = hv_Index.TupleAdd(step_val11)) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RegionsLine3.Dispose(); HOperatorSet.GenRegionHline(out ho_RegionsLine3, (new HTuple(-45)).TupleRad() , 1 * ((1 * hv_HalfDiagonal) - hv_Index)); } ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionsLine3, ho_Rectangle, out ho_RegionIntersection ); hv_RegionIntersectionArea.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_RegionIntersection, out hv_RegionIntersectionArea, out hv_Row, out hv_Column); if ((int)(new HTuple(hv_RegionIntersectionArea.TupleGreater(0))) != 0) { if (hv_Rows == null) { hv_Rows = new HTuple(); } hv_Rows[hv_Polarity] = hv_Row; if (hv_Cols == null) { hv_Cols = new HTuple(); } hv_Cols[hv_Polarity] = hv_Column; break; } } } if ((int)(new HTuple(hv_Polarity.TupleEqual(2))) != 0) { HTuple end_val23 = hv_HalfDiagonal; HTuple step_val23 = 1; for (hv_Index = 0; hv_Index.Continue(end_val23, step_val23); hv_Index = hv_Index.TupleAdd(step_val23)) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RegionsLine3.Dispose(); HOperatorSet.GenRegionHline(out ho_RegionsLine3, (new HTuple(45)).TupleRad() , 1 * ((0 * hv_HalfDiagonal) + hv_Index)); } ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionsLine3, ho_Rectangle, out ho_RegionIntersection ); hv_RegionIntersectionArea.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_RegionIntersection, out hv_RegionIntersectionArea, out hv_Row, out hv_Column); if ((int)(new HTuple(hv_RegionIntersectionArea.TupleGreater(0))) != 0) { if (hv_Rows == null) { hv_Rows = new HTuple(); } hv_Rows[hv_Polarity] = hv_Row; if (hv_Cols == null) { hv_Cols = new HTuple(); } hv_Cols[hv_Polarity] = hv_Column; break; } } } if ((int)(new HTuple(hv_Polarity.TupleEqual(3))) != 0) { HTuple end_val35 = hv_HalfDiagonal; HTuple step_val35 = 1; for (hv_Index = 0; hv_Index.Continue(end_val35, step_val35); hv_Index = hv_Index.TupleAdd(step_val35)) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RegionsLine3.Dispose(); HOperatorSet.GenRegionHline(out ho_RegionsLine3, (new HTuple(-45)).TupleRad() , -1 * ((1 * hv_HalfDiagonal) - hv_Index)); } ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionsLine3, ho_Rectangle, out ho_RegionIntersection ); hv_RegionIntersectionArea.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_RegionIntersection, out hv_RegionIntersectionArea, out hv_Row, out hv_Column); if ((int)(new HTuple(hv_RegionIntersectionArea.TupleGreater(0))) != 0) { if (hv_Rows == null) { hv_Rows = new HTuple(); } hv_Rows[hv_Polarity] = hv_Row; if (hv_Cols == null) { hv_Cols = new HTuple(); } hv_Cols[hv_Polarity] = hv_Column; break; } } } if ((int)(new HTuple(hv_Polarity.TupleEqual(4))) != 0) { HTuple end_val47 = hv_HalfDiagonal; HTuple step_val47 = 1; for (hv_Index = 0; hv_Index.Continue(end_val47, step_val47); hv_Index = hv_Index.TupleAdd(step_val47)) { using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_RegionsLine3.Dispose(); HOperatorSet.GenRegionHline(out ho_RegionsLine3, (new HTuple(45)).TupleRad() , 1 * ((2 * hv_HalfDiagonal) - hv_Index)); } ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionsLine3, ho_Rectangle, out ho_RegionIntersection ); hv_RegionIntersectionArea.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_RegionIntersection, out hv_RegionIntersectionArea, out hv_Row, out hv_Column); if ((int)(new HTuple(hv_RegionIntersectionArea.TupleGreater(0))) != 0) { if (hv_Rows == null) { hv_Rows = new HTuple(); } hv_Rows[hv_Polarity] = hv_Row; if (hv_Cols == null) { hv_Cols = new HTuple(); } hv_Cols[hv_Polarity] = hv_Column; break; } } } //get_region_points (RegionIntersection, Rows, Columns) //disp_message (WindowHandle, 'Intesection Row:'+ Row +'Col'+ Column, 'window', Row, Column, 'black', 'true') } //dev_set_colored (12) //for Index := 1 to 4 by 1 //disp_circle (WindowHandle, Rows[Index], Cols[Index], 64) //endfor ho_RegionsLine3.Dispose(); ho_RegionIntersection.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); hv_LengthDiagonal.Dispose(); hv_HalfDiagonal.Dispose(); hv_Polarity.Dispose(); hv_Index.Dispose(); hv_RegionIntersectionArea.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); return; }
// Chapter: Graphics / Text // Short Description: This procedure writes a text message. public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem, HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box) { // Local iconic variables // Local control variables HTuple hv_GenParamName = new HTuple(), hv_GenParamValue = new HTuple(); HTuple hv_Color_COPY_INP_TMP = new HTuple(hv_Color); HTuple hv_Column_COPY_INP_TMP = new HTuple(hv_Column); HTuple hv_CoordSystem_COPY_INP_TMP = new HTuple(hv_CoordSystem); HTuple hv_Row_COPY_INP_TMP = new HTuple(hv_Row); // Initialize local and output iconic variables try { //This procedure displays text in a graphics window. // //Input parameters: //WindowHandle: The WindowHandle of the graphics window, where // the message should be displayed //String: A tuple of strings containing the text message to be displayed //CoordSystem: If set to 'window', the text position is given // with respect to the window coordinate system. // If set to 'image', image coordinates are used. // (This may be useful in zoomed images.) //Row: The row coordinate of the desired text position // A tuple of values is allowed to display text at different // positions. //Column: The column coordinate of the desired text position // A tuple of values is allowed to display text at different // positions. //Color: defines the color of the text as string. // If set to [], '' or 'auto' the currently set color is used. // If a tuple of strings is passed, the colors are used cyclically... // - if |Row| == |Column| == 1: for each new textline // = else for each text position. //Box: If Box[0] is set to 'true', the text is written within an orange box. // If set to' false', no box is displayed. // If set to a color string (e.g. 'white', '#FF00CC', etc.), // the text is written in a box of that color. // An optional second value for Box (Box[1]) controls if a shadow is displayed: // 'true' -> display a shadow in a default color // 'false' -> display no shadow // otherwise -> use given string as color string for the shadow color // //It is possible to display multiple text strings in a single call. //In this case, some restrictions apply: //- Multiple text positions can be defined by specifying a tuple // with multiple Row and/or Column coordinates, i.e.: // - |Row| == n, |Column| == n // - |Row| == n, |Column| == 1 // - |Row| == 1, |Column| == n //- If |Row| == |Column| == 1, // each element of String is display in a new textline. //- If multiple positions or specified, the number of Strings // must match the number of positions, i.e.: // - Either |String| == n (each string is displayed at the // corresponding position), // - or |String| == 1 (The string is displayed n times). // // //Convert the parameters for disp_text. if ((int)((new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(new HTuple())))) != 0) { hv_Color_COPY_INP_TMP.Dispose(); hv_Column_COPY_INP_TMP.Dispose(); hv_CoordSystem_COPY_INP_TMP.Dispose(); hv_Row_COPY_INP_TMP.Dispose(); hv_GenParamName.Dispose(); hv_GenParamValue.Dispose(); return; } if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0) { hv_Row_COPY_INP_TMP.Dispose(); hv_Row_COPY_INP_TMP = 12; } if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0) { hv_Column_COPY_INP_TMP.Dispose(); hv_Column_COPY_INP_TMP = 12; } // //Convert the parameter Box to generic parameters. hv_GenParamName.Dispose(); hv_GenParamName = new HTuple(); hv_GenParamValue.Dispose(); hv_GenParamValue = new HTuple(); if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(0))) != 0) { if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleEqual("false"))) != 0) { //Display no box using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat( "box"); hv_GenParamName.Dispose(); hv_GenParamName = ExpTmpLocalVar_GenParamName; } } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat( "false"); hv_GenParamValue.Dispose(); hv_GenParamValue = ExpTmpLocalVar_GenParamValue; } } } else if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleNotEqual( "true"))) != 0) { //Set a color other than the default. using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat( "box_color"); hv_GenParamName.Dispose(); hv_GenParamName = ExpTmpLocalVar_GenParamName; } } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat( hv_Box.TupleSelect(0)); hv_GenParamValue.Dispose(); hv_GenParamValue = ExpTmpLocalVar_GenParamValue; } } } } if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(1))) != 0) { if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleEqual("false"))) != 0) { //Display no shadow. using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat( "shadow"); hv_GenParamName.Dispose(); hv_GenParamName = ExpTmpLocalVar_GenParamName; } } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat( "false"); hv_GenParamValue.Dispose(); hv_GenParamValue = ExpTmpLocalVar_GenParamValue; } } } else if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleNotEqual( "true"))) != 0) { //Set a shadow color other than the default. using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat( "shadow_color"); hv_GenParamName.Dispose(); hv_GenParamName = ExpTmpLocalVar_GenParamName; } } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { { HTuple ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat( hv_Box.TupleSelect(1)); hv_GenParamValue.Dispose(); hv_GenParamValue = ExpTmpLocalVar_GenParamValue; } } } } //Restore default CoordSystem behavior. if ((int)(new HTuple(hv_CoordSystem_COPY_INP_TMP.TupleNotEqual("window"))) != 0) { hv_CoordSystem_COPY_INP_TMP.Dispose(); hv_CoordSystem_COPY_INP_TMP = "image"; } // if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(""))) != 0) { //disp_text does not accept an empty string for Color. hv_Color_COPY_INP_TMP.Dispose(); hv_Color_COPY_INP_TMP = new HTuple(); } // HOperatorSet.DispText(hv_WindowHandle, hv_String, hv_CoordSystem_COPY_INP_TMP, hv_Row_COPY_INP_TMP, hv_Column_COPY_INP_TMP, hv_Color_COPY_INP_TMP, hv_GenParamName, hv_GenParamValue); hv_Color_COPY_INP_TMP.Dispose(); hv_Column_COPY_INP_TMP.Dispose(); hv_CoordSystem_COPY_INP_TMP.Dispose(); hv_Row_COPY_INP_TMP.Dispose(); hv_GenParamName.Dispose(); hv_GenParamValue.Dispose(); return; } catch (HalconException HDevExpDefaultException) { hv_Color_COPY_INP_TMP.Dispose(); hv_Column_COPY_INP_TMP.Dispose(); hv_CoordSystem_COPY_INP_TMP.Dispose(); hv_Row_COPY_INP_TMP.Dispose(); hv_GenParamName.Dispose(); hv_GenParamValue.Dispose(); throw HDevExpDefaultException; } }
public void TestImage(ref HWindowControl hv_HWindowControl) { if (hv_Test_DlClassifierName == null) { Console.WriteLine("错误提示:无可用分类器"); return; } if (ho_Preprocessed_TestImage == null) { Console.WriteLine("图像未进行预处理"); return; } HObject ho_ImagePreprocessed = new HObject(); HTuple hv_DLClassifierResultHandle = new HTuple(); HTuple hv_Exception = new HTuple(); HTuple hv_Text = new HTuple(); hv_Test_DLClassifierHandle.Dispose(); HOperatorSet.ReadDlClassifier(hv_Test_DlClassifierName, out hv_Test_DLClassifierHandle); //If it is not possible to accumulate more than one image at a time the batch size should be set to 1. HOperatorSet.SetDlClassifierParam(hv_Test_DLClassifierHandle, "batch_size", 1); //Set the runtime to 'cpu' to perform the inference on the CPU, if this is possible on the current hardware. //(see the system requirements in the Installation Guide) try { HOperatorSet.SetDlClassifierParam(hv_Test_DLClassifierHandle, "runtime", "cpu"); hv_Runtime.Dispose(); hv_Runtime = "cpu"; } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); //Keep the 'gpu' runtime if switching to 'cpu' failed. hv_Runtime.Dispose(); hv_Runtime = "gpu"; } //This initializes the runtime environment immediately. HOperatorSet.SetDlClassifierParam(hv_Test_DLClassifierHandle, "runtime_init", "immediately"); // //dev_disp_inference_text(hv_Runtime, hv_WindowHandle); // stop(...); only in hdevelop ho_ImagePreprocessed.Dispose(); preprocess_dl_classifier_images(this.ho_TestImage, out ho_ImagePreprocessed, new HTuple(), new HTuple(), hv_Test_DLClassifierHandle); hv_DLClassifierResultHandle.Dispose(); HOperatorSet.ApplyDlClassifier(ho_ImagePreprocessed, hv_Test_DLClassifierHandle, out hv_DLClassifierResultHandle); hv_Inference_PredictedClass.Dispose(); HOperatorSet.GetDlClassifierResult(hv_DLClassifierResultHandle, "all", "predicted_classes", out hv_Inference_PredictedClass); HOperatorSet.GetDlClassifierResult(hv_DLClassifierResultHandle, "all", "confidences", out hv_Inference_Confidences); // DispImageAdaptively(ref hv_HWindowControl, this.ho_TestImage); hv_Text.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Text = "Predicted class: " + hv_Inference_PredictedClass + "; Confidence: " + hv_Inference_Confidences; } HOperatorSet.DispText(hv_HWindowControl.HalconWindow, hv_Text, "window", "top", "left", "red", "box", "true"); HOperatorSet.DispText(hv_HWindowControl.HalconWindow, "Click to continue", "window", "bottom", "right", "black", new HTuple(), new HTuple()); this.ho_TestImage = null; }
// Procedures // Local procedures public void I40GetBaseRects(HObject ho_Modelright, HTuple hv_ModelID, out HTuple hv_rowVRect, out HTuple hv_colVRect, out HTuple hv_angleVRect, out HTuple hv_len1VRect, out HTuple hv_len2VRect, out HTuple hv_rowHRect, out HTuple hv_colHRect, out HTuple hv_angleHRect, out HTuple hv_len1HRect, out HTuple hv_len2HRect) { // Local iconic variables HObject ho_ROI_0, ho_ImageReduced; // Local control variables HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Angle = new HTuple(), hv_Score = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ROI_0); HOperatorSet.GenEmptyObj(out ho_ImageReduced); hv_rowVRect = new HTuple(); hv_colVRect = new HTuple(); hv_angleVRect = new HTuple(); hv_len1VRect = new HTuple(); hv_len2VRect = new HTuple(); hv_rowHRect = new HTuple(); hv_colHRect = new HTuple(); hv_angleHRect = new HTuple(); hv_len1HRect = new HTuple(); hv_len2HRect = new HTuple(); ho_ROI_0.Dispose(); HOperatorSet.GenRectangle1(out ho_ROI_0, 56.831, 111.206, 465.524, 1574.75); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Modelright, ho_ROI_0, out ho_ImageReduced); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); HOperatorSet.FindShapeModel(ho_ImageReduced, hv_ModelID, -0.39, 0.79, 0.2, 1, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column, out hv_Angle, out hv_Score); hv_rowVRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_rowVRect = hv_Row + 394; } hv_colVRect.Dispose(); hv_colVRect = new HTuple(hv_Column); hv_angleVRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_angleVRect = (new HTuple(-90)).TupleRad() ; } hv_len1VRect.Dispose(); hv_len1VRect = 20; hv_len2VRect.Dispose(); hv_len2VRect = 380; hv_colHRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_colHRect = hv_Column - 550; } hv_rowHRect.Dispose(); hv_rowHRect = new HTuple(hv_Row); hv_angleHRect.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_angleHRect = (new HTuple(-180)).TupleRad() ; } hv_len1HRect.Dispose(); hv_len1HRect = 20; hv_len2HRect.Dispose(); hv_len2HRect = 80; ho_ROI_0.Dispose(); ho_ImageReduced.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose(); return; }
// Procedures public void image_seg_paper(HObject ho_Image, out HObject ho_Image_rectified, HTuple hv_WindowHandle, HTuple hv_factorScale) { // Local iconic variables HObject ho_Region, ho_RegionFill, ho_ConnectedRegions; HObject ho_Paper, ho_Image_trans, ho_Rectangle, ho_Mask; // Local control variables HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_UsedThreshold = new HTuple(), hv_Area = new HTuple(); HTuple hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Rows = new HTuple(), hv_Cols = new HTuple(); HTuple hv_DistanceHeight = new HTuple(), hv_DistanceRMax = new HTuple(); HTuple hv_DistanceWidth = new HTuple(), hv_DistanceCMax = new HTuple(); HTuple hv_XCoordCorners = new HTuple(), hv_YCoordCorners = new HTuple(); HTuple hv_paperHeight = new HTuple(), hv_paperWidth = new HTuple(); HTuple hv_HomMat2D = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image_rectified); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionFill); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_Paper); HOperatorSet.GenEmptyObj(out ho_Image_trans); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_Mask); //** Prog hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); //对饱和度图像进行二值化 //* Detecting Paper //auto_threshold (Saturation, Regions, 20) ho_Region.Dispose(); hv_UsedThreshold.Dispose(); HOperatorSet.BinaryThreshold(ho_Image, out ho_Region, "max_separability", "light", out hv_UsedThreshold); ho_RegionFill.Dispose(); HOperatorSet.FillUpShape(ho_Region, out ho_RegionFill, "area", 1, 40000); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionFill, out ho_ConnectedRegions); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row, out hv_Column); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_Paper.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_Paper, "area", "and", hv_Area.TupleMax() , 9999999); } //* Detecting Corner hv_Rows.Dispose(); hv_Cols.Dispose(); region_get_corner(ho_Image, ho_Paper, hv_WindowHandle, out hv_Rows, out hv_Cols); //计算分割角点质检距离 //Distance := [] //for Index := 1 to 4 by 1 //if (Index == 4) //distance_pp (Rows[Index], Cols[Index], Rows[1], Cols[1], Distance) //break //endif //distance_pp (Rows[Index], Cols[Index], Rows[Index+1], Cols[Index+1], Distance) //endfor //dev_set_colored (12) //for Index := 1 to 4 by 1 //disp_circle (WindowHandle, Rows[Index], Cols[Index], 64) //endfor using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_DistanceHeight.Dispose(); hv_DistanceRMax.Dispose(); HOperatorSet.DistanceSs(hv_Rows.TupleSelect(1), hv_Cols.TupleSelect(1), hv_Rows.TupleSelect( 2), hv_Cols.TupleSelect(2), hv_Rows.TupleSelect(3), hv_Cols.TupleSelect(3), hv_Rows.TupleSelect(4), hv_Cols.TupleSelect(4), out hv_DistanceHeight, out hv_DistanceRMax); } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_DistanceWidth.Dispose(); hv_DistanceCMax.Dispose(); HOperatorSet.DistanceSs(hv_Rows.TupleSelect(2), hv_Cols.TupleSelect(2), hv_Rows.TupleSelect( 3), hv_Cols.TupleSelect(3), hv_Rows.TupleSelect(1), hv_Cols.TupleSelect(1), hv_Rows.TupleSelect(4), hv_Cols.TupleSelect(4), out hv_DistanceWidth, out hv_DistanceCMax); } hv_XCoordCorners.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_XCoordCorners = new HTuple(); hv_XCoordCorners = hv_XCoordCorners.TupleConcat(hv_Rows.TupleSelect( 2)); hv_XCoordCorners = hv_XCoordCorners.TupleConcat(hv_Rows.TupleSelect( 3)); hv_XCoordCorners = hv_XCoordCorners.TupleConcat(hv_Rows.TupleSelect( 4)); hv_XCoordCorners = hv_XCoordCorners.TupleConcat(hv_Rows.TupleSelect( 1)); } hv_YCoordCorners.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_YCoordCorners = new HTuple(); hv_YCoordCorners = hv_YCoordCorners.TupleConcat(hv_Cols.TupleSelect( 2)); hv_YCoordCorners = hv_YCoordCorners.TupleConcat(hv_Cols.TupleSelect( 3)); hv_YCoordCorners = hv_YCoordCorners.TupleConcat(hv_Cols.TupleSelect( 4)); hv_YCoordCorners = hv_YCoordCorners.TupleConcat(hv_Cols.TupleSelect( 1)); } //factorScale := 0.5 hv_paperHeight.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_paperHeight = hv_factorScale * hv_DistanceHeight; } hv_paperWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_paperWidth = hv_factorScale * hv_DistanceWidth; } using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HomMat2D.Dispose(); HOperatorSet.HomVectorToProjHomMat2d(hv_XCoordCorners, hv_YCoordCorners, (((new HTuple(1)).TupleConcat( 1)).TupleConcat(1)).TupleConcat(1), (((((new HTuple(0)).TupleConcat(hv_paperHeight))).TupleConcat( hv_paperHeight))).TupleConcat(0), ((((new HTuple(0)).TupleConcat(0)).TupleConcat( hv_paperWidth))).TupleConcat(hv_paperWidth), (((new HTuple(1)).TupleConcat( 1)).TupleConcat(1)).TupleConcat(1), "normalized_dlt", out hv_HomMat2D); } ho_Image_trans.Dispose(); HOperatorSet.ProjectiveTransImage(ho_Image, out ho_Image_trans, hv_HomMat2D, "bilinear", "false", "false"); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, 0, 0, hv_paperHeight, hv_paperWidth); ho_Mask.Dispose(); HOperatorSet.ReduceDomain(ho_Image_trans, ho_Rectangle, out ho_Mask); ho_Image_rectified.Dispose(); HOperatorSet.CropDomain(ho_Mask, out ho_Image_rectified); ho_Region.Dispose(); ho_RegionFill.Dispose(); ho_ConnectedRegions.Dispose(); ho_Paper.Dispose(); ho_Image_trans.Dispose(); ho_Rectangle.Dispose(); ho_Mask.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); hv_UsedThreshold.Dispose(); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Rows.Dispose(); hv_Cols.Dispose(); hv_DistanceHeight.Dispose(); hv_DistanceRMax.Dispose(); hv_DistanceWidth.Dispose(); hv_DistanceCMax.Dispose(); hv_XCoordCorners.Dispose(); hv_YCoordCorners.Dispose(); hv_paperHeight.Dispose(); hv_paperWidth.Dispose(); hv_HomMat2D.Dispose(); return; }