Programmatically Creating measured lines from bounding box measurements from count/size
The app IDs given image structures and returns dimensional info using Count/Size and bounding box metrics. The app displays the detected region and returns either the Box Height or Width depending on the measured structure. This works well. However, I would prefer to draw a single line that would represent the measured length as measured by the bounding box. I thought I could use the Count/Size Count Option, Longest Line feature. This worked but it is not constrained to the X or Y axis of the Bounding Box. I see the value of the current behavior but it would be nice to offer an X or Y constraint option, the line drawn would track the width or height axis of the box so to speak.
Given this, in order to programmatically draw the line I thought that I could acquire the bounding box upper left and lower right X/Y coordinates and draw an annotation line using this data relative to the bounding box width or height result. I found the GetBoundingBox Method that will return the point data needed to draw an anno line but this seems tied to manual Measurements as the documentation indicates and not available from a Count/Size measurement. How do I grab the bound box coordinates, is there a better method for annotating the measured dimension constrained to the X/Y of the box?
For clarity, I am using Premier 9.0.3.
Best Answer
-
Hi Rod,Here is the macro that will draw bounding box with width/height and angle of the objects.
Public Sub DrawWidthHeightBoxes() If ThisApplication.ActiveImage Is Nothing Then OpenDemoImage Dim image1 As McImage=ThisApplication.ActiveImage Dim md As McMMData=image1.MeasurementsData If md.Count=0 Then Exit Sub Dim pixelSize As Double=1 If image1.SpatialCalibration IsNot Nothing Then pixelSize=image1.SpatialCalibration.PixelSizeX End If Dim ovl As MediaCy.IQL.Display.Overlays.McGraphOverlay=image1.AnnotationOverlay For Each sf As McMMSubFeature In md.SubFeatures If sf.FeatureType And McMMSubFeature.mcmmsfTypes.mcmmsfRegion = 0 Then Continue For 'get size in pixels Dim width As Double =sf.Value(eMeasures.RgnWidth)/pixelSize Dim height As Double =sf.Value(eMeasures.RgnLength)/pixelSize Dim angle As Double=sf.Value(emeasures.RgnDirection) Dim center As System.Drawing.PointF center.X=sf.Value(eMeasures.RgnCentroidX)/pixelSize center.Y=sf.Value(eMeasures.RgnCentroidY)/pixelSize Dim box As MediaCy.IQL.Display.Overlays.McGraphObjRect= ovl.Add("McGraphObjRect") box.SetHandle(1,center.x-width/2,center.y-height/2) box.SetHandle(5,center.x+width/2,center.y+height/2) box.AngleOfRotation=angle+90 box.NotifyCreationComplete Next End Sub
0
Answers
I've also attached the complete project.
Yuri
Yuri:
I added the Box sub to the original code and called. Works fine with your sample1. For testing purposes I added the draw box sub to my app and called after I have counted the objects. However, when I attempt to load my app I receive" type identifier is invalid" and is referencing McMMSubFeature. It thought I had not included all the references required. I compared the working app with mine and all was the same. I am overlooking something simple I suspect. Any thoughts?