private void AffineTransModelContour(HShapeModel model, HRegion modelRegion) { if (model != null && modelRegion != null) { try { //获取金字塔第一层轮廓 HXLDCont modelContour = model.GetShapeModelContours(1); double num3, num4; modelRegion.AreaCenter(out num3, out num4); HHomMat2D matd = new HHomMat2D(); matd.VectorAngleToRigid(0.0, 0.0, 0.0, num3, num4, 0.0); HXLD affterAffineModelXLD = matd.AffineTransContourXld(modelContour); if (info.IsShowModelXLD) { Window.SetColor("green"); affterAffineModelXLD.DispXld(Window.Window); } } catch (Exception e) { WriteErrorLog("VisionTool", e.ToString()); } } }
//仿射变换后的全部轮廓 public void GenDetectionXLDResults(HXLDCont modelXldCont) { if (resultXLDCont == null) { resultXLDCont = new HXLDCont(); } if (resultXLDCont != null && resultXLDCont.IsInitialized()) { resultXLDCont.Dispose(); } resultXLDCont.GenEmptyObj(); HXLDCont rContours; for (int i = 0; i < row.Length; i++) { HHomMat2D mat1 = new HHomMat2D(); mat1.VectorAngleToRigid(0, 0, 0, row[i].D, column[i].D, angle[i].D); mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D); //图像偏移 rContours = mat1.AffineTransContourXld(modelXldCont); //获取模板集合 resultXLDCont = resultXLDCont.ConcatObj(rContours); rContours.Dispose(); rContours.GenCrossContourXld(row[i].D, column[i].D, 10, angle[i].D); resultXLDCont = resultXLDCont.ConcatObj(rContours); rContours.Dispose(); } }
public override HMessage ActorTask(HMessage imsg) { HTuple row, column, angle, score; HImage img = new HImage(imsg.GetMessageObj("image")); if (sbm == null) { return(GenFinishMessage()); } HMessage msg = new HMessage(); msg.SetMessageObj(img, "image"); Monitor.Enter(lockobj); try { sbm.FindShapeModel(img, -Math.PI, 2 * Math.PI, 0.5, 1, 0.5, "least_squares", 0, 0.9, out row, out column, out angle, out score); if (row.Length > 0) { HXLDCont contours = sbm.GetShapeModelContours(1); HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, row.D, column.D, angle.D); HXLDCont projcont = homMat2D.AffineTransContourXld(contours); msg.SetMessageObj(projcont, "contour"); } } finally { Monitor.Exit(lockobj); } imsg.Dispose(); return(msg); }
public override HMessage ActorTask(HMessage obj) { HTuple isempty = msg_queue.GetMessageQueueParam("is_empty"); if (isempty.I == 0) { msg_queue.SetMessageQueueParam("flush_queue", 1); } if (obj != null) { obj.Dispose(); } HTuple row, column, angle, score; HImage img; img = imggrabber.GrabImageAsync(-1); HRegion roi = new HRegion(ActiveObject); HMessage msg = new HMessage(); msg.SetMessageObj(img, "image"); Monitor.Enter(lockobj); try { if (sbm != null) { sbm.Dispose(); } sbm = new HShapeModel(img.ReduceDomain(roi), "auto", -Math.PI, 2 * Math.PI, "auto", "auto", "use_polarity", "auto", "auto"); sbm.FindShapeModel(img, 0.0, 0.0, 0.5, 1, 0.5, "least_squares", 0, 0.9, out row, out column, out angle, out score); if (row.Length > 0) { HXLDCont contours = sbm.GetShapeModelContours(1); HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, row.D, column.D, angle.D); HXLDCont projcont = homMat2D.AffineTransContourXld(contours); msg.SetMessageObj(projcont, "contour"); } else { sbm.Dispose(); sbm = null; } } finally { Monitor.Exit(lockobj); } return(msg); }
/// <summary> /// Gets the detected contour. /// </summary> /// <returns>Detected contour</returns> public HXLDCont getDetectionResults() { HXLDCont rContours = new HXLDCont(); hmat.HomMat2dIdentity(); mContResults.GenEmptyObj(); for (int i = 0; i < count; i++) { hmat.VectorAngleToRigid(0, 0, 0, mRow[i].D, mCol[i].D, mAngle[i].D); rContours = hmat.AffineTransContourXld(mContour); mContResults = mContResults.ConcatObj(rContours); } return(mContResults); }
/// <summary> /// Gets the detected contour. /// </summary> /// <returns>Detected contour</returns> public HXLDCont getDetectionResults() { HXLDCont rContours = new HXLDCont(); hmat.HomMat2dIdentity(); if (mContResults != null) { mContResults.Dispose(); } mContResults.GenEmptyObj(); for (int i = 0; i < count; i++) { if (mImageScale < 0.1 || mImageScale > 2) { mImageScale = 1.0; } hmat.VectorAngleToRigid(0, 0, 0, mRow[i].D * mImageScale, mCol[i].D * mImageScale, mAngle[i].D); //2020.11.7 gengxmÐÞ¸Ä £¬ÂÖÀª·Å´óÈý±¶ hmat = hmat.HomMat2dScale(1.0000 / mImageScale, 1.0000 / mImageScale, 0, 0); rContours = hmat.AffineTransContourXld(mContour); mContResults = mContResults.ConcatObj(rContours); } if (rContours != null) { rContours.Dispose(); } if (true) { HTuple convexity; HTuple col1, col2, row1, row2; HOperatorSet.SmallestRectangle1Xld(mContResults, out row1, out col1, out row2, out col2); HOperatorSet.ConvexityXld(mContResults, out convexity); // wid = col2 - col1; //hei = row2 - row1; } return(mContResults); }
public HXLDCont TransContXLD(HXLDCont xldContour) { try { HHomMat2D matd = new HHomMat2D(); matd.VectorAngleToRigid(this.info.ModelRegionRow, this.info.ModelRegionCol, this.info.ModelRegionAngle, this.info.ResultY, this.info.ResultX, this.info.ResultAngle); if (IsSuccess) { xldContour = matd.AffineTransContourXld(xldContour); return(xldContour); } } catch (Exception ex) { WriteErrorLog("VisionTool", ToolName + "模板" + ex.ToString()); } return(null); }
public void ShowShapeModel(HWndCtrl viewCtrl) { if (modelRegion == null || !modelRegion.IsInitialized()) { return; } if (ModelXLDCont == null || !ModelXLDCont.IsInitialized()) { return; } viewCtrl.ChangeGraphicSettings(Mode.DRAWMODE, "margin"); if (modelRegion != null && modelRegion.IsInitialized()) { viewCtrl.ChangeGraphicSettings(Mode.COLOR, "blue"); viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 2); viewCtrl.AddIconicVar(modelRegion); } if (modelXLDContAffine == null) { modelXLDContAffine = new HXLDCont(); } if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized()) { modelXLDContAffine.Dispose(); } if (refCoordinates == null || refCoordinates.Length != 3) { return; } HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, refCoordinates[0].D, refCoordinates[1].D, refCoordinates[2].D); modelXLDContAffine = homMat2D.AffineTransContourXld(ModelXLDCont); if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized()) { viewCtrl.ChangeGraphicSettings(Mode.COLOR, "red"); viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 1); viewCtrl.AddIconicVar(modelXLDContAffine); } }
/// <summary> /// Gets the model supplied by a loaded shapebased model file (.shm) /// </summary> public HXLD getLoadedModelContour() { HTuple row1, col1, row2, col2, row, col; HHomMat2D homMat2D = new HHomMat2D(); try { tResult.mContour.SmallestRectangle1Xld(out row1, out col1, out row2, out col2); row2 = row1.TupleMin(); col2 = col1.TupleMin(); row = row2.TupleFloor() - 5; col = col2.TupleFloor() - 5; homMat2D.HomMat2dIdentity(); homMat2D = homMat2D.HomMat2dTranslate(-row, -col); return(homMat2D.AffineTransContourXld(tResult.mContour)); } catch (HOperatorException e) { exceptionText = e.Message; NotifyIconObserver(MatchingAssistant.ERR_READ_SHAPEMODEL); return(null); } }
public bool FindDataCode(HImage img, HRegion region, bool train = false) { if (!region.IsInitialized()) { region = img.GetDomain(); } if (!train) { Display(0, region); } HImage reduceImg = img.ReduceDomain(region); HImage searchImg = reduceImg.CropDomain(); reduceImg.Dispose(); int width, height; searchImg.GetImageSize(out width, out height); HImage zoomImg = searchImg.ZoomImageFactor(DateCodeZoomImg, DateCodeZoomImg, "constant"); DataCodeContour.Dispose(); searchImg.Dispose(); HTuple ResultHandles, DecodedDataStrings; if (train) { DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "train", "all", out ResultHandles, out DecodedDataStrings); } else { DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings); } if (DecodedDataStrings.Length > 0) { DataCodeString = DecodedDataStrings[0].S; HHomMat2D mat = new HHomMat2D(); HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0); double row, col; region.AreaCenter(out row, out col); HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0); HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour); DataCodeContour.Dispose(); DataCodeContour = tranDataCodeContour; if (!train) { Display(2); Display(3); } } else { if (UseBrighten) { HImage brightenImg = zoomImg.ScaleImage(UseBrightenValue, 0.0); DataCodeContour = CodeReaderHand.FindDataCode2d(brightenImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings); if (DecodedDataStrings.Length > 0) { DataCodeString = DecodedDataStrings[0].S; HHomMat2D mat = new HHomMat2D(); HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0); double row, col; region.AreaCenter(out row, out col); HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0); HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour); DataCodeContour.Dispose(); DataCodeContour = tranDataCodeContour; if (!train) { Display(2); Display(3); } return(true); } } DataCodeString = string.Empty; if (!train) { Display(4); } return(false); } return(true); }
/// <summary> /// Gets the model supplied by a loaded shapebased model file (.shm) /// </summary> public HXLD getLoadedModelContour() { HTuple row1, col1, row2, col2, row, col; HHomMat2D homMat2D = new HHomMat2D(); try { tResult.mContour.SmallestRectangle1Xld(out row1, out col1, out row2, out col2); row2 = row1.TupleMin(); col2 = col1.TupleMin(); row = row2.TupleFloor()-5; col = col2.TupleFloor()-5; homMat2D.HomMat2dIdentity(); homMat2D = homMat2D.HomMat2dTranslate(-row,-col); return homMat2D.AffineTransContourXld(tResult.mContour); } catch(HOperatorException e) { exceptionText = e.Message; NotifyIconObserver(MatchingAssistant.ERR_READ_SHAPEMODEL); return null; } }