CMeasureRegions:Add


The Add mehod adds a region to the collection and draws it on the image. The Measure Regions toolbar is opened on the target image window, if not already open, to facilitate working with the regions (mark, move, and delete regions, etc.). The collection is actually owned by the image window. See the Mira Pro x64 User's Guide for details about the MeasureRegions feature.

Syntax

C = CMeasureRegions:Add( Image, tblData )

bullet.gif    Adds a region with properties defined by RegionParams and coordinates passed in a 1-dimensional array.

C = CMeasureRegions:Add( Image, tblDataX, tblDataY )

bullet.gif    Adds a region with properties defined by RegionParams and coordinates passed in two 1-dimensional arrays with values that are numbers.

bullet.gif    tblData is a table of x and y as described in Remarks, below.

bullet.gif    tblDataX and tblDataY contain separate x and y coordinates.

bullet.gif    Returns true on success, and false on failure.

Remarks

This method supports two strategies for defining regions based on storing coordinates in a 1-dimensional arrays. You can use either one that is convenient:

bullet.gif    Use one array containing the points [1], [2], [3], etc., as in { x[1], y[1], x[2], y[2], x[3], y[3], ... }.

bullet.gif    Use two arrays, one for x coordinates and the other for y coordinates. The points [1], [2], [3], etc., are then stored as { x[1], x[2], x[3], ... } and { y[1], y[2], y[3], ... }.

Example

The following script creates a new CMeasureRegions object, attaches an image window and an image, then adds two regions to the image using the two strategies described above, under Remarks.

R = new_measureregions()

-- create a new CMeasureRegions

 

 

Params =

 -- RegionParams properties to change

{

  

  bSetColor = true,

 

  sColor = "0,255,0",

 

  bSetLineThk = true,

 

  nLineThk = 1.5,

 

  bSetCentroid = true,

 

  bCentroid = true,

 

}

  

R:SetParams(Params)

  

 

 

V = attachlist_imageview()

-- attach an image window

Assert( V, "No image window")

 -- exit if no image window

-- grab an image from the window, V

 

if V:Count() > 1 then

  

  I = CImage:AttachFromList( V )

-- pick an image from the CImageView V

  Assert( I, "No Images available")

 -- exit if no image

else

 

  I = V:GetImage()

-- pick the only image in the window

end

 

 

 

-- create regions centered on the image:

 

-- first, get the image center coordinates

 

yc = I:Cols() / 2

 

xc = I:Rows() / 2

 

 

 

-- create a region using one x,y table

 

tblData = {}

-- create a table for x and y coordinates

tblData[1] = xc - 200

 

tblData[2] = yc + 50

 

tblData[3] = xc + 150

 

tblData[4] = yc + 220

 

tblData[5] = xc + 280

 

tblData[6] = yc - 100

 

tblData[7] = xc - 100

 

tblData[8] = yc - 80

 

R:Add( I, tblData )

-- draw the marker

 

 

-- create a region using separate x, y tables

 

tblDataX = {}

-- creaste a table for x coordinates

tblDataX[1] = xc - 50

 

tblDataX[2] = xc + 250

 

tblDataX[3] = xc - 150

 

tblDataX[4] = xc + 120

 

tblDataY = {}

-- create a table for y coordinates

tblDataY[1] = yc + 180

 

tblDataY[2] = yc + 60

 

tblDataY[3] = yc - 100

 

tblDataY[4] = yc + 200

 

R:Add( I, tblDataX, tblDataY )

-- draw the marker

Related Topics

CMeasureRegions class, new, delete, RegionParams Table


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.