Requirements to use OpenCV 2.3 with Scorpion 9.0
and 9.1
There are some additional requirements for OpenCV 2.3 to work with Scorpion
- Install OpenCV 2.3
- Samples require that OpenCV 2.3 is installed(extracted) into C:\opencv
folder
- Add the OpenCV "bin" folder to
the system environment path variable
It is required that Numpy 1.6.1
version is installed
To verify that you have installed OpenCV 2.3 properly you can run following script in Scorpion:
import site
site.addsitedir("C:\\opencv\\build\\python\\2.6")
import cv2
If you see any errors in Scorpion console output then it means that OpenCV module was not loaded successfully.
You need to verify your OpenCV installation. Make sure you do have Python 2.6 bindings for OpenCV 2.3. Verify
that path is pointing to a valid location.
arrToNumpy - Scorpion helper class
All of the functions for OpenCV 2.3 accepts only numpy arrays for the image parameters. "arrToNumpy" module helps to convert Scorpion
image matrix to numpy and vice versa.
To convert image to numpy array use function:
- numpyArray = arrToNumpy(imageMatrix)
reverse:
- imageMatrix = numpyToArr(numpyArray)
Sample profiles with OpenCV 2.3
Example 1 - OpenCV 2.3
: ScriptTool AdaptiveThreshold
import cv2
from arrToNumpy import arrToNumpy, numpyToArr
try:
#Example of a useful transform - adaptive threshold
# cv2.adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C[, dst]) -> dst
#apply to OpenCV image, can be done in place
data = arrToNumpy(GetImageMatr("Image"))
cv2.adaptiveThreshold(data, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 20, data)
#can apply morphology if desired,
# - again safe to do in place or could make second image
cv2.dilate(data, None, data, iterations=1)
SetImageMatr("Output", numpyToArr(data))
except Exception, msg:
print msg
Example 2 - OpenCV 2.3
: Adding Canny Filter
#the script reside inside a Scorpion ScriptTool
import cv2
from arrToNumpy import arrToNumpy, numpyToArr
try:
data = arrToNumpy(GetImageMatr("Image"))
cv2.Canny(data, 0, 255, data)
SetImageMatr("Output", numpyToArr(data))
except Exception, msg:
print msg
Example 3
- OpenCV 2 :
Test Installation and Setup
def testOpenCV():
import site
site.addsitedir("C:\\opencv\\build\\python\\2.6")
try: # verifies that cv2 is available
import cv2
print 'OpenCV23 installed OK'
except:
print 'OpenCV23 not installed'
|