IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

Modules demonstrating how to mix PyIPSDK library features with OpenCV features. More...

Modules demonstrating how to mix PyIPSDK library features with OpenCV features.

OpenCV images, see OpenCV official web site, can easily be manipulated has PyIPSDK images and vice versa without memory penalty cost using numpy array. There is no reallocation exchanging data from OpenCV images to PyIPSDK images and vice versa.

Prerequisite

OpenCV library should be installed with used Python distribution (see OpenCV official web site for more informations).

Usage

The following script illustrate how to handle usage of OpenCV library with PyIPSDK library.

We start by importing all necessary libraries:

import os
import PyIPSDK
# specific opencv library import
import cv2
# specific numpy library import
import numpy as np

We can now mix PyIPSDK and OpenCV features :

# opening of a 2d image with size 483x348 and with unsigned char data type
img2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs_483x348_UInt8.tif"))
# threshold this image using OpenCV function
threshold1,cvBinImg2d1 = cv2.threshold(img2d1.array, 127, 255, cv2.THRESH_BINARY)
print("Threshold1 = " + str(threshold1))
# once done we can retrieve a PyIPSDK image
# note that cvBinImg2d1 and binImg2d1 share memory
binImg2d1 = PyIPSDK.fromArray(cvBinImg2d1)
# and finaly save resulting image
outputPath1 = os.path.join(tmpPath, "PyIPSDK_mix_with_OpenCV_1.tif")
PyIPSDK.saveTiffImageFile(outputPath1, binImg2d1)
print("Image saved to " + outputPath1)
Note
For more informations on mixing PyIPSDK images with numpy array see Mix PyIPSDK with Numpy library.