Up | CameraError | ImageComplete | LoadTools | SaveTools | ToolApply | ToolVariantChange | DataInputApply | Query Events | UpdateResultPanel | UpdateIndicatorPanel | ContextChange | Mouse Events | Timer | LogMsg

 

  

 
ImageComplete
The ImageComplete event is called when an image is aquired.

The event can be used to validate an image before accepting it - this can be used to implement soft triggers thus removing the need of a hardware trigger. Discarded images will not enter into the image history list.

Note : There is no protection against entering a infinite loop if the script always discards the image.

Example 1: Software Trigger - Wait until Line is in Position

In the example each image is preprocessed by executing a tool to find a center position within a range. If this condition is not true the script discards the image and Scorpion will capture a new image. A global counter retry is used to protect against entering a infinite loop in case of bad images.

def Handle_System_ImageComplete(Image):
  #
  # Image = VT_BSTR
  #
  # Return 1 if handled by script
  # Return 0 if default handling
  #
  global retry                   #global initialized retry counter
  img = GetImageMatr(Image)      #get the image
  line = GetTool('Line')
  line.execute(img)
  y = line.getValue('Center[1]_y')
  if 200 < y < 300:              #check if center of line is in range <200..300>
    print 'y - ',y
    retry=0                      #reset global retry counter
    return 0                     #image ok
  else:
    print 'rejected - y -',y
    retry=retry+1                #increment retry counter
    if retry<10 :
      return 1                   #discard image. Capture new image
    else:
      retry=0
      return 0                   #retry counter overrun, give up - pass image to scorpion

Example 2: Dynamic Shutter using ImageComplete and an IntensityTool

def Handle_System_ImageComplete(Image):
  #
  # Image = VT_BSTR
  #
  # Return 1 if handled by script
  # Return 0 if default handling
  #
if Image = 'Image_1' :
  img=GetImageMatr(Image)
  try:
    lm=GetTool('LightMeter')
    lm.execute(img)
    percentile=GetIntValue('GlobalInput.Percentile')
    intensity =lm.getFloatValue('Percentile['+str(percentile)+']')
    print 'p'+str(percentile)+'=',p
    cam=GetCamera('0')
    shutter=cam.getProperty('shutter')
    shutterstep=GetIntValue('GlobalInput.ShutterStep')
    print 'current shutter =',shutter
    maxIntensityLevel=GetFloatValue('GlobalInput.MaximumIntensity')
    minIntensityLevel=GetFloatValue('GlobalInput.MinimumIntensity')
    if intensity > maxIntensityLevel and shutter > GetIntValue('GlobalInput.MinimumShutter'):
      print 'Reduce shutter time'
      cam.setProperty('shutter',shutter - shutterstep)
      ExecuteCmd('GrabImage','')  # capture a new image
      return 1
    elif intensity < minIntensityLevel and shutter < GetIntValue('GlobalInput.MaximumShutter'):
      print ' Increase shutter time'
      cam.setProperty('shutter',shutter + shutterstep)
      ExecuteCmd('GrabImage','') # capture a new image 
      return 1 # capture new image
    else:
      print 'Shutter time OK'
      return 0 # capture new image

  except:
    print 'ImageComplete - ',Image, ' - Cannot adjust shutter time'
    return 0 # image is handled by scorpion.
else:
  return 0 # image is handled by scorpion. 

Action - GrabImage # trigger new image

   # An action must be defined to let Scorpion terminate ImageComplete before issuing a Grab command

Delay;value=200
Grab

 

 
 

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