Up | Examples | Shortcuts | Release Notes

 

  

 
Examples
Example 1: ObjectPosition3D Python Wrapper Class
def CreateObjectPosition3D(name):

  class ObjectPosition3D:
    def __init__(self,name):
      self.name = name


    def X(self):
      return GetFloatValue(self.name+'.Position_x')

    def Y(self):
      return GetFloatValue(self.name+'.Position_y')

    def Z(self):
      return GetFloatValue(self.name+'.Position_z')

    def GetPosition(self):
      deviation = self.GetDeviation()
      status = self.GetStatus()
      return self.X(),self.Y(),self.Z(),deviation,status

    def SetPosition(self,name,x,y,z):
      SetFloatValue(name+'_x',x)
      SetFloatValue(name+'_y',y)
      SetFloatValue(name+'_z',z)

    def GetCameraUsed(self):
      return GetFloatValue(self.name+'.CamerasUsed')

    def GetDeviation(self):
      return GetFloatValue(self.name+'.Deviation')

    def SetDeviation(self,deviation):
      SetFloatValue(self.name+'.Deviation',deviation)

    def SetStatus(self,status):
      SetIntValue(self.name+'.Status',status)

    def GetStatus(self):
      return GetIntValue(self.name+'.Status')

    def GetMatch(self):
      m2 = GetValue(self.name+'.Match2')
      m3 = GetValue(self.name+'.Match2')
      m4 = GetValue(self.name+'.Match2')

      count = 0
      match = 0
      if m2 > 0:
        count = count +1
        match = match + m2
      if m3 > 0:
        count = count +1
        match = match + m3
      if m4 > 0:
        count = count +1
        match = match + m4

      if count > 0:
        return match / count
      else:
        return 0
        
    def Quality(self):

      return self.GetCameraUsed()*self.GetCameraUsed()*self.GetCameraUsed() * 1.0/ max(0.2,self.GetDeviation())


  return ObjectPosition3D(name)
Example 2: Use BubbleSort to sort a list of ObjectPosition3D objects
obpList = []
obpList.append(CreateObjectPosition3D('obp - 1'))
obpList.append(CreateObjectPosition3D('obp - 2'))
obpList.append(CreateObjectPosition3D('obp - 3'))
obpList.append(CreateObjectPosition3D('obp - 4'))

for obp in obpList:
  print obp.name,' - ',obp.Quality(),obp.GetMatch(),obp.GetDeviation(),obp.GetCameraUsed(),obp.Z()

# bubblesort
for passesLeft in range(len(obpList)-1, 0, -1):
  for index in range(passesLeft):
    if obpList[index].Quality() < obpList[index + 1].Quality():
      obpList[index], obpList[index + 1] = obpList[index + 1], obpList[index]

for obp in obpList:
  print obp.name,' - ',obp.Quality(),obp.Z()

z = (obpList[0].Z() + obpList[1].Z()) / 2

print ' z = ', z
 
 

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