Example 1: Use barcode reader functionality:
The sample is embedded in the following Scorpion Profile:
1. Place this code into Central Start:
# Create bar code reader instance.
from BarcodeReader import GetBarcodeReader
global reader
reader = GetBarcodeReader()
from BarcodeReader import GetBarcodeReader
2. Create PythonScript tool in toolbox and paste this code:
# This gets image number, which is set to current tool.
reader.general['ImageIndex'] = GetTool(GetCurSource()).imageNo
# Setup visualisation options.
reader.visualisation['Frame'].enabled = True
reader.visualisation['Frame'].penWidth = 3
reader.visualisation['Code'].enabled = True
reader.visualisation['Code'].fontSize = 12
reader.visualisation['Code'].backColor = 'Black'
reader.visualisation['Code'].textStyle = 1
# Setup barcode type for searching.
reader.option['ReadCode25'].enabled = False
reader.option['ReadCode39'].enabled = False
#reader.option['ReadCode93'].enabled = False
reader.option['ReadCode128'].enabled = False
reader.option['ReadShortCode128'].enabled = False
reader.option['ReadCodabar'].enabled = False
reader.option['ReadDatabar'].enabled = FalseCentral Start
reader.option['ReadDataMatrix'].enabled = True
reader.option['ReadEAN8'].enabled = False
reader.option['ReadEAN13'].enabled = False
reader.option['ReadPatchCodes'].enabled = False
reader.option['ReadMicroPDF417'].enabled = False
reader.option['ReadPDF417'].enabled = False
reader.option['ReadUPCA'].enabled = False
reader.option['ReadUPCE'].enabled = False
# Setup other options.
reader.option['MultipleRead'].enabled = False
reader.option['QuietZoneSize'].value = 0
reader.option['SkewTolerance'].value = 3
reader.option['SkewLineJump'].value = 1
reader.option['LineJump'].value = 1
reader.option['ScanDirection'].value = 15
reader.option['PrefOccurrence'].value = 1
reader.option['AllowDuplicateValues'].value = 0
# Execute reader to perform barcode search.
try:
reader.Execute()
except Exception, msg:
pass # No barcode found.
# Print result
print 'Barcodes Count: ', reader.result['Count']
if reader.result['Count'] > 0:
print 'Barcode: ', reader.result['Code[1]']
Example 2: Using BaseTool to create a barcodereader
component
- Requires Scorpion 8.4.0.482 or higher
The sample is embedded in the following Scorpion Profile:
1. Create BaseTool in Toolbox.
2. Create external data in BaseTool.
3. Create data input page and configure it.
4. Place this code into BaseTool init script:
def init(self):
# use self.name to get this tool instance
# tool=GetTool(self.name)
# Python start script goes here
# Create bar code reader instance
from BarcodeReader import GetBarcodeReader
self.reader = GetBarcodeReader()
5. Place this code into BaseTool execute script:
def execute(self,image):
# use self.name to get this tool instance
# tool=GetTool(self.name)
# Return 1 for pass, 0 for fail
t=GetTool(self.name)
reader = self.reader
# Setup visualisation options.
reader.visualisation['Frame'].enabled = t.getIntValue('Vis_enabled')
reader.visualisation['Frame'].penWidth = t.getIntValue('Vis_penWidth')
reader.visualisation['Code'].enabled = t.getIntValue('Vis_code')
reader.visualisation['Code'].fontSize = t.getIntValue('Vis_fontSize')
reader.visualisation['Code'].backColor = 'Black'
reader.visualisation['Code'].textStyle = 1
# Setup barcode type for searching.
reader.option['ReadCode25'].enabled = False
reader.option['ReadCode39'].enabled = False
#reader.option['ReadCode93'].enabled = False requires .net2 and v2 of library
reader.option['ReadCode128'].enabled = False
reader.option['ReadShortCode128'].enabled = False
reader.option['ReadCodabar'].enabled = False
#reader.option['ReadDatabar'].enabled = False requires and v2 of library
reader.option['ReadDataMatrix'].enabled = False
reader.option['ReadEAN8'].enabled = t.getBoolValue('Opt_EAN8')
reader.option['ReadEAN13'].enabled = t.getBoolValue('Opt_EAN13')
reader.option['ReadPatchCodes'].enabled = False
reader.option['ReadMicroPDF417'].enabled = False
reader.option['ReadPDF417'].enabled = False
reader.option['ReadUPCA'].enabled = False
reader.option['ReadUPCE'].enabled = False
# This gets image number, which is set to current tool.
reader.general['ImageIndex'] = t.imageNo
# Setup other options.
reader.option['MultipleRead'].enabled = False
reader.option['QuietZoneSize'].value = 0
reader.option['SkewTolerance'].value = t.getFloatValue('Opt_skewTolerance')
reader.option['SkewLineJump'].value = t.getFloatValue('Opt_skewLineJump')
reader.option['LineJump'].value = t.getFloatValue('Opt_lineJump')
reader.option['ScanDirection'].value = t.getFloatValue('Opt_scanDirection')
reader.option['PrefOccurrence'].value = 1
reader.option['AllowDuplicateValues'].value = 0
# Execute reader to perform barcode search.
try:
reader.Execute(image)
except Exception, msg:
t.setStringValue('StatusText','%s %s'%(Exception, msg))
print Exception, msg # No barcode found.
# Set Results
t.setBoolValue('Pass', reader.result['Count'] > 0)
t.setIntValue('Count', reader.result['Count'])
if reader.result['Count'] > 0:
t.setStringValue('BarCode' , reader.result['Code[1]'])
else:
t.setStringValue('BarCode', '-')
return reader.result['Count'] > 0
NOTE: If BaseTool uses Reference, ROI left upper corner coordinate must be (0, 0).
Otherwise BarCode visualization can be incorrect.
|