private void btn_GrabTraget_Click(object sender, EventArgs e) { if (m_modleHandle != null) { try { HTuple _column = new HTuple(), _angle = new HTuple(), _score = new HTuple(); HOperatorSet.FindShapeModel(m_image, m_modleHandle, m_paramFind.AngleStart, m_paramFind.AngleExtent, m_paramFind.MinScore, m_paramFind.NumMatch, m_paramFind.MaxOverLap, m_paramFind.SubPixel, m_paramFind.NumLevels, m_paramFind.Greediness, out HTuple _row, out _column, out _angle, out _score); hDisplay1.HRegionXList = null; if (_row.TupleLength() > 0) { List <RegionX> lr = new List <RegionX>(); for (int i = 0; i < _row.TupleLength(); i++) { HObject _modlecountor = new HObject(); HOperatorSet.GetShapeModelContours(out _modlecountor, m_modleHandle, 1); HTuple _hommat2d; HOperatorSet.VectorAngleToRigid(0, 0, 0, _row.DArr[i], _column.DArr[i], _angle.DArr[i], out _hommat2d); HObject _transcountor; HOperatorSet.AffineTransContourXld(_modlecountor, out _transcountor, _hommat2d); HalWindow.RegionX regionX = new HalWindow.RegionX(_transcountor, "green"); lr.Add(regionX); } hDisplay1.HImageX = m_image; hDisplay1.HRegionXList = lr; } else { hDisplay1.HImageX = m_image; hDisplay1.HRegionXList = null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "异常"); } } }
private void btn_TrainModle_Click(object sender, EventArgs e) { if (hDisplay1.GetTrainRegions().Count == 0) { MessageBox.Show("请先设置模板区域", "提示"); return; } try { HObject _imagereduced = new HObject(); HOperatorSet.ReduceDomain(m_image, hDisplay1.GetTrainRegions().ElementAt(0), out _imagereduced); HOperatorSet.CreateShapeModel(_imagereduced, m_paramTrain.NumLevels, m_paramTrain.AngleStart, m_paramTrain.AngleExtent, m_paramTrain.AngleStep, m_paramTrain.Optimization, m_paramTrain.Metric, m_paramTrain.Contrast, m_paramTrain.MinContrast, out m_modleHandle); HTuple _column = new HTuple(), _angle = new HTuple(), _score = new HTuple(); HOperatorSet.FindShapeModel(_imagereduced, m_modleHandle, m_paramFind.AngleStart, m_paramFind.AngleExtent, m_paramFind.MinScore, m_paramFind.NumMatch, m_paramFind.MaxOverLap, m_paramFind.SubPixel, m_paramFind.NumLevels, m_paramFind.Greediness, out HTuple _row, out _column, out _angle, out _score); HOperatorSet.WriteShapeModel(m_modleHandle, AppDomain.CurrentDomain.BaseDirectory + "123.shm"); if (_row.TupleLength() > 0) { HObject _modlecountor = new HObject(); HOperatorSet.GetShapeModelContours(out _modlecountor, m_modleHandle, 1); HTuple _hommat2d; HOperatorSet.VectorAngleToRigid(0, 0, 0, _row.D, _column.D, _angle.D, out _hommat2d); HObject _transcountor; HOperatorSet.AffineTransContourXld(_modlecountor, out _transcountor, _hommat2d); HalWindow.RegionX regionX = new HalWindow.RegionX(_transcountor, "green"); hDisplay1.HRegionXList = new List <RegionX>() { regionX }; } } catch (Exception ex) { MessageBox.Show(ex.Message, "异常"); } }