CImExtract:Extract CImExtract:new

CImExtract:GetSource


The GetSource method returns a table of properties for a source in an image extracted using the CImExtract class. The properties are returned as a table of type Source Properties table.

Syntax

tblSource = CImExtract:GetSource( nSourceIndex, bUseIndex )

tblSource = CImExtract:GetSource( nSourceIndex )

bullet.gif    nSourceIndex is the index of the source from the list of extracted sources, between 1 and CImExtract:Count.

bullet.gif    bUseIndex is used to select whether the returned table is organized by property name or numeric index. If omitted or set to false, the source properties table is referenced by property name rather than its table index.

bullet.gif    tblSource is a table containing the extracted properties of the source.

bullet.gif    On failure, nil is returned

Example

Suppose an image window exists on the Mira screen. The script below performs source extraction on an image from this window and then repeatedly uses GetSource to fetch the (x,y) coordinates from each source's Source Properties table.

Before calling Extract, the default configuration is updated using a ImExtractParams table. Note that your ImExtractParams table does not need to be named Params as shown here.

V = attachlist_imageview()

-- attach an image window

Assert( V, "No image window")

-- leave script if no image window

 

 

I = V:GetImage()

-- get the top-most or only image

Assert( I, "No image selected")

-- leave script if no image

 

 

E = new_imextract()

-- create a CImExtract object

Params =

-- setup an ImExtractParams table

{

-- use a comma after each "name=value" pair

  bProcFilter = true,

 

  bFilterUseSepMin = true,

 

  nFilterSepMin = 10,

 

  bFilterUseAreaMax = true,

 

  nFilterAreaMax= 100,

 

  nBgMethod = 1,

 

  nDetectTreshold = 45,

-- threshold value = 45

  nDetectTest = 0,

-- detect pixels >= threshold

}

 

E:SetParams(Params)

-- set new configuration properties

 

 

bOK = E:Extract( I )

-- extract sources from image I

if not bOK then Exit("Extract failed.\n") end

 

 

 

-- report the number of sources extracted:

 

nCount = E:Count()

 

if nCount < 1 then Exit("No sources.\n") end

 

Printf("Number of sources = %d\n", nCount)

 

 

 

-- list the x,y coordinates for all sources:

 

for i = 1,nCount do

 

  local Stbl = E:GetSource(i)

-- fetch the properties of source i

  Printf("[%d]:%lg,%lg\n", i,Stbl.nCenterX,Stbl.nCenterY)

 

end

 

Related Topics

CImExtract class, Count, Extract, Source Properties Table


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