private void DisplayModelControur() { hWndCtrller.AddIconicVar(Model.ModelImg); hWndCtrller.ChangeGraphicSettings("Color", "blue"); hWndCtrller.AddIconicVar(Model.SearchRegion); hWndCtrller.ChangeGraphicSettings("Color", "green"); hWndCtrller.ChangeGraphicSettings("DrawMode", "margin"); HHomMat2D mat2D = new HHomMat2D(); mat2D.VectorAngleToRigid(0.0, 0.0, 0.0, Model.ModelImgRow, Model.ModelImgCol, Model.ModelimgAng); HXLDCont cont = Model.GetModelCont(); if (cont != null) { double row, col; Model.shapeModel.GetShapeModelOrigin(out row, out col); mat2D = mat2D.HomMat2dTranslateLocal(row, col); hWndCtrller.AddIconicVar(cont.AffineTransContourXld(mat2D)); cont.Dispose(); } }
public HXLDCont GetMatchModelCont(int index) { HXLDCont hXLD = GetModelCont(); if (hXLD == null) { return(null); } HXLDCont cont = null; if (index < OutputResult.Count) { HHomMat2D mat2d = new HHomMat2D(); mat2d = mat2d.HomMat2dScale(OutputResult.Scale[index], OutputResult.Scale[index], 0d, 0d); mat2d = mat2d.HomMat2dRotate(OutputResult.Angle[index], 0d, 0d); mat2d = mat2d.HomMat2dTranslate(OutputResult.Row[index].D, OutputResult.Col[index].D); cont = hXLD.AffineTransContourXld(mat2d); } return(cont); }
// Procedure to find the coins and to read the serialized item from a // file stream private void Action() { HRegion Coin, Circle; HTuple Row, Column, Angle, Score, ResultModel; if (ImgNum == 0) { MatchingLabel.Text = "Deserialize shape models..."; MatchingLabel.Refresh(); //Reading names Stream s = File.OpenRead("serialized_shape_model"); Names = HTuple.Deserialize(s); //Reading shape models for (int i = 0; i < 4; i++) { Models[i] = HShapeModel.Deserialize(s); } s.Close(); MatchingLabel.Text = "Deserialize shape models... OK"; MatchingLabel.Refresh(); } if (ImgNum == 13) { ImgNum = 0; } HTuple Zero; if (ImgNum + 1 < 10) { Zero = "0"; } else { Zero = ""; } //Find shape based model using the read models Img.ReadImage("coins/20cent_" + Zero + (ImgNum + 1).ToString() + ".png"); ImgNum++; HRegion Region = Img.Threshold(70.0, 255.0); HRegion ConnectedRegions = Region.Connection(); HRegion SelectedRegions = ConnectedRegions.SelectShapeStd("max_area", 0); HRegion RegionTrans = SelectedRegions.ShapeTrans("convex"); Coin = new HRegion(RegionTrans.Row, RegionTrans.Column, 120); Circle = new HRegion(Coin.Row, Coin.Column, 35); HImage ImgReduced = Img.ReduceDomain(Circle); ImgReduced.FindShapeModels(Models, 0.0, new HTuple(360.0).TupleRad(), 0.6, 1, 0, "interpolation", 0, 0.9, out Row, out Column, out Angle, out Score, out ResultModel); HXLDCont ModelContours = Models[ResultModel.I].GetShapeModelContours(1); HHomMat2D HomMat2D = new HHomMat2D(); Window.SetColor("green"); HomMat2D.VectorAngleToRigid(0, 0, 0, Row, Column, Angle); HXLDCont ContoursAffineTrans = ModelContours.AffineTransContourXld(HomMat2D); HSystem.SetSystem("flush_graphic", "false"); Window.DispObj(Img); HSystem.SetSystem("flush_graphic", "true"); Window.DispObj(ContoursAffineTrans); MatchingLabel.Text = "#" + (ImgNum + 1) + ": Found: " + Names[ResultModel.I] + " coin"; }