TopCodes

javadoc

TopCodes service allows to recognize a special code. You can print these codes using the attached topcodes.pdf.

The service gives back the following information :

  • Number of the code recognized
  • Coordinates of the center of the code (x,y)
  • Diameter of the code (which can be used to find distance)
  • Angular rotation of the code

‚ÄčTHERE ARE 99 DIFFERENT CODES.

CAMERA SHOULD BE AS PERPENDICULAR AS POSSIBLE TO THE CODE, IN ORDER TO WORK WELL.

References :


#file : /service/TopCodes.py edit raw
from org.myrobotlab.opencv import OpenCVData
from org.myrobotlab.service import OpenCV

opencv = Runtime.create("opencv","OpenCV")
topcodes = Runtime.createAndStart("topcodes","TopCodes")
opencv.startService()
opencv.addFilter("PyramidDown1", "PyramidDown")

def input(data) :
 simage = opencv.getDisplay()
 codes = topcodes.scan(simage.getImage())
 limit = codes.size()
 for x in range(limit) :
    code = codes.get(x)
    print 'code number' , x ,'=', code.getCode()
# other information could be provided
    #print 'diameter' , x , 'is' , code.getDiameter()
    #print 'x of center' , x , 'is' , code.getCenterX()
    #print 'y of center' , x , 'is' , code.getCenterY()
    #print 'rotation' , x , 'is' , code.getOrientation() , 'radians'
opencv.addListener("publishOpenCVData", python.name, "input");
opencv.setCameraIndex(0)
opencv.capture()

Examples:


#file : service/TopCodes.py edit raw
from org.myrobotlab.opencv import OpenCVData
from org.myrobotlab.service import OpenCV

opencv = Runtime.create("opencv","OpenCV")
topcodes = Runtime.createAndStart("topcodes","TopCodes")
opencv.startService()
opencv.addFilter("PyramidDown1", "PyramidDown")

def input(data) :
 simage = opencv.getDisplay()
 codes = topcodes.scan(simage.getImage())
 limit = codes.size()
 for x in range(limit) :
    code = codes.get(x)
    print 'code number' , x ,'=', code.getCode()
# other information could be provided
    #print 'diameter' , x , 'is' , code.getDiameter()
    #print 'x of center' , x , 'is' , code.getCenterX()
    #print 'y of center' , x , 'is' , code.getCenterY()
    #print 'rotation' , x , 'is' , code.getOrientation() , 'radians'
opencv.addListener("publishOpenCVData", python.name, "input");
opencv.setCameraIndex(0)
opencv.capture()