Using ScorpionOpenCV

ScorpionOpenCV key features

  • multithreaded
  • uses on Scorpion Arrlib structures

In Scorpion 12 - the Scorpion Tool Component - STC-0135-ImageFilter2 is an indispensable package based on OpenCV, ScorpionOpenCV and Numpy.

Introduction

ScorpionOpenCV is a Scorpion encapsulation of OpenCV 1.1, primarily filter functions. These filters are a valuable part of OpenCV that is a part of the Scorpion Vision Software framework.

ScorpionOpenCV is multithreaded while standard OpenCV 1.1 single threaded. Working with large images the performance gain is significant.

The following methods are implemented:

  • imageFilter
  • median
  • smooth
  • canny
  • imageMerge

ScorpionOpenCV works on Scorpion Arrlib’s data structures, there is no need for transferring Scorpion structures to Numpy as for standard OpenCV. The python module ScorpionOpenCV.py is distributed with the Scorpion Vision installer and is located in the Python sub-folder.

Image filters

Scorpion Vision supports a image filter command strings to perform image filtering to an image, either pre-filter or post-filter. These filters was first invented in the STC-0011-ImageFilter. This is STC or Scorpion Tool Components.

The filter commands strings make it easy to create customs filter where parameter settings and filter sequence are defined by command string.

c40,200,3m3  # canny followed by a median smooth filter

These filters are supported by various tools like TemplateFinder3 and ColorSegmentor.

The filter format is given by a command string where filter type is given by a single letter followed by one or more parameters.

<cmd><p1><,p2><,pn>

Multiple filters can be combined in any sequence. Some filters are optimized by threading, this applies mainly for larger images (>VGA) and may be tuned due to image size, filter aperture and no of cpu’s.

Supported filters:

The following subset of filters are supported by ScorpionOpenCV imageFilter command.

Filter Parameters  
Canny c<threshold1=40><,threshold2=200><,aperturesize=3><,threads=4>
Dilate d<iterations=1><,threads=n> # example - d2
Erode e<iterations=1><,threads=n> # example - e4
Close C<iterations=4><,threads=n>,# example - C2
Open O<iterations=4><,threads=n> # example - O4
Laplace l<aperture=3><,threads=n>, # example - l3
AdaptiveThreshold t<maxvalue=125><,adaptive_method=MEAN(0)><,thresh_type=BIN(0)><,block_size=3><,param1=5>
Gaussian g<size1=3><,size2=0><,sigma1=0><,sigma2><,threads=n>
Blur b<size1=3><,threads=n>
Median m<size1=3><,threads=n>
Sobel s<xorder=1><,yorder=1><,aperture_size=3><,threads=n>
Threshold H<threshold=100><,maxvalue=255><,threshold_type=0><,threads=n>
Normalize N<aperture=21><,scale=255><,percentile=50><,threads=n> percentile is currently fixed at 50 but has to be specified if threads is to be specified
Threads ‘|’<threads> no of threads used for following commands, ‘|’ - PIPE chacter. All functions uses by default 4 threads

ImageFilter examples

Example 1: Canny and erode, using 8 threads for erode

c40|8e2

Example 2: Image blur

b5

Example 3: Adaptive Threshold

t125,0,0,5

Example 4: Normalize image

N101,200,50

Code examples

Example 1 - Using imageFilter inside a BaseTool

The example is from the Scorpion Vision Toolbox inside the BaseTool’s execute method.

It is required that the tool has implemented a data input configuration

  • Filter # contains image filter string
  • OutputImage # contains image filter destination image
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
        import ScorpionOpenCV
        tool=GetBaseTool(self.name)     #get this tool instance
        dst=image                   #allocate destination of same type and size - critical
        ScorpionOpenCV.imageFilter(tool.arrState,image,dst,tool.getString('Filter'))
        SetImageMatr(tool.getString('OutputImage'),dst)
        return 1