Up | Logic - 1 | Blob1 - 61 | Intensity - 75 | PythonScript - 3 | BaseTool - 163 | SimpleMath - 21 | DummyTool - 20 | Goto - 59 | ColorMatcher - 54 | ImageCombiner - 74 | ImageFilter - 77 | ImageConverter - 55 | BarCodeReader - 56 | EasyBarCode - 72 | EasyMatrixCode - 73 | CommitImage - 159 | Separator - 102

Release Notes | Commands
 

  

 
BaseTool - 163

Tool Name:

BaseTool
Tool Index: 163 
Tool Category: Basic Tools
   

Description:

Specialized tool for Scorpion Tool Component, configurable for SDK license users only.

User Interface:

TBD

Basic Processing when the tool is executed:

TBD

BaseTool python class:

access method : GetBaseTool(name)

The derived python tool class supporting coordinate and reference transform methods moving between resampled input image and the origin image, and access to user added DataInput pages. In addition to the attributes and methods of the object returned by GetTool(name) the BaseTool class has following attributes and methods.

In the tool's python methods, the "self" object is a python BaseTool instance and the attributes and methods in below tables may be accessed directly.

Attribute Access Type Description
wholeImage R bool returns state of whole image flag
center R point ROI center in object coordinates
size R point ROI size in object coordinates
angle R float  ROI angle, 0 if deactivated

Method Returns Description
imgToObj(pnt) point transforms execute method's incoming image pixel coordinates to basetools object coordinates, single point, tuple/list of point tuples or arrlib object
imgToPix(pnt) point transforms execute method's incoming image pixel coordinates to origin image pixel coordinates, single point, tuple/list of point tuples or arrlib object
objToImg(pnt) point transforms basetools object coordinates to execute method's incoming image pixel coordinates, single point, tuple/list of point tuples or arrlib object
pixToImg(pnt) point transforms origin image pixel coordinates to execute method's incoming image pixel coordinates, single point, tuple/list of point tuples or arrlib object
getDataInput(name) DataInput returns internal DataInput object. Note! available only when configuration dialog is shown, else None is returned
getDataInputByChild(ctrl) DataInput returns internal DataInput object owning the ctrl, typically used in DataInput callback scripts
dataInputApply(page="") int apply all or single DataInput page. Returns pages applied
dataInputRefresh(page="") int refresh all or single DataInput page. Returns pages refreshed


Inputs to the Tool:
Inputs: User configurable
Uses Reference: User configurable, 2D or 3D
Uses Image: User configurable, 2D or 3D
   

Results



Outputs from the Tool:
Outputs:
1 MeanPixRatio Numeric mean pixel ratio when configured ROI
2 PixRatio_x Numeric ROI pixel ratio, x direction
3 PixRatio_y Numeric ROI pixel ratio, y direction
4 AnalyzeTime: Numeric This is a standard output from all Scorpion tools and indicates the time taken by the last processing operation of this tool
Visualizations: ROI
Reference outputs: Incoming or user defined
   

Templates:
Supports Templates: Yes
   

Example 1, Coordinate transforms
def execute(self,image):
  # use self.name to get this tool instance
  # tool=GetTool(self.name)
  # image parameter is a python image matrix due to ROI
  # Return 1 for pass, 0 for fail
  
  def PrintPoint(txt,p):
    '''
    print formatted point
    '''
    print txt,'(%.1f, %.1f)'%(p[0],p[1])
  def DrawPoint(ref,p,col,idx):
    '''
    draws a marker and coordinate text in ref's object coords
    '''
    DrawMarker(ref,p[0],p[1],col)
    DrawText(ref,p[0],p[1],'%d:(%d,%d)'%(idx,p[0],p[1]),'yellow',8)
  t=BaseTool(self.name)            #get the BaseTool wrapper instance
  print t.wholeImage               #basetool internal wholeImage flag
  print t.center                   #basetool internal ROI center, object coords
  print t.size                     #basetool internal ROI size, object coords
  rows,cols=image.dim()            #incoming image size
  
  pc=t.imgToPix((rows/2,cols/2))   #origin image center
  pmn=t.imgToPix((0,0))            #origin image "upper left"
  pmx=t.imgToPix((rows,cols))      #origin image "bottom right"
  
  rc=t.pixToImg(pc)                #incoming image center
  rmn=t.pixToImg(pmn)              #incoming image "upper left"
  rmx=t.pixToImg(pmx)              #incoming image "bottom right"
  
  print '-'*40
  PrintPoint('PIX size  ',((abs(pmx[0]-pmn[0]),abs(pmx[1]-pmn[1]))))
  PrintPoint('PIX center',pc)
  PrintPoint('PIX min   ',pmn)
  PrintPoint('PIX max   ',pmx)
  PrintPoint('IMG center',rc)
  PrintPoint('IMG size  ',((abs(rmx[0]-rmn[0]),abs(rmx[1]-rmn[1]))))
  PrintPoint('IMG min   ',rmn)
  PrintPoint('IMG max   ',rmx)
  if 0:
    ref='Pixels' #none existing tool - using pixel coords
    DrawPoint(ref,t.imgToPix((0,0)),'red',1)
    DrawPoint(ref,t.imgToPix((rows,0)),'blue',2)
    DrawPoint(ref,t.imgToPix((rows,cols)),'lime',3)
    DrawPoint(ref,t.imgToPix((0,cols)),'yellow',4)
    DrawPoint(ref,pc,'white',0)
  
  if 1:
    ref=''  #no reference - using current tool's object coords
    DrawPoint(ref,t.imgToObj((0,0)),'red',1)
    DrawPoint(ref,t.imgToObj((rows,0)),'blue',2)
    DrawPoint(ref,t.imgToObj((rows,cols)),'lime',3)
    DrawPoint(ref,t.imgToObj((0,cols)),'yellow',4)
    DrawPoint(ref,t.imgToObj((rows/2,cols/2)),'white',0)
  return 1
Example 2, Accessing internal DataInput page from ScriptButton on DataInput page
def DataInputScriptButtonClick(Sender,Args):
  #insert the button handler code

  t=GetBaseTool(Args.name)       #Args the a generic tool instance, get the BaseTool instance
  di=t.getDataInput('Config')    #get the BaseTool's 'Config' DataInput object
  if di:                         #check if available, ie. config dialog is open
    di.update()                  #refresh content
Example 3, Generic button click handling in DataInput buttons
def ButtonClicked(Sender,Args):
  #Sender is the clicked button
  #Insert the control on clicked code
  di=Args.getDataInputByChild(Sender)
  param=di.getParameterByChild(Sender)
  #print di,param.group,param.name,Sender.caption
  if param.name.find('Tower')>-1:
    if Sender.caption.find('-')>0:
      print 'decreasing %s for %s'%(param.group,param.name)
     elif Sender.caption.find('+')>0:
      print 'increasing %s for %s'%(param.group,param.name)
 

Scorpion Vision Version XII : Build 650 - Date: 20170614
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.