// Procedures public void test_barcode(HObject ho_Image, HTuple hv_WindowHandle) { // Local iconic variables HObject ho_SymbolRegions = null; // Local control variables HTuple hv_BarCodeHandle = new HTuple(), hv_DecodedDataStrings = new HTuple(); HTuple hv_BarcodeLocation = new HTuple(), hv_Exception = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolRegions); try { //* Init Barcode这行代码放到初始化位置,函数最上边,打开相机之前 HOperatorSet.SetCurrentDir("C:/Users/iwake/OneDrive - wake/Desktop/HalconPractise/HalconProj/Barcode"); hv_BarCodeHandle.Dispose(); HOperatorSet.ReadBarCodeModel("BarCodeHandle.bcm", out hv_BarCodeHandle); //set_bar_code_param (BarCodeHandle, 'check_char', 'present') HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", 1); //* Recognition Barcode这行代码什么时候想识别二维码放到那里,输入Image,BarCodeHandle, WindowHandle, //*输出SymbolRegions,DecodedDataStrings, BarcodeLocation try { ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_BarcodeLocation.Dispose(); image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, hv_WindowHandle, out hv_DecodedDataStrings, out hv_BarcodeLocation); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); } ho_SymbolRegions.Dispose(); hv_BarCodeHandle.Dispose(); hv_DecodedDataStrings.Dispose(); hv_BarcodeLocation.Dispose(); hv_Exception.Dispose(); return; } catch (HalconException HDevExpDefaultException) { ho_SymbolRegions.Dispose(); hv_BarCodeHandle.Dispose(); hv_DecodedDataStrings.Dispose(); hv_BarcodeLocation.Dispose(); hv_Exception.Dispose(); throw HDevExpDefaultException; } }
// Main procedure private void action() { // Local iconic variables HObject ho_Image; // Local control variables HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "printer_chip/printer_chip_01"); if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_Image.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); }
private void hWindowControl_HMouseMove(object sender, HMouseEventArgs e) { hv_MouseRow.Dispose(); hv_MouseCol.Dispose(); HOperatorSet.GetMposition(hv_WindowHandle, out hv_MouseRow, out hv_MouseCol, out _); if (MoveImage) { HTuple Row0 = new HTuple(), Column0 = new HTuple(); HTuple Row00 = new HTuple(), Column00 = new HTuple(); HTuple hv_dx = new HTuple(); HTuple hv_dy = new HTuple(); try { HOperatorSet.GetPart(hv_WindowHandle, out Row0, out Column0, out Row00, out Column00); hv_dy.Dispose(); hv_dx.Dispose(); hv_dy = hv_MouseRow - hv_MouseDownRow; hv_dx = hv_MouseCol - hv_MouseDownCol; HOperatorSet.SetPart(hv_WindowHandle, Row0 - hv_dy, Column0 - hv_dx, Row00 - hv_dy, Column00 - hv_dx); } catch { } finally { hv_dy.Dispose(); hv_dx.Dispose(); Row0.Dispose(); Column0.Dispose(); Row00.Dispose(); Column00.Dispose(); } } else { HTuple pointGray = new HTuple(); try { if (!ho_Image.IsInitialized()) { return; } if (hv_MouseRow > 0 && hv_MouseRow < hv_ImageHeight - 1 && hv_MouseCol > 0 && hv_MouseCol < hv_ImageWidth - 1) { pointGray.Dispose(); HOperatorSet.GetGrayval(ho_Image, hv_MouseRow, hv_MouseCol, out pointGray); StatusLabel.Text = $"X:{hv_MouseCol} Y:{hv_MouseRow} Value:{pointGray}"; } else { StatusLabel.Text = $"X:{hv_MouseCol} Y:{hv_MouseRow} Value:-"; } } catch { } finally { pointGray.Dispose(); hv_MouseRow.Dispose(); hv_MouseCol.Dispose(); hv_MouseVal.Dispose(); } } }
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_Image = null; // Local control variables HTuple hv_AcqHandle = new HTuple(), hv_Mean = new HTuple(); HTuple hv_Deviation = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); //Image Acquisition 02: Code generated by Image Acquisition 02 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); HOperatorSet.GrabImageStart(hv_AcqHandle, -1); while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1); //Image Acquisition 02: Do something hv_Mean.Dispose(); hv_Deviation.Dispose(); HOperatorSet.Intensity(ho_Image, ho_Image, out hv_Mean, out hv_Deviation); } HOperatorSet.CloseFramegrabber(hv_AcqHandle); ho_Image.Dispose(); hv_AcqHandle.Dispose(); hv_Mean.Dispose(); hv_Deviation.Dispose(); }
// 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 image_get_bar(HObject ho_Image, out HObject ho_SymbolRegions, HTuple hv_BarCodeHandle, out HTuple hv_DecodedDataStrings, out HTuple hv_someitem) { // Local iconic variables // Local control variables HTuple hv_CodeTypes = new HTuple(), hv_Width = new HTuple(); HTuple hv_Height = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolRegions); hv_DecodedDataStrings = new HTuple(); hv_someitem = new HTuple(); try { // //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 // hv_CodeTypes.Dispose(); hv_CodeTypes = "Code 128"; // //Set display defaults hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_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) hv_CodeTypes.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); return; } catch (HalconException HDevExpDefaultException) { hv_CodeTypes.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); throw HDevExpDefaultException; } }
// Procedures public void image_judge_stop(HObject ho_ImageBefore, HObject ho_ImageLater, out HObject ho_Selected, out HTuple hv_juadge_stop) { // Local iconic variables // Local control variables HTuple hv_Area = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Selected); hv_juadge_stop = new HTuple(); //** 初始化图片 //* 测试traffic demo //read_image (ImageBefore, 'traffic1') //read_image (ImageLater, 'traffic2') //* 测试 高拍测试 //read_image (ImageBefore, 'C:/Users/iwake/MVS/Data/Hos0.bmp') //read_image (ImageLater, 'C:/Users/iwake/MVS/Data/Hos1.bmp') //read_image (ImageLater2, 'C:/Users/iwake/MVS/Data/Hos2.bmp') //* 对比图像 //difference //diff_of_gauss (ImageLater, DiffOfGauss, 3, 1.6) //traffic demo 参数 //check_difference (ImageBefore, ImageLater2, Selected, 'diff_outside', -15, 255, 0, 0, 0) //高拍测试 参数 ho_Selected.Dispose(); HOperatorSet.CheckDifference(ho_ImageBefore, ho_ImageLater, out ho_Selected, "diff_outside", -15, 255, 0, 0, 0); hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); HOperatorSet.AreaCenter(ho_Selected, out hv_Area, out hv_Row, out hv_Column); //disp_obj (Selected, WindowHandle) //** 判断 hv_juadge_stop.Dispose(); hv_juadge_stop = 0; if ((int)(new HTuple(hv_Area.TupleLessEqual(10000))) != 0) { hv_juadge_stop.Dispose(); hv_juadge_stop = 1; } hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); return; }
private void hWindowControl_HMouseWheel(object sender, HMouseEventArgs e) { HTuple Zoom = new HTuple(), Ht = new HTuple(), Wt = new HTuple(), r1 = new HTuple(), c1 = new HTuple(), r2 = new HTuple(), c2 = new HTuple(), Row = new HTuple(), Col = new HTuple(), Row0 = new HTuple(), Column0 = new HTuple(), Row00 = new HTuple(), Column00 = new HTuple(); try { Zoom.Dispose(); if (e.Delta > 0) { Zoom = 2; } else { Zoom = 0.5; } Row.Dispose(); Col.Dispose(); HOperatorSet.GetMposition(hv_WindowHandle, out Row, out Col, out _); Row0.Dispose(); Column0.Dispose(); Row00.Dispose(); Column00.Dispose(); HOperatorSet.GetPart(hv_WindowHandle, out Row0, out Column0, out Row00, out Column00); Ht = Row00 - Row0; Wt = Column00 - Column0; if (Ht * Wt < 32768 * 32768 || Zoom == 2.0) { r1 = (Row0 + ((1 - (1.0 / Zoom)) * (Row - Row0))); c1 = (Column0 + ((1 - (1.0 / Zoom)) * (Col - Column0))); r2 = r1 + (Ht / Zoom); c2 = c1 + (Wt / Zoom); HOperatorSet.SetPart(hv_WindowHandle, r1, c1, r2, c2); } } catch { } Zoom.Dispose(); Ht.Dispose(); Wt.Dispose(); r1.Dispose(); c1.Dispose(); r2.Dispose(); c2.Dispose(); Row.Dispose(); Col.Dispose(); Row0.Dispose(); Column0.Dispose(); Row00.Dispose(); Column00.Dispose(); }
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(); }
public void image_class_mia(HObject ho_Image, HTuple hv_WindowHandle, out HTuple hv_DecodedDataStrings) { // Local iconic variables HObject ho_SymbolXLDs; // Local control variables HTuple hv_DataCodeHandle = new HTuple(), hv_ResultHandles = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SymbolXLDs); hv_DecodedDataStrings = new HTuple(); //* INIT BARCODE //create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle) //create_data_code_2d_model ('Data Matrix ECC 200', 'maximum_recognition', [], DataCodeHandle) //create_data_code_2d_model ('Data Matrix ECC 200', 'train', 'all', DataCodeHandle) //*train //read_image (ImageTrain, 'C:/Users/iwake/OneDrive - wake/Desktop/Mia/Images/V3/3CWDL.bmp') //* find_data_code_2d (ImageTrain, SymbolXLDs, DataCodeHandle, 'train', 'all', \ // ResultHandlesTrain, DecodedDataStringsTrain) //*end train hv_DataCodeHandle.Dispose(); HOperatorSet.ReadDataCode2dModel("C:/Users/iwake/OneDrive - wake/Desktop/BarCode/Halcon/DataCodeHandle.dcm", out hv_DataCodeHandle); ho_SymbolXLDs.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose(); HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle, "stop_after_result_num", 1, out hv_ResultHandles, out hv_DecodedDataStrings); //find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, 'symbol_search', 1, ResultHandles, DecodedDataStrings1) //image_display_datacode(ho_SymbolXLDs, hv_ResultHandles, hv_WindowHandle, hv_DecodedDataStrings, hv_DataCodeHandle); ho_SymbolXLDs.Dispose(); hv_DataCodeHandle.Dispose(); hv_ResultHandles.Dispose(); return; }
// Main procedure private void action() { // Local iconic variables HObject ho_Image; // Local control variables HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, "printer_chip/printer_chip_01"); HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle); hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_Image.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); }
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); }
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(); }
/// <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); } }
public void ComputeConfusionMatrix(HTuple hv_WindowHandle) { HOperatorSet.ClearWindow(hv_WindowHandle); hv_Train_DLClassifierHandle.Dispose(); HOperatorSet.ReadDlClassifier(this.hv_Trained_DlClassifierName, out hv_Train_DLClassifierHandle); // //Compute the confusion matrix for the validation data set. hv_PredictedClassesValidation.Dispose(); get_predicted_classes(hv_ValidationImages, hv_Train_DLClassifierHandle, out hv_PredictedClassesValidation); hv_ConfusionMatrix.Dispose(); gen_confusion_matrix(hv_ValidationLabels, hv_PredictedClassesValidation, new HTuple(), new HTuple(), hv_WindowHandle, out hv_ConfusionMatrix); HOperatorSet.DispText(hv_WindowHandle, "Validation data", "window", "top", "left", "gray", "box", "false"); HOperatorSet.DispText(hv_WindowHandle, "Click to continue...", "window", "bottom", "right", "black", new HTuple(), new HTuple()); }
private void btn_Open_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { ofd.Title = "Open Image File"; ofd.Filter = "Image|*.jpg;*.bmp;*.gif;*.png"; if (ofd.ShowDialog() == DialogResult.OK && ofd.FileName != null) { // Open document string filename = ofd.FileName; ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, filename); hv_ImageWidth.Dispose(); hv_ImageHeight.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight); HOperatorSet.DispObj(ho_Image, hv_WindowHandle); ResetWindow(ref hWindowControl, hv_ImageHeight, hv_ImageWidth); } } }
private void DispTestInformation() { HTuple hv_Text = new HTuple(); // Initialize local and output iconic variables hv_Text.Dispose(); hv_Text = "INFERENCE"; hv_Text[new HTuple(hv_Text.TupleLength())] = ""; hv_Text[new HTuple(hv_Text.TupleLength())] = "This part of the program is a brief introduction on how to "; hv_Text[new HTuple(hv_Text.TupleLength())] = "make use of your trained classifier. "; hv_Text[new HTuple(hv_Text.TupleLength())] = ""; hv_Text[new HTuple(hv_Text.TupleLength())] = "It is important that the same preprocessing as for the training "; hv_Text[new HTuple(hv_Text.TupleLength())] = "of the classifier is applied to the raw images. "; hv_Text[new HTuple(hv_Text.TupleLength())] = ""; if ((int)(new HTuple(hv_Runtime.TupleEqual("cpu"))) != 0) { hv_Text[new HTuple(hv_Text.TupleLength())] = "The 'cpu' runtime has been selected for inference."; } }
private void hWindowControl_HMouseDown(object sender, HMouseEventArgs e) { try { if (hv_MouseRow > 0 && hv_MouseRow < hv_ImageHeight - 1 && hv_MouseCol > 0 && hv_MouseCol < hv_ImageWidth - 1) { hv_MouseDownRow.Dispose(); hv_MouseDownRow = hv_MouseRow; hv_MouseDownCol.Dispose(); hv_MouseDownCol = hv_MouseCol; MoveImage = true; } else { MoveImage = false; } } catch { } }
public static bool affineTransPixel(HTuple initialRow, HTuple initialCol, HTuple checkRow, HTuple checkCol, HTuple checkPhi, out HTuple tansRow, out HTuple transCol) { try { HTuple hv_HomMat2D = new HTuple(); HTuple homMat2DTranslate = new HTuple(); HTuple homMat2DRotate = new HTuple(); hv_HomMat2D.Dispose(); homMat2DTranslate.Dispose(); homMat2DRotate.Dispose(); HOperatorSet.HomMat2dIdentity(out hv_HomMat2D); HOperatorSet.HomMat2dTranslate(hv_HomMat2D, checkRow, checkCol, out homMat2DTranslate); HOperatorSet.HomMat2dRotate(homMat2DTranslate, checkPhi, checkRow, checkCol, out homMat2DRotate); HOperatorSet.AffineTransPixel(homMat2DRotate, initialRow, initialCol, out tansRow, out transCol); return(true); } catch (Exception) { tansRow = -1; transCol = -1; return(false); } }
// 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; }
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; }
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; }
/// <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() { // 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(); }
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() { // 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(); }
// 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; }