public bool LoadImage(string imagePath) { windowHandle.ClearWindow(); HObject ho_ImageRGB; HOperatorSet.ReadImage(out ho_ImageRGB, imagePath); HOperatorSet.GetImageSize(ho_ImageRGB, out hv_width, out hv_height); windowHandle.SetPart(0, 0, hv_height - 1, hv_width - 1); HTuple channelCount; HOperatorSet.CountChannels(ho_ImageRGB, out channelCount); ho_Image.Dispose(); if (channelCount >= 3) { HOperatorSet.AccessChannel(ho_ImageRGB, out ho_Image, 2); } else { HOperatorSet.AccessChannel(ho_ImageRGB, out ho_Image, 1); } windowHandle.DispObj(ho_Image); return(true); }
public void read_light_state(HObject ho_Image, HTuple hv_blue_num, HTuple hv_red_num, HTuple hv_yellow_num, out HTuple hv_outport_result) { // Local iconic variables HOperatorSet.WriteImage(ho_Image, "jpeg", 0, "light"); HObject ho_Rectangle, ho_lightImageReduced; HObject ho_ImageReducedChannel3, ho_lightRegions; // Local control variables HTuple hv_lightArea, hv_lightRow, hv_lightColumn; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_lightImageReduced); HOperatorSet.GenEmptyObj(out ho_ImageReducedChannel3); HOperatorSet.GenEmptyObj(out ho_lightRegions); hv_outport_result = new HTuple(); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle1(out ho_Rectangle, 215, 395, 300, 435); ho_lightImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_lightImageReduced); //rgb1_to_gray (lightImageReduced, grayImage) ho_ImageReducedChannel3.Dispose(); HOperatorSet.AccessChannel(ho_lightImageReduced, out ho_ImageReducedChannel3, 3); ho_lightRegions.Dispose(); HOperatorSet.Threshold(ho_ImageReducedChannel3, out ho_lightRegions, 157, 255); HOperatorSet.AreaCenter(ho_lightRegions, out hv_lightArea, out hv_lightRow, out hv_lightColumn); hv_outport_result[1] = hv_lightArea.TupleInt(); if ((int)(new HTuple(hv_lightArea.TupleGreater(hv_blue_num))) != 0) { //blue light 1000 hv_outport_result[0] = 3; } else if ((int)(new HTuple(hv_lightArea.TupleGreater(hv_red_num))) != 0) { //red light 400 hv_outport_result[0] = 2; } else if ((int)(new HTuple(hv_lightArea.TupleGreater(hv_yellow_num))) != 0) { //yellow light 40 hv_outport_result[0] = 1; } else { //no light hv_outport_result[0] = 0; } ho_Rectangle.Dispose(); ho_lightImageReduced.Dispose(); ho_ImageReducedChannel3.Dispose(); ho_lightRegions.Dispose(); return; }
// Main procedure private void action() { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_NewImage, ho_Image, ho_ImageSelected = null; HObject ho_Image1 = null; // Local control variables HTuple hv_AcqHandle = null, hv_ChannelCount = null; HTuple hv_Index = null, hv_Pointer = new HTuple(), hv_Type = new HTuple(); HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_NewImage); HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageSelected); HOperatorSet.GenEmptyObj(out ho_Image1); //Image Acquisition 01: Code generated by Image Acquisition 01 ho_NewImage.Dispose(); HOperatorSet.GenEmptyObj(out ho_NewImage); HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_AcqHandle); HOperatorSet.GrabImageStart(hv_AcqHandle, -1); //Image Acquisition 01: Do something ho_Image.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1); HOperatorSet.CountChannels(ho_Image, out hv_ChannelCount); HTuple end_val7 = hv_ChannelCount; HTuple step_val7 = 1; for (hv_Index = 1; hv_Index.Continue(end_val7, step_val7); hv_Index = hv_Index.TupleAdd(step_val7)) { ho_ImageSelected.Dispose(); HOperatorSet.AccessChannel(ho_Image, out ho_ImageSelected, hv_Index); HOperatorSet.GetImagePointer1(ho_ImageSelected, out hv_Pointer, out hv_Type, out hv_Width, out hv_Height); ho_Image1.Dispose(); HOperatorSet.GenImage1(out ho_Image1, "byte", hv_Width, hv_Height, hv_Pointer); { HObject ExpTmpOutVar_0; HOperatorSet.AppendChannel(ho_NewImage, ho_Image1, out ExpTmpOutVar_0); ho_NewImage.Dispose(); ho_NewImage = ExpTmpOutVar_0; } } HOperatorSet.CloseFramegrabber(hv_AcqHandle); ho_NewImage.Dispose(); ho_Image.Dispose(); ho_ImageSelected.Dispose(); ho_Image1.Dispose(); }
public static HObject GetChannnelImageUpdate(HObject Image, int ImageIndex) { if (Image == null || ImageIndex < 0) { return(null); } HOperatorSet.CountChannels(Image, out HTuple channels); if (ImageIndex >= channels) { return(null); } HOperatorSet.GenEmptyObj(out HObject ImageReturn); if (channels == 1) { ImageReturn = Image; } else if (channels > 1) { //1122-lw HOperatorSet.AccessChannel(Image, out ImageReturn, ImageIndex + 1); //1121-lht //ImageReturn = Image; //HOperatorSet.GenEmptyObj(out HObject ImageR); //HOperatorSet.GenEmptyObj(out HObject ImageG); //HOperatorSet.GenEmptyObj(out HObject ImageB); //HOperatorSet.GenEmptyObj(out HObject ImageConcact); //HOperatorSet.Decompose3(Image, out ImageR, out ImageG, out ImageB); //HOperatorSet.ConcatObj(ImageConcact, Image, out ImageConcact); //HOperatorSet.ConcatObj(ImageConcact, ImageR, out ImageConcact); //HOperatorSet.ConcatObj(ImageConcact, ImageG, out ImageConcact); //HOperatorSet.ConcatObj(ImageConcact, ImageB, out ImageConcact); //HOperatorSet.SelectObj(ImageConcact, out HObject ChannelImage, ImageIndex+1); //ImageReturn = ChannelImage; //ImageR.Dispose(); //ImageG.Dispose(); //ImageB.Dispose(); //ImageConcact.Dispose(); } return(ImageReturn); }
private static void scale_image_range(HObject ho_Image, out HObject ho_ImageScaled, HTuple hv_Min, HTuple hv_Max) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_SelectedChannel = null, ho_LowerRegion = null; HObject ho_UpperRegion = null; // Local copy input parameter variables HObject ho_Image_COPY_INP_TMP; ho_Image_COPY_INP_TMP = ho_Image.CopyObj(1, -1); // Local control variables HTuple hv_LowerLimit = new HTuple(), hv_UpperLimit = new HTuple(); HTuple hv_Mult = null, hv_Add = null, hv_Channels = null; HTuple hv_Index = null, hv_MinGray = new HTuple(), hv_MaxGray = new HTuple(); HTuple hv_Range = new HTuple(); HTuple hv_Max_COPY_INP_TMP = hv_Max.Clone(); HTuple hv_Min_COPY_INP_TMP = hv_Min.Clone(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ImageScaled); HOperatorSet.GenEmptyObj(out ho_SelectedChannel); HOperatorSet.GenEmptyObj(out ho_LowerRegion); HOperatorSet.GenEmptyObj(out ho_UpperRegion); //Convenience procedure to scale the gray values of the //input image Image from the interval [Min,Max] //to the interval [0,255] (default). //Gray values < 0 or > 255 (after scaling) are clipped. // //If the image shall be scaled to an interval different from [0,255], //this can be achieved by passing tuples with 2 values [From, To] //as Min and Max. //Example: //scale_image_range(Image:ImageScaled:[100,50],[200,250]) //maps the gray values of Image from the interval [100,200] to [50,250]. //All other gray values will be clipped. // //input parameters: //Image: the input image //Min: the minimum gray value which will be mapped to 0 // If a tuple with two values is given, the first value will // be mapped to the second value. //Max: The maximum gray value which will be mapped to 255 // If a tuple with two values is given, the first value will // be mapped to the second value. // //output parameter: //ImageScale: the resulting scaled image // if ((int)(new HTuple((new HTuple(hv_Min_COPY_INP_TMP.TupleLength())).TupleEqual( 2))) != 0) { hv_LowerLimit = hv_Min_COPY_INP_TMP[1]; hv_Min_COPY_INP_TMP = hv_Min_COPY_INP_TMP[0]; } else { hv_LowerLimit = 0.0; } if ((int)(new HTuple((new HTuple(hv_Max_COPY_INP_TMP.TupleLength())).TupleEqual( 2))) != 0) { hv_UpperLimit = hv_Max_COPY_INP_TMP[1]; hv_Max_COPY_INP_TMP = hv_Max_COPY_INP_TMP[0]; } else { hv_UpperLimit = 255.0; } // //Calculate scaling parameters hv_Mult = (((hv_UpperLimit - hv_LowerLimit)).TupleReal()) / (hv_Max_COPY_INP_TMP - hv_Min_COPY_INP_TMP); hv_Add = ((-hv_Mult) * hv_Min_COPY_INP_TMP) + hv_LowerLimit; // //Scale image { HObject ExpTmpOutVar_0; HOperatorSet.ScaleImage(ho_Image_COPY_INP_TMP, out ExpTmpOutVar_0, hv_Mult, hv_Add); ho_Image_COPY_INP_TMP.Dispose(); ho_Image_COPY_INP_TMP = ExpTmpOutVar_0; } // //Clip gray values if necessary //This must be done for each channel separately HOperatorSet.CountChannels(ho_Image_COPY_INP_TMP, out hv_Channels); HTuple end_val48 = hv_Channels; HTuple step_val48 = 1; for (hv_Index = 1; hv_Index.Continue(end_val48, step_val48); hv_Index = hv_Index.TupleAdd(step_val48)) { ho_SelectedChannel.Dispose(); HOperatorSet.AccessChannel(ho_Image_COPY_INP_TMP, out ho_SelectedChannel, hv_Index); HOperatorSet.MinMaxGray(ho_SelectedChannel, ho_SelectedChannel, 0, out hv_MinGray, out hv_MaxGray, out hv_Range); ho_LowerRegion.Dispose(); HOperatorSet.Threshold(ho_SelectedChannel, out ho_LowerRegion, ((hv_MinGray.TupleConcat( hv_LowerLimit))).TupleMin(), hv_LowerLimit); ho_UpperRegion.Dispose(); HOperatorSet.Threshold(ho_SelectedChannel, out ho_UpperRegion, hv_UpperLimit, ((hv_UpperLimit.TupleConcat(hv_MaxGray))).TupleMax()); { HObject ExpTmpOutVar_0; HOperatorSet.PaintRegion(ho_LowerRegion, ho_SelectedChannel, out ExpTmpOutVar_0, hv_LowerLimit, "fill"); ho_SelectedChannel.Dispose(); ho_SelectedChannel = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.PaintRegion(ho_UpperRegion, ho_SelectedChannel, out ExpTmpOutVar_0, hv_UpperLimit, "fill"); ho_SelectedChannel.Dispose(); ho_SelectedChannel = ExpTmpOutVar_0; } if ((int)(new HTuple(hv_Index.TupleEqual(1))) != 0) { ho_ImageScaled.Dispose(); HOperatorSet.CopyObj(ho_SelectedChannel, out ho_ImageScaled, 1, 1); } else { { HObject ExpTmpOutVar_0; HOperatorSet.AppendChannel(ho_ImageScaled, ho_SelectedChannel, out ExpTmpOutVar_0 ); ho_ImageScaled.Dispose(); ho_ImageScaled = ExpTmpOutVar_0; } } } ho_Image_COPY_INP_TMP.Dispose(); ho_SelectedChannel.Dispose(); ho_LowerRegion.Dispose(); ho_UpperRegion.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 static void scale_image_range(HObject ho_Image, out HObject ho_ImageScaled, HTuple hv_Min, HTuple hv_Max) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_ImageSelected = null, ho_SelectedChannel = null; HObject ho_LowerRegion = null, ho_UpperRegion = null, ho_ImageSelectedScaled = null; // Local copy input parameter variables HObject ho_Image_COPY_INP_TMP; ho_Image_COPY_INP_TMP = ho_Image.CopyObj(1, -1); HTuple hv_LowerLimit = new HTuple(), hv_UpperLimit = new HTuple(); HTuple hv_Mult = null, hv_Add = null, hv_NumImages = null; HTuple hv_ImageIndex = null, hv_Channels = new HTuple(); HTuple hv_ChannelIndex = new HTuple(), hv_MinGray = new HTuple(); HTuple hv_MaxGray = new HTuple(), hv_Range = new HTuple(); HTuple hv_Max_COPY_INP_TMP = hv_Max.Clone(); HTuple hv_Min_COPY_INP_TMP = hv_Min.Clone(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ImageScaled); HOperatorSet.GenEmptyObj(out ho_ImageSelected); HOperatorSet.GenEmptyObj(out ho_SelectedChannel); HOperatorSet.GenEmptyObj(out ho_LowerRegion); HOperatorSet.GenEmptyObj(out ho_UpperRegion); HOperatorSet.GenEmptyObj(out ho_ImageSelectedScaled); try { if ((int)(new HTuple((new HTuple(hv_Min_COPY_INP_TMP.TupleLength())).TupleEqual( 2))) != 0) { hv_LowerLimit = hv_Min_COPY_INP_TMP.TupleSelect(1); hv_Min_COPY_INP_TMP = hv_Min_COPY_INP_TMP.TupleSelect(0); } else { hv_LowerLimit = 0.0; } if ((int)(new HTuple((new HTuple(hv_Max_COPY_INP_TMP.TupleLength())).TupleEqual( 2))) != 0) { hv_UpperLimit = hv_Max_COPY_INP_TMP.TupleSelect(1); hv_Max_COPY_INP_TMP = hv_Max_COPY_INP_TMP.TupleSelect(0); } else { hv_UpperLimit = 255.0; } // //Calculate scaling parameters. hv_Mult = (((hv_UpperLimit - hv_LowerLimit)).TupleReal()) / (hv_Max_COPY_INP_TMP - hv_Min_COPY_INP_TMP); hv_Add = ((-hv_Mult) * hv_Min_COPY_INP_TMP) + hv_LowerLimit; // //Scale image. { HObject ExpTmpOutVar_0; HOperatorSet.ScaleImage(ho_Image_COPY_INP_TMP, out ExpTmpOutVar_0, hv_Mult, hv_Add); ho_Image_COPY_INP_TMP.Dispose(); ho_Image_COPY_INP_TMP = ExpTmpOutVar_0; } // //Clip gray values if necessary. //This must be done for each image and channel separately. ho_ImageScaled.Dispose(); HOperatorSet.GenEmptyObj(out ho_ImageScaled); HOperatorSet.CountObj(ho_Image_COPY_INP_TMP, out hv_NumImages); HTuple end_val49 = hv_NumImages; HTuple step_val49 = 1; for (hv_ImageIndex = 1; hv_ImageIndex.Continue(end_val49, step_val49); hv_ImageIndex = hv_ImageIndex.TupleAdd(step_val49)) { ho_ImageSelected.Dispose(); HOperatorSet.SelectObj(ho_Image_COPY_INP_TMP, out ho_ImageSelected, hv_ImageIndex); HOperatorSet.CountChannels(ho_ImageSelected, out hv_Channels); HTuple end_val52 = hv_Channels; HTuple step_val52 = 1; for (hv_ChannelIndex = 1; hv_ChannelIndex.Continue(end_val52, step_val52); hv_ChannelIndex = hv_ChannelIndex.TupleAdd(step_val52)) { ho_SelectedChannel.Dispose(); HOperatorSet.AccessChannel(ho_ImageSelected, out ho_SelectedChannel, hv_ChannelIndex); HOperatorSet.MinMaxGray(ho_SelectedChannel, ho_SelectedChannel, 0, out hv_MinGray, out hv_MaxGray, out hv_Range); ho_LowerRegion.Dispose(); HOperatorSet.Threshold(ho_SelectedChannel, out ho_LowerRegion, ((hv_MinGray.TupleConcat( hv_LowerLimit))).TupleMin(), hv_LowerLimit); ho_UpperRegion.Dispose(); HOperatorSet.Threshold(ho_SelectedChannel, out ho_UpperRegion, hv_UpperLimit, ((hv_UpperLimit.TupleConcat(hv_MaxGray))).TupleMax()); { HObject ExpTmpOutVar_0; HOperatorSet.PaintRegion(ho_LowerRegion, ho_SelectedChannel, out ExpTmpOutVar_0, hv_LowerLimit, "fill"); ho_SelectedChannel.Dispose(); ho_SelectedChannel = ExpTmpOutVar_0; } { HObject ExpTmpOutVar_0; HOperatorSet.PaintRegion(ho_UpperRegion, ho_SelectedChannel, out ExpTmpOutVar_0, hv_UpperLimit, "fill"); ho_SelectedChannel.Dispose(); ho_SelectedChannel = ExpTmpOutVar_0; } if ((int)(new HTuple(hv_ChannelIndex.TupleEqual(1))) != 0) { ho_ImageSelectedScaled.Dispose(); HOperatorSet.CopyObj(ho_SelectedChannel, out ho_ImageSelectedScaled, 1, 1); } else { { HObject ExpTmpOutVar_0; HOperatorSet.AppendChannel(ho_ImageSelectedScaled, ho_SelectedChannel, out ExpTmpOutVar_0); ho_ImageSelectedScaled.Dispose(); ho_ImageSelectedScaled = ExpTmpOutVar_0; } } } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_ImageScaled, ho_ImageSelectedScaled, out ExpTmpOutVar_0 ); ho_ImageScaled.Dispose(); ho_ImageScaled = ExpTmpOutVar_0; } } ho_Image_COPY_INP_TMP.Dispose(); ho_ImageSelected.Dispose(); ho_SelectedChannel.Dispose(); ho_LowerRegion.Dispose(); ho_UpperRegion.Dispose(); ho_ImageSelectedScaled.Dispose(); return; } catch (HalconException HDevExpDefaultException) { ho_Image_COPY_INP_TMP.Dispose(); ho_ImageSelected.Dispose(); ho_SelectedChannel.Dispose(); ho_LowerRegion.Dispose(); ho_UpperRegion.Dispose(); ho_ImageSelectedScaled.Dispose(); throw HDevExpDefaultException; } }
private void hWindowControl1_HMouseMove(object sender, HMouseEventArgs e) { if (_ho_Image.IsInitialized()) { try { int button_state; double positionX, positionY; hWindowControl1.HalconWindow.GetMpositionSubPix(out positionY, out positionX, out button_state);//得到亚像素组成 取得坐标,及鼠标的状态 switch (button_state) { case 0: this.Cursor = System.Windows.Forms.Cursors.Default; //显示鼠标类型为手型 #region 显示像素 string str_value; string str_position; bool _isXOut = true, _isYOut = true; HTuple channel_count; //元素 HOperatorSet.CountChannels(_ho_Image, out channel_count); //计算图片的通道 str_position = String.Format("X: {0:0000.0}, Y: {1:0000.0}", positionX, positionY); //把坐标转成字符 HTuple width, height; HOperatorSet.GetImageSize(_ho_Image, out width, out height); _isXOut = (positionX < 0 || positionX >= (double)width); //判断是否超出范围,超出为1 _isYOut = (positionY < 0 || positionY >= (double)height); //判断是否超出范围,超出为1 if (!_isXOut && !_isYOut) { if ((int)channel_count == 1) { HTuple grayval; HOperatorSet.GetGrayval(_ho_Image, (HTuple)positionY, (HTuple)positionX, out grayval); str_value = String.Format("灰度值: {0:000.0}", (double)grayval); //显示出去 } else { if ((int)channel_count == 3) { str_value = ""; HTuple grayValRed, grayValGreen, grayValBlue; HObject _RedChannel, _GreenChannel, _BlueChannel; HOperatorSet.GenEmptyObj(out _RedChannel); HOperatorSet.GenEmptyObj(out _GreenChannel); HOperatorSet.GenEmptyObj(out _BlueChannel); HOperatorSet.AccessChannel(_ho_Image, out _RedChannel, 1); HOperatorSet.AccessChannel(_ho_Image, out _GreenChannel, 2); HOperatorSet.AccessChannel(_ho_Image, out _BlueChannel, 3); HOperatorSet.GetGrayval(_RedChannel, (HTuple)positionY, (HTuple)positionX, out grayValRed); HOperatorSet.GetGrayval(_GreenChannel, (HTuple)positionY, (HTuple)positionX, out grayValGreen); HOperatorSet.GetGrayval(_BlueChannel, (HTuple)positionY, (HTuple)positionX, out grayValBlue); _RedChannel.Dispose(); _GreenChannel.Dispose(); _BlueChannel.Dispose(); str_value = String.Format("Val: ({0:000.0}, {1:000.0}, {2:000.0})", (double)grayValRed, (double)grayValGreen, (double)grayValBlue); //显示3个通道的灰度值 } else { str_value = ""; } } StatusMessage.Text = str_position + " " + str_value; } #endregion break; case 1: this.Cursor = System.Windows.Forms.Cursors.Hand; //显示鼠标类型为手型 switch (_roiStatus) { case ROIStatus.ChioceROI: #region 拉动ROI _roiControl.setROISelectedPoint(positionX, positionY); if (this.ROIPointMoveEvent != null) { this.ROIPointMoveEvent(); } #endregion break; case ROIStatus.NoChioceROI: #region 拉动图片 HSystem.SetSystem("flush_graphic", "false"); //防止图片频闪 hWindowControl1.HalconWindow.ClearWindow(); //清空窗体类容 hWindowControl1.HalconWindow.SetPaint(new HTuple("default")); //设置显示默认 // 保持图像显示比例 zoom_beginRow -= (int)(positionY - _start_positionY); zoom_beginCol -= (int)(positionX - _start_positionX); zoom_endRow -= (int)(positionY - _start_positionY); #region 无用代码 //if (zoom_endRow == zoom_beginRow) //{ // //HOperatorSet.GetImageSize(_ho_Image); // zoom_endRow = 2000; //} #endregion zoom_endCol -= (int)(positionX - _start_positionX); if ((zoom_endCol == zoom_beginCol) || (zoom_endRow == zoom_beginRow)) { HTuple w, h; HOperatorSet.GetImageSize(_ho_Image, out w, out h); zoom_endCol = (int)w; zoom_endRow = (int)h; } hWindowControl1.HalconWindow.SetPart(zoom_beginRow, zoom_beginCol, zoom_endRow, zoom_endCol); // hWindowControl1.HalconWindow.DispObj(_ho_Image);//显示图片 HSystem.SetSystem("flush_graphic", "true"); #endregion break; } #region 重新刷新图片 this._halconWindow1.DispObj(this.Ho_Image); if (this.RepaintingROI != null) { this.RepaintingROI(null, null); } #endregion break; } } catch (Exception ex) { StatusMessage.Text = ex.Message; } } }
private void hWindowControl1_HMouseMove(object sender, HMouseEventArgs e) { if (Ho_Image.IsInitialized()) { try { int button_state; double positionX, positionY; string str_value; string str_position; bool _isXOut = true, _isYOut = true; HTuple channel_count; //元素 HOperatorSet.CountChannels(Ho_Image, out channel_count); //计算图片的通道 _halconWindow1.GetMpositionSubPix(out positionY, out positionX, out button_state); //得到亚像素组成 取得坐标,及鼠标的状态 str_position = String.Format("X: {0:0000.0}, Y: {1:0000.0}", positionX, positionY); //把坐标转成字符格式 HTuple width, height; HOperatorSet.GetImageSize(Ho_Image, out width, out height); _isXOut = (positionX < 0 || positionX >= (double)width); //判断是否超出范围,超出为1 _isYOut = (positionY < 0 || positionY >= (double)height); //判断是否超出范围,超出为1 if (!_isXOut && !_isYOut) { if ((int)channel_count == 1) { HTuple grayval; HOperatorSet.GetGrayval(Ho_Image, (HTuple)positionY, (HTuple)positionX, out grayval); str_value = String.Format("灰度值: {0:000.0}", (double)grayval);//显示出去 } else { if ((int)channel_count == 3) { str_value = ""; HTuple grayValRed, grayValGreen, grayValBlue; HObject _RedChannel, _GreenChannel, _BlueChannel; HOperatorSet.GenEmptyObj(out _RedChannel); HOperatorSet.GenEmptyObj(out _GreenChannel); HOperatorSet.GenEmptyObj(out _BlueChannel); HOperatorSet.AccessChannel(Ho_Image, out _RedChannel, 1); HOperatorSet.AccessChannel(Ho_Image, out _GreenChannel, 2); HOperatorSet.AccessChannel(Ho_Image, out _BlueChannel, 3); HOperatorSet.GetGrayval(_RedChannel, (HTuple)positionY, (HTuple)positionX, out grayValRed); HOperatorSet.GetGrayval(_GreenChannel, (HTuple)positionY, (HTuple)positionX, out grayValGreen); HOperatorSet.GetGrayval(_BlueChannel, (HTuple)positionY, (HTuple)positionX, out grayValBlue); _RedChannel.Dispose(); _GreenChannel.Dispose(); _BlueChannel.Dispose(); str_value = String.Format("Val: ({0:000.0}, {1:000.0}, {2:000.0})", (double)grayValRed, (double)grayValGreen, (double)grayValBlue);//显示3个通道的灰度值 } else { str_value = ""; } } StatusMessage.Text = str_position + " " + str_value; } switch (button_state) { case 0: this.Cursor = System.Windows.Forms.Cursors.Default; //显示鼠标类型为手型 break; case 1: this.Cursor = System.Windows.Forms.Cursors.Hand; //显示鼠标类型为手型 _halconWindow1.ClearWindow(); //清空窗体类容 _halconWindow1.SetPaint(new HTuple("default")); //设置显示默认 // 保持图像显示比例 zoom_beginRow -= (int)(positionY - _start_positionY); zoom_beginCol -= (int)(positionX - _start_positionX); zoom_endRow -= (int)(positionY - _start_positionY); zoom_endCol -= (int)(positionX - _start_positionX); _halconWindow1.SetPart(zoom_beginRow, zoom_beginCol, zoom_endRow, zoom_endCol); _halconWindow1.DispObj(Ho_Image); //显示图片 break; } } catch (Exception ex) { StatusMessage.Text = ex.Message; } } }
private void winContr_GCP_HMouseMove(object sender, HMouseEventArgs e) { if (image == null /*|| *//*bShowImagePoint == false*/ /*|| bVideo == true*/) { return; } try { HTuple htuple; HOperatorSet.CountChannels(image, out htuple); double row; double column; int button; winContr_GCP.HalconWindow.GetMpositionSubPix(out row, out column, out button); string ss1 = string.Format("Y: {0:0000.0},X: {1:0000.0}", row, column); if (column >= 0.0 && column < width && (row >= 0.0 && row < height)) { string ss2; if ((htuple) == 1) //ss2 = string.Format("Val: {0:000.0}", himage.GetGrayval((int)row, (int)column)); { HTuple value = 0; HOperatorSet.GetGrayval(image, (int)row, (int)column, out value); ss2 = string.Format("灰度值: {0:000.0}", value); } else if ((htuple) == 3) { //HImage R = himage.AccessChannel(1); //HImage G = himage.AccessChannel(2); //HImage B = himage.AccessChannel(3); HObject R, G, B; HOperatorSet.GenEmptyObj(out R); HOperatorSet.GenEmptyObj(out G); HOperatorSet.GenEmptyObj(out B); HOperatorSet.AccessChannel(image, out R, 1); HOperatorSet.AccessChannel(image, out G, 2); HOperatorSet.AccessChannel(image, out B, 3); HTuple grayval1; HTuple grayval2; HTuple grayval3; HOperatorSet.GetGrayval(R, (int)row, (int)column, out grayval1); HOperatorSet.GetGrayval(G, (int)row, (int)column, out grayval2); HOperatorSet.GetGrayval(B, (int)row, (int)column, out grayval3); //double grayval1 = R.GetGrayval((int)row, (int)column); //double grayval2 = G.GetGrayval((int)row, (int)column); //double grayval3 = B.GetGrayval((int)row, (int)column); (R).Dispose(); (G).Dispose(); (B).Dispose(); ss2 = string.Format("灰度值: ({0:000.0}, {1:000.0}, {2:000.0})", grayval1, grayval2, grayval3); } else { ss2 = ""; } m_CtrlHStatusLabelCtrl.Text = str_imgSize + " " + ss1 + " " + ss2; } } catch (Exception ex) { } }
private void hWindowControl1_HMouseMove(object sender, HMouseEventArgs e) { if (_ho_Image.IsInitialized()) { try { int button_state; double positionX, positionY; string str_value; string str_position; bool _isXOut = true, _isYOut = true; HTuple channel_count; //元素 HOperatorSet.CountChannels(_ho_Image, out channel_count); //计算图片的通道 hWindowControl1.HalconWindow.GetMpositionSubPix(out positionY, out positionX, out button_state); //得到亚像素组成 取得坐标,及鼠标的状态 str_position = String.Format("X: {0:0000.0}, Y: {1:0000.0}", positionX, positionY); //把坐标转成字符格式 HTuple width, height; HOperatorSet.GetImageSize(_ho_Image, out width, out height); _isXOut = (positionX < 0 || positionX >= (double)width); //判断是否超出范围,超出为1 _isYOut = (positionY < 0 || positionY >= (double)height); //判断是否超出范围,超出为1 if (!_isXOut && !_isYOut) { if ((int)channel_count == 1) { HTuple grayval; HOperatorSet.GetGrayval(_ho_Image, (HTuple)positionY, (HTuple)positionX, out grayval); str_value = String.Format("灰度值: {0:000.0}", (double)grayval);//显示出去 } else { if ((int)channel_count == 3) { str_value = ""; HTuple grayValRed, grayValGreen, grayValBlue; HObject _RedChannel, _GreenChannel, _BlueChannel; HOperatorSet.GenEmptyObj(out _RedChannel); HOperatorSet.GenEmptyObj(out _GreenChannel); HOperatorSet.GenEmptyObj(out _BlueChannel); HOperatorSet.AccessChannel(_ho_Image, out _RedChannel, 1); HOperatorSet.AccessChannel(_ho_Image, out _GreenChannel, 2); HOperatorSet.AccessChannel(_ho_Image, out _BlueChannel, 3); HOperatorSet.GetGrayval(_RedChannel, (HTuple)positionY, (HTuple)positionX, out grayValRed); HOperatorSet.GetGrayval(_GreenChannel, (HTuple)positionY, (HTuple)positionX, out grayValGreen); HOperatorSet.GetGrayval(_BlueChannel, (HTuple)positionY, (HTuple)positionX, out grayValBlue); _RedChannel.Dispose(); _GreenChannel.Dispose(); _BlueChannel.Dispose(); str_value = String.Format("Val: ({0:000.0}, {1:000.0}, {2:000.0})", (double)grayValRed, (double)grayValGreen, (double)grayValBlue);//显示3个通道的灰度值 } else { str_value = ""; } } StatusMessage.Text = str_position + " " + str_value; } switch (button_state) { case 0: this.Cursor = System.Windows.Forms.Cursors.Default; //显示鼠标类型为手型 break; case 1: if (this.SanDHuoErDXianShiBiaoZhi == false) { HSystem.SetSystem("flush_graphic", "false"); //防止图片频闪 this.Cursor = System.Windows.Forms.Cursors.Hand; //显示鼠标类型为手型 hWindowControl1.HalconWindow.ClearWindow(); //清空窗体类容 //hWindowControl1.HalconWindow.SetPaint(new HTuple("default"));//设置显示默认 //保持图像显示比例 zoom_beginRow -= (int)(positionY - _start_positionY); zoom_beginCol -= (int)(positionX - _start_positionX); zoom_endRow -= (int)(positionY - _start_positionY); //if (zoom_endRow == zoom_beginRow) //{ //HOperatorSet.GetImageSize(_ho_Image); //zoom_endRow = 2000; //} zoom_endCol -= (int)(positionX - _start_positionX); if ((zoom_endCol == zoom_beginCol) || (zoom_endRow == zoom_beginRow)) { HTuple w, h; HOperatorSet.GetImageSize(_ho_Image, out w, out h); zoom_endCol = (int)w; zoom_endRow = (int)h; } hWindowControl1.HalconWindow.SetPart(zoom_beginRow, zoom_beginCol, zoom_endRow, zoom_endCol); HSystem.SetSystem("flush_graphic", "true"); hWindowControl1.HalconWindow.DispObj(_ho_Image); //显示图片 } else { HTuple hv_mode = new HTuple(); hv_mode = "rotate"; HSystem.SetSystem("flush_graphic", "false"); //防止图片频闪 this.Cursor = System.Windows.Forms.Cursors.Hand; //显示鼠标类型为手型 hWindowControl1.HalconWindow.ClearWindow(); //清空窗体类容 hWindowControl1.HalconWindow.UpdateWindowPose(hv_lastRow, hv_lastCol, positionY, positionX, hv_mode); HSystem.SetSystem("flush_graphic", "true"); hWindowControl1.HalconWindow.DispObj(_ho_Image); //显示图片 } break; } hv_lastCol = positionX; hv_lastRow = positionY; } catch (Exception ex) { StatusMessage.Text = ex.Message; } } }
// Procedures #if !NO_EXPORT_MAIN // Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_ImageRotate, ho_ROI_0; HObject ho_ImageReduced, ho_Regions, ho_RegionFillUp, ho_ConnectedRegions; HObject ho_SelectedRegions, ho_BinImage, ho_Characters; HObject ho_Image2, ho_ImageRotate2, ho_ROI_02, ho_ImageReduced2; HObject ho_Regions2, ho_RegionFillUp2, ho_ConnectedRegions2; HObject ho_SelectedRegions2, ho_BinImage2, ho_Characters2; // Local control variables HTuple hv_AcqHandle = null, hv_Width = null; HTuple hv_Height = null, hv_TextModel = null, hv_TextResultID = null; HTuple hv_ResultValue = null, hv_Width2 = null, hv_Height2 = null; HTuple hv_TextModel2 = null, hv_TextResultID2 = null, hv_ResultValue2 = null; HTuple hv_license = null, hv_container = null, hv_licLength = null; HTuple hv_i = null, hv_conLength = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageRotate); HOperatorSet.GenEmptyObj(out ho_ROI_0); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_BinImage); HOperatorSet.GenEmptyObj(out ho_Characters); HOperatorSet.GenEmptyObj(out ho_Image2); HOperatorSet.GenEmptyObj(out ho_ImageRotate2); HOperatorSet.GenEmptyObj(out ho_ROI_02); HOperatorSet.GenEmptyObj(out ho_ImageReduced2); HOperatorSet.GenEmptyObj(out ho_Regions2); HOperatorSet.GenEmptyObj(out ho_RegionFillUp2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_BinImage2); HOperatorSet.GenEmptyObj(out ho_Characters2); //open_framegrabber ('GenICamTL', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', '0x305316d5c4', 0, -1, AcqHandle) //Image Acquisition 01: Code generated by Image Acquisition 01 //Image Acquisition 01: Code generated by Image Acquisition 01 HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", "licenseCam", 0, -1, out hv_AcqHandle); //open_framegrabber ('GigEVision', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', 'licenseCam', 0, -1, AcqHandle) HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "AcquisitionMode", "SingleFrame"); //set_framegrabber_param (AcqHandle, 'ExposureTimeAbs', 55555.0) HOperatorSet.GrabImageStart(hv_AcqHandle, -1); // ho_Image.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); ho_ImageRotate.Dispose(); HOperatorSet.RotateImage(ho_Image, out ho_ImageRotate, 0, "constant"); ho_Image.Dispose(); HOperatorSet.AccessChannel(ho_ImageRotate, out ho_Image, 1); //OLD //gen_rectangle1 (ROI_0, 431.688, 468.25, 607.938, 1265.75) //gen_rectangle1 (ROI_0, 442.63, 403.582, 632.248, 1275.42) ho_ROI_0.Dispose(); HOperatorSet.GenRectangle1(out ho_ROI_0, 490.034, 428.071, 681.714, 1339.09); //Remove large blobs //gray_closing_rect (Image, ImageClosing, 10, 10) //sub_image (Image, ImageClosing, ImageSub, 3, 0) // //Preprocessing to enhance contrast ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced); ho_Regions.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, 0, 80); ho_RegionFillUp.Dispose(); HOperatorSet.FillUpShape(ho_Regions, out ho_RegionFillUp, "area", 0, 40); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionFillUp, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 150, 99999); ho_BinImage.Dispose(); HOperatorSet.RegionToBin(ho_SelectedRegions, out ho_BinImage, 0, 255, hv_Width, hv_Height); // //Perform OCR using the automatic text model reader HOperatorSet.CreateTextModelReader("auto", "Industrial_0-9+_Rej.omc", out hv_TextModel); //set_text_model_param (TextModel, 'max_char_height', 200) //set_text_model_param (TextModel, 'min_char_height', 20) //set_text_model_param (TextModel, 'min_char_width', 5) //set_text_model_param (TextModel, 'max_char_width', 175) //set_text_model_param (TextModel, 'return_separators', 'false') //set_text_model_param (TextModel, 'min_contrast', 30) HOperatorSet.FindText(ho_BinImage, hv_TextModel, out hv_TextResultID); // //Get the results from the OCR ho_Characters.Dispose(); HOperatorSet.GetTextObject(out ho_Characters, hv_TextResultID, "all_lines"); HOperatorSet.GetTextResult(hv_TextResultID, "class", out hv_ResultValue); // if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Characters, HDevWindowStack.GetActive()); } //do memory cleanup here if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } dev_update_on(); HOperatorSet.CloseFramegrabber(hv_AcqHandle); //********************************************second camera //Image Acquisition 02: Code generated by Image Acquisition 02 //open_framegrabber ('GigEVision', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', 'containerCam', 0, -1, AcqHandle) //Image Acquisition 02: Code generated by Image Acquisition 02 HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", "containerCam", 0, -1, out hv_AcqHandle); //open_framegrabber ('GenICamTL', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', '0x3053228741', 0, -1, AcqHandle) //set_framegrabber_param (AcqHandle, 'ExposureTimeAbs', 55555.0) HOperatorSet.GrabImageStart(hv_AcqHandle, -1); // ho_Image2.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image2, hv_AcqHandle, -1); HOperatorSet.GetImageSize(ho_Image2, out hv_Width2, out hv_Height2); ho_ImageRotate2.Dispose(); HOperatorSet.RotateImage(ho_Image2, out ho_ImageRotate2, 180, "constant"); ho_Image2.Dispose(); HOperatorSet.AccessChannel(ho_ImageRotate2, out ho_Image2, 1); //OLD //gen_rectangle1 (ROI_02, 330.438, 690.75, 459.813, 1548.25) //gen_rectangle1 (ROI_02, 30.416, 658.276, 199.424, 1564.4) ho_ROI_02.Dispose(); HOperatorSet.GenRectangle1(out ho_ROI_02, -4.62214, 670.52, 114.92, 1527.66); //Remove large blobs //gray_closing_rect (Image2, ImageClosing2, 10, 10) //sub_image (Image2, ImageClosing2, ImageSub2, 3, 180) // //Preprocessing to enhance contrast ho_ImageReduced2.Dispose(); HOperatorSet.ReduceDomain(ho_Image2, ho_ROI_02, out ho_ImageReduced2); ho_Regions2.Dispose(); HOperatorSet.Threshold(ho_ImageReduced2, out ho_Regions2, 0, 120); ho_RegionFillUp2.Dispose(); HOperatorSet.FillUpShape(ho_Regions2, out ho_RegionFillUp2, "area", 0, 40); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionFillUp2, out ho_ConnectedRegions2); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions2, "area", "and", 150, 99999); ho_BinImage2.Dispose(); HOperatorSet.RegionToBin(ho_SelectedRegions2, out ho_BinImage2, 255, 0, hv_Width2, hv_Height2); // //Perform OCR using the automatic text model reader HOperatorSet.CreateTextModelReader("auto", "Industrial_0-9A-Z_Rej.omc", out hv_TextModel2); //set_text_model_param (TextModel2, 'max_char_height', 200) //set_text_model_param (TextModel2, 'min_char_height', 1) //set_text_model_param (TextModel2, 'min_char_width', 1) //set_text_model_param (TextModel2, 'max_char_width', 175) //set_text_model_param (TextModel2, 'return_separators', 'false') //set_text_model_param (TextModel2, 'min_contrast', 30) HOperatorSet.FindText(ho_BinImage2, hv_TextModel2, out hv_TextResultID2); // //Get the results from the OCR ho_Characters2.Dispose(); HOperatorSet.GetTextObject(out ho_Characters2, hv_TextResultID2, "all_lines"); HOperatorSet.GetTextResult(hv_TextResultID2, "class", out hv_ResultValue2); // if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image2, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Characters2, HDevWindowStack.GetActive()); } //do memory cleanup here if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } dev_update_on(); HOperatorSet.CloseFramegrabber(hv_AcqHandle); hv_license = ""; hv_container = ""; HOperatorSet.TupleStrlen(hv_ResultValue, out hv_licLength); HOperatorSet.TupleSum(hv_licLength, out hv_licLength); HTuple end_val117 = hv_licLength - 1; HTuple step_val117 = 1; for (hv_i = 0; hv_i.Continue(end_val117, step_val117); hv_i = hv_i.TupleAdd(step_val117)) { hv_license = hv_license + (hv_ResultValue.TupleSelect(hv_i)); } HOperatorSet.TupleStrlen(hv_ResultValue2, out hv_conLength); HOperatorSet.TupleSum(hv_conLength, out hv_conLength); HTuple end_val122 = hv_conLength - 1; HTuple step_val122 = 1; for (hv_i = 0; hv_i.Continue(end_val122, step_val122); hv_i = hv_i.TupleAdd(step_val122)) { hv_container = hv_container + (hv_ResultValue2.TupleSelect(hv_i)); } hv_license = hv_license.TupleSelect(0); ho_Image.Dispose(); ho_ImageRotate.Dispose(); ho_ROI_0.Dispose(); ho_ImageReduced.Dispose(); ho_Regions.Dispose(); ho_RegionFillUp.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_BinImage.Dispose(); ho_Characters.Dispose(); ho_Image2.Dispose(); ho_ImageRotate2.Dispose(); ho_ROI_02.Dispose(); ho_ImageReduced2.Dispose(); ho_Regions2.Dispose(); ho_RegionFillUp2.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_BinImage2.Dispose(); ho_Characters2.Dispose(); }