Example #1
0
        public void SobelFilter(HDrawingObject dobj, HWindow hwin, string type)
        {
            try
            {
                HObject region = null;

                if (dobj.GetDrawingObjectParams("type") == "line")
                {
                    HTuple a = dobj.GetDrawingObjectParams("row1");
                    HOperatorSet.GenRegionLine(out region, dobj.GetDrawingObjectParams("row1"),
                                               dobj.GetDrawingObjectParams("column1"), dobj.GetDrawingObjectParams("row2"),
                                               dobj.GetDrawingObjectParams("column2"));
                }
                else
                {
                    region = new HRegion(dobj.GetDrawingObjectIconic());
                }

                AddToStack(region);
                DisplayResults();
            }
            catch (HalconException hex)
            {
                MessageBox.Show(hex.GetErrorMessage(), "HALCON error", MessageBoxButtons.OK);
            }
        }
Example #2
0
        private void CreateTemplete(object sender, EventArgs e)
        {
            HTuple CenterRow    = ObjectRoi.GetDrawingObjectParams("row");
            HTuple CenterColumn = ObjectRoi.GetDrawingObjectParams("column");
            HTuple Phi          = ObjectRoi.GetDrawingObjectParams("phi");
            HTuple Lenght1      = ObjectRoi.GetDrawingObjectParams("length1");
            HTuple Lenght2      = ObjectRoi.GetDrawingObjectParams("length2");

            HObject ModelRegion;

            HOperatorSet.GenEmptyObj(out ModelRegion);
            HOperatorSet.GenRectangle2(out ModelRegion, CenterRow, CenterColumn, Phi, Lenght1, Lenght2);

            HObject TemplateImage;

            HOperatorSet.GenEmptyObj(out TemplateImage);
            HOperatorSet.ReduceDomain(ho_Image, ModelRegion, out TemplateImage);

            HTuple hv_ParameterValue = null, hv_ParameterName = null;

            HOperatorSet.DetermineShapeModelParams(TemplateImage, "auto", 0, (new HTuple(360)).TupleRad(), 0.9, 1.1, "auto", "use_polarity", "auto", "auto", "all", out hv_ParameterName, out hv_ParameterValue);
            HTuple MinContrast          = hv_ParameterValue[7].I.ToString();
            HTuple Location_MaxContrast = hv_ParameterValue[5].I.ToString();

            HOperatorSet.CreateShapeModel(TemplateImage, 0, 0, (new HTuple(360)).TupleRad(), "auto", "auto", "use_polarity", int.Parse(Location_MaxContrast), int.Parse(MinContrast), out hv_ModelID);

            if (File.Exists(Directory.GetCurrentDirectory() + @"/Templete.shm"))
            {
                File.Delete(Directory.GetCurrentDirectory() + @"/Templete.shm");
                HOperatorSet.WriteShapeModel(hv_ModelID, Directory.GetCurrentDirectory() + @"/Templete.shm");
            }
            else
            {
                HOperatorSet.WriteShapeModel(hv_ModelID, Directory.GetCurrentDirectory() + @"/Templete.shm");
            }

            ModelRegion.Dispose();
            TemplateImage.Dispose();
        }