Top Banner
Video Savant Python function library Python is a popular scripting language with easy to use syntax. The user has the capability to run Python scripts to help customize the control of Video Savant. A good introduction to the general syntax of Python can be found at the following web page: http://www.python.org/doc/current/ . Python scripts are setup in the DVR Control Panel of Video Savant. The screenshot below shows a Recording script displayed in Python window on the bottom right of the DVR Control Panel. The output of that script can be displayed by selecting Script output instead of Record script. The Record Script control box allows the user to create a Python script or to open an existing one. For more detailed information about how to use Record scripts or Playback scripts, refer to the Video Savant 4.0 User's Guide. The functions below are the Python functions that can be called to directly control parts of Video Savant. iAbsDif Calculate the absolute difference between two images forming a third image. int iAbsDif( int source1StartBuf, // Starting source1 buffer int source1EndBuf, // Ending source1 buffer int source2StartBuf, // Starting source2 buffer int source2EndBuf, // Ending source2 buffer 1
141

Video Savant Python function library - [email protected]

Feb 09, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Video Savant Python function library - [email protected]

Video Savant Python function library Python is a popular scripting language with easy to use syntax. The user has the capability to run Python scripts to help customize the control of Video Savant. A good introduction to the general syntax of Python can be found at the following web page: http://www.python.org/doc/current/. Python scripts are setup in the DVR Control Panel of Video Savant. The screenshot below shows a Recording script displayed in Python window on the bottom right of the DVR Control Panel. The output of that script can be displayed by selecting Script output instead of Record script. The Record Script control box allows the user to create a Python script or to open an existing one. For more detailed information about how to use Record scripts or Playback scripts, refer to the Video Savant 4.0 User's Guide.

The functions below are the Python functions that can be called to directly control parts of Video Savant. iAbsDif

Calculate the absolute difference between two images forming a third image.

int iAbsDif(

int source1StartBuf, // Starting source1 buffer int source1EndBuf, // Ending source1 buffer int source2StartBuf, // Starting source2 buffer int source2EndBuf, // Ending source2 buffer

1

Page 2: Video Savant Python function library - [email protected]

int destStartBuf, // Starting destination buffer int destEndBuf // Ending destination buffer

);

Parameters source1StartBuf , source1EndBuf

Starting and ending buffers of the first sequence of buffers to calculate the absolute difference on.

source2StartBuf, source2EndBuf

Starting and ending buffers of the second sequence of buffers to calculate the absolute difference on.

destStartBuf, destEndBuf

Starting and ending buffers to store the absolute difference between source1 buffers and source2 buffers

Return Values The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. See also iSubtract Example

To calculate the absolute difference between buffers 2 and 7 and store the result in buffer 10: vspython.iAbsDif(2,2,7,7,10,10) iActivateCursorMode Activates interactive image cursor operations.

2

Page 3: Video Savant Python function library - [email protected]

The image cursor operations are:

• Moving a cursor in an image (Cursor Tool); • Moving and sizing a line graphic (Line Tool); • Moving and sizing a rectangle graphic (Area Tool); and • Sketching in an image (Pen Tool).

list iActivateCursorMode(

int sourceBuffer, // image buffer for cursor operation int toolStyle, // Tool style int initialToolState, // Initial state of tool int lockToolInState, // Lock tool into a state? int xCursorPos, yCursorPos // Cursor position or first endpoint

// of line/rectangle graphic int xSecondEndpoint, ySecondEndpoint

// Second endpoint of line or // rectangle graphic.

string CaptionName, // operation name for status line optional string CallBackFunctionName, // Callback function name optional string CallBackModuleName // Callback Module name

);

Parameters

sourceBuffer

Image buffer to be used for the image cursor operation. toolStyle

The style of the tool that is being used. It must be set to one of the following values:

Value Meaning

iCM_CURSORTOOL Allows a cursor to positioned. iCM_LINETOOL Allows a line to be positioned and sized. iCM_AREATOOL Allows a rectangle to be positioned and sized. iCM_PENTOOL Allows sketching in an image

initialToolState

The initialToolState is the intial state that the tool is in. It must be set to one of the following values:

Value Meaning

iCM_CURSOR An image cursor is shown.

3

Page 4: Video Savant Python function library - [email protected]

iCM_ANCHOR A line or rectangle graphic is being sized. iCM_LINE A line is being positioned. iCM_AREA A rectangle is being positioned.

The initialToolState can take on the value iCM_CANCEL if the user has issued a command to cancel. The initialToolState field is necessary to allow positioning and sizing of rectangle and line graphics for the Area Tool and Line Tool.

lockToolInState

If lockToolInState is set to 0, this allows state switching by the user. If it is set to a non-zero value, this prevents state switching by the user.

xCursorPos, yCursorPos

Cursor coordinates or first endpoint in line or rectangle graphic. xSecondEndpoint, ySecondEndpoint

Second endpoint of line or rectangle graphic. CaptionName

Points to a null terminated character string to be displayed as a label for the image cursor operation. In a two-monitor system, the caption is a window title bar. In a single-monitor system, the caption is the first field on the image viewer status line.

CallBackFunctionName

The function name of a callback function used to trap cursor messages during a cursor operation. If feedback is not required during a cursor operation, CallBackFunctionName should not be used.

Parameters

wMsg Value Meaning

iCM_EXIT User issued exit command by pressing the right

mouse button, RETURN key, or ESC key.

iCM_CHANGE The user clicked the left mouse button or pressed the SPACE BAR key. This message is only sent when using the cursor tool or when using a tool with state switching locked.

iCM_DO User issued a do command by pressing the SHIFT

key in combination with the right mouse button or the RETURN key. The usual response is for the application to perform some task.

4

Page 5: Video Savant Python function library - [email protected]

wCursor

The wCursor parameter is an integer which represents the location of the cursor information calculated each time the Callback function is called. To extract this information, you need to call “vspython.iCursorModeInfo” with wCursor as its only parameter inside your callback function. iCursorModeInfo will return a list with 6 elements. See iCursorModeInfo for more information.

CallBackModuleName The module name of a callback function used to trap cursor messages during a cursor operation. If feedback is not required during a cursor operation, CallBackModuleName should not be used. You may be required to specify the full path name of the module.

Return Value The function returns a list of 4 elements which represents the endpoints of the graphic clipped to image boundaries. If the tool is in the cursor state, the endpoints are equal. If the tool is in the area state, the first two elements are the top-left coordinate of the area.

Remarks The user switches between the following states:

• Positioning one endpoint of the graphic; • Positioning the other endpoint of the graphic; and • Moving the graphic.

State switching is accomplished by pushing the left mouse button or pressing the SPACE BAR on the keyboard. The user exits an image cursor operation by:

• Pushing the right mouse button (normal); • Pushing the RETURN key (normal); or • Pushing the ESCAPE key (user requests that his settings be ignored).

. See Also

5

Page 6: Video Savant Python function library - [email protected]

iShowCursorPoint, iShowCursorLine, iShowCursorRect, iCursorModeInfo Examples

Example 1 Using an unlocked cursor tool on buffer 3, starting at position (45, 45). The label for the image cursor operation is “Testing”. The resulting position after calling the function is stored in “pos”

pos = iActivateCursorMode(3, iCM_CURSORTOOL, iCM_CURSOR, 0, 45, 45, 45, 45, "Testing") print "positions are:",pos

Example 2

In file “c:/test/sample.py” I have the following callback function defined: # sample callback function for iActivateCursor def cursor(msg, cursor): import vspython cursorList = vspython.iCursorModeInfo(cursor) print "State is: ", cursorList[1] print "Message is: ", msg print "Style is: ", cursorList[0] print "Cursor Locked is: ", cursorList[2] print "Cursor Position is: ", cursorList[3] print "Cursor Anchor Position is: ", cursorList[4] print "New Cursor Position is: ", cursorList[5] return 1

In my main script I use an unlocked area tool on buffer 3. The starting rectangular area has a top-left coordinate of (45,45) and a bottom-right coordinate of (250,350). The label for the image cursor operation is “Testing”. The Callback function is in the module “sample.py” in the “c:/test directory. The Callback function is called “cursor” iActivateCursorMode(3, iCM_AREATOOL, iCM_AREA, 0, 45, 45, 250, 350, "Testing", "cursor", "c:/test/sample") iAdd Add two images to form a third image. int iAdd(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer

6

Page 7: Video Savant Python function library - [email protected]

int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is added together with the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers in do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. If an addition results in overflow the result is automatically truncated to (2pixel size - 1). Example Adding buffers 2,3,4,5 with buffers 7,8,9,10 and storing the result in buffers 13,14,15,16. vspython.iAdd(2,5,7,10,13,16) iAddConstant Add a constant value to an image to form a second image.

int iAddConstant(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer

7

Page 8: Video Savant Python function library - [email protected]

int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constantPixelValue // constant to add to pixels optional int greenPixelValue // green constant to add to pixels optional int bluePixelValue // blue constant to add to pixels

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will be added to the constant value.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

constantPixelValue

The constant value to add to the pixels in the images in the sequence between sourceStartBuf and sourceEndBuf. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be added to all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be added to the corresponding color in the source buffers.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks

The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. Results which overflow are limited to (2pixel size - 1). See also iSubtractConstant Examples

8

Page 9: Video Savant Python function library - [email protected]

Example 1 Adding the constant(50) to the images in the sequence 2,3 and storing the result in

buffers 7,8. vspython.iAddConstant(2,3,7,8,50) Example 2 Adding the constant(128) to the red pixel values, constant(255) to the green pixel values, and constant(0) to the blue pixel values of the image in buffer 2. The result will be stored in buffer 7. vspython.iAddConstant(2,2,7,7,128,255,0) iAlloc Allocate space for a storage block of data. int iAlloc(

int size, // size of storage block int pixelType // pixel type

)

Parameters size

The size of the storage block. All functions that require iAlloc to allocate space for a storage block will specify what size should be passed to iAlloc.

pixelType

The type of data to be stored in the storage block. The possible types are:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale

values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit

9

Page 10: Video Savant Python function library - [email protected]

devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

iPIXTYPEPOINT Data is stored as (x,y) coordinate pairs.

iPIXTYPECONTOURS Data is stored as contour values.

Return Value The return value is an integer which represents the location of the storage block of data, which now has space allocated for it. See Also iFree, iReadBlock, iReadElement, iReadRGBBlock, iReadLine, iWriteBlock, iWriteElement, iWriteRGBBlock, iEnumExtractContours, iGetLinePoints, iTableTransform Example See examples for all the functions in the See Also section. iAND Perform a bitwise AND between two images to form a third image.

int iAND(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters

source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

10

Page 11: Video Savant Python function library - [email protected]

The sequence between source1StartBuf and source1EndBuf buffers is ANDed together with the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise AND examines the pixel values in the sources bit-by-bit, and sets the bits in the destination value according to this table: Source1 Source 2 Destination 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1 Example ANDing buffers 2,3,4,5 with buffers 7,8,9,10 and storing the result in buffers 13,14,15,16. vspython.iAND(2,5,7,10,13,16) iANDConstant Perform a bitwise AND between an image and a constant to form a second image.

int iANDConstant(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer

11

Page 12: Video Savant Python function library - [email protected]

int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constantPixelValue // constant to AND with pixels optional int greenPixelValue // green constant to AND with pixels optional int bluePixelValue // blue constant to AND with pixels

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will be ANDed with the constant value.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

constantPixelValue

The constant value to AND with the pixels in the images in the sequence between sourceStartBuf and sourceEndBuf. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be ANDed with all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be ANDed with the corresponding color in the source buffers.

Return Value The return value is non-zero if successful, and zero if an error occurred. Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise AND examines the pixel values in the source and the constant value bit-by-bit, and sets the destination pixel bits according to this table: Source1 Source 2 Destination 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0

12

Page 13: Video Savant Python function library - [email protected]

1 AND 1 = 1 Examples Example 1

ANDing the constant(50) to the images in the sequence 2,3 and storing the result in buffers 7,8. vspython.iANDConstant(2,3,7,8,50) Example 2 ANDing the constant(128) to the red pixel values, constant(255) to the green pixel values, and constant(0) to the blue pixel values of the image in buffer 2. The result will be stored in buffer 7. vspython.iANDConstant(2,2,7,7,128,255,0) iAverageSequence Average images in a sequence of consecutive image buffers and store the result in a destination image buffer.

int iAverageSequence(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destBuf // destination buffer to store results

);

Parameters

sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will be averaged together

destBuf

The averaged image is stored in this image buffer Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The current ROI setting is ignored in the calculation.

13

Page 14: Video Savant Python function library - [email protected]

The average is calculated by accumulating image pixels in an image of 32-bit storage elements, 1 for each pixel location, and dividing each storage element by the number of images in the average.

iSetRGBPlaneUsage sets the color planes affected by this operation. The contents of the source buffers may be overwritten. This function is useful for improving image quality after acquisition. Once an image sequence is acquired, this function can be used to average out electronic noise between frames in the image sequence. Example Averaging images 2,3,4,and 5 and storing the result in buffer 7 vspython.iAverageSequence(2,5,7) iBinarize Convert an image to a binary image.

int iBinarize(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int lowPixelValue, // low value in pixel range int highPixelValue, // high value in pixel range int constantPixelValue, // constant value to assign to pixels in range optional int greenPixelValue, // green constant to assign to pixels

// in range optional int bluePixelValue, // blue constant to assign to pixels in

// range optional int greenLowPixelValue, // green low value in pixel range optional int blueLowPixelValue, // blue low value in pixel range optional int greenHighPixelValue, // green high value in pixel range optional int blueHighPixelValue // blue high value in pixel range

);

Parameters

sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers are the buffers to be operated on.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image

14

Page 15: Video Savant Python function library - [email protected]

buffers to place the results. lowPixelValue

The low end of the range of pixel values. If you wish to set a different low end of the range of pixel values for each of the red, green, and blue color planes, set the optional parameters greenLowPixelValue and blueLowPixelValue. (constantPixelValue will be used for the red color plane) Otherwise, lowPixelValue will be the low end of the range of pixel values for each of the color planes.

highPixelValue

The high end of the range of pixel values. Normally, pixel values between lowPixelValue and highPixelValue are set to constantPixelValue in the destination buffers. If highPixelValue is less than lowPixelValue, the values wrap around, i.e. pixel values from lowPixelValue to (2pixel size - 1) and from 0 to highPixelValue are set to constantPixelValue in the destination buffers. If you wish to set a different high end of the range of pixel values for each of the red, green, and blue color planes, set the optional parameters greenHighPixelValue and blueHighPixelValue. (constantPixelValue will be used for the red color plane) Otherwise, highPixelValue will be the high end of the range of pixel values for each of the color planes.

constantPixelValue

The constant value to set destination pixels to when the source pixels fall between pxLow and pxHigh. If the image is a color image and greenPixelValue and bluePixelValue are not set, all three color planes will be set to constantPixelValue when the source pixels fall between pxLow and pxHigh.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be used to set destination pixels to when the source pixels fall between the low and high pixel values (of the appropriate color).

greenLowPixelValue, blueLowPixelValue

See the description of lowPixelValue above to see how to set these values greenHighPixelValue, blueHighPixelValue

See the description of highPixelValue above to see how to set these values Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

15

Page 16: Video Savant Python function library - [email protected]

Remarks A binary image has two possible values for each pixel. For color images, iSetRGBPlaneUsage sets the color planes affected by this operation. Color planes are binarized separately, therefore it is possible to binarize each color plane differently, yielding pixels with 8 possible values instead of two (if all 3 planes are processed). The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. Examples Example 1 Convert the image in buffer 3 to a binary image by setting all pixels with values between 0 and 7 to 50. Store the result in buffer 5. vspython.iBinarize(3,3,5,5,0,7,50) Example 2 Convert the image in buffer 3 to a binary image by setting all red pixels with values between 0 and 255 to 128, all green pixels with values between 0 and 255 to 255 and all blue pixels with values between 0 and 255 to 0. Store the result in buffer 5. vspython.iBinarize(3,3,5,5,0,255,128,255,0) Example 3 Convert the image in buffer 3 to a binary image by setting all red pixels with values between 0 and 255 to 128, all green pixels with values between 127 and 129 to 255 and all blue pixels with values between 250 and the maximum pixel size or between 0 and 150 to 0. Store the result in buffer 5. vspython.iBinarize(3,3,5,5,0,255,128,255,0,127,250,129,150) iConvertPixel Converts a pixel of one type to another type. [int or list] iConvertPixel(

int incomingPixelType, // pixel type of pixelValue int outgoingPixelType, // pixel type to convert to int pixelValue, // pixel value to convert optional int greenPixelValue, // green pixel value to convert

16

Page 17: Video Savant Python function library - [email protected]

optional int bluePixelValue // blue pixel value to convert );

Parameters incomingPixelType This is the pixel type of pixelValue. If you are converting a color RGB value,

then incomingPixelType is the pixel type of the RGB triplet (pixelValue, greenPixelValue, bluePixelValue). incomingPixelType can be set to the same values as pixelType in iReadBlock.

outgoingPixelType This is the pixel type to convert pixelValue to. You may not set

outgoingPixelType to the same value as incomingPixelType. outgoingPixelType can be set to the same values as pixelType in iReadBlock.

pixelValue

The pixel value to be converted. If incomingPixelType is iPIXTYPERGB, then pixelValue will represent the red pixel value, and greenPixelValue and bluePixelValue will represent the green and blue pixel values of the color image respectively.

greenPixelValue, bluePixelValue

greenPixelValue and bluePixelValue should only be set if incomingPixelType is iPIXTYPERGB. They represent the green and blue pixel values of the color image to be converted.

Return Value The converted pixel value. If the outgoingPixelType refers to a gray scale image pixel type, the return value will be an integer representing the converted pixel value. Otherwise, if the outgoingPixelType is iPIXTYPERGB, the return value will be a list of 3 elements which represents the red, green, and blue pixel values of a color image. Remarks iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iWritePixel, iReadPixel, iSetRGBPlaneUsage

17

Page 18: Video Savant Python function library - [email protected]

Examples Example 1

I want to convert the 16 bit gray scale pixelValue "20000" to the corresponding 8 bit gray scale value. resultValue = vspython.iConvertPixel(iPIXTYPE16, iPIXTYPE8, 20000) print "The 8 bit value is: ", resultValue Example 2

I want to convert the color image with red, green and blue values of (100, 125, 75) to an 8 bit gray scale value. resultValue = vspython.iConvertPixel(iPIXTYPERGB, iPIXTYPE8, 100, 125, 75) print "The 8 bit value is: ", resultValue iConvolve Perform image convolution.

int iConvolve(

int sourceStartBuf, // source start buffer of images to process int sourceEndBuf, // source end buffer of images to process int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int predefKernelIndex, // index of predefined kernel to use int numColInKernel, // number of columns in kernel int numRowInKernel, // number of rows in kernel string userDefinedKernel, // user defined Kernel int Divisor, // divisor used in processing int Options // processing option

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers are the buffers to process.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

predefKernelIndex

When set to zero, the user defined kernel will be used. When set to one of the following constants, a predefined kernel will be loaded.

18

Page 19: Video Savant Python function library - [email protected]

Value Operation Kernel

iCONVO_LOWPASS Smooth

1 1 1 1 1 1 1 1 1

iCONVO_LAPLACIAN Enhance edges and lines

1 0 1 0 -4 0 1 0 1

iCONVO_EDGE Enhance edges

0 -1 0 -1 4 -1 0 -1 0

iCONVO_EDGEV Enhance vertical edges

-1 0 1 -2 0 2 -1 0 1

iCONVO_EDGEH Enhance horizontal edges

-1 -2 -1 0 0 0 1 2 1

iCONVO_EDGED1 Enhance diagonal edges (\)

0 -1 2 1 0 -1

-2 1 0

iCONVO_EDGED2 Enhance diagonal edges (/)

2 -1 0 -1 0 1 0 1 -2

iCONVO_LINEHV1 Enhance horizontal and vertical lines (1)

0 1 0 -1 0 1 0 1 0

iCONVO_LINEHV2 Enhance horizontal and vertical lines (2)

-1 0 1 0 0 0 1 0 -1

iCONVO_LINED1 Enhance diagonal lines (1)

1 -2 1 -2 4 -2 1 -2 1

iCONVO_LINED2 Enhance diagonal lines (2)

-2 1 -2 1 4 1

-2 1 -2

numColInKernel

The number of columns in the kernel. This number must be odd and equal to or greater than 3. numColInKernel is ignored if a predefined kernel is being used.

numRowInKernel

The number of rows in the kernel. This number must be odd and equal to or greater than 3. numRowInKernel is ignored if a predefined kernel is being used.

userDefinedKernel

This string represents a user defined kernel. Each value in the string is separated by a comma. There must be numColInKernel*numRowInKernel values in the string. To create a user defined kernel equivalent to

19

Page 20: Video Savant Python function library - [email protected]

iCONVO_LAPLACIAN, the string should be "1,0,1,0,-4,0,1,0,1" with numColInKernel and numRowInKernel both set to 3. If a predefined kernel is being used, this parameter should be set to NULL or the empty string.

Divisor

The convolution result is divided by Divisor. Divisor is ignored if a predefined kernel is being used.

Option

Specifies a processing option for the convolution operation. Option is set by performing a bitwise OR operation of any combination of the following constants:

Value Meaning iCONVO_COPYNEWEDGES Boundaries set to copy of nearest neighbor's

result. If not specified, image boundaries will not be modified.

iCONVO_ABSRESULT Negative results set to positive, absolute value.

If not specified, negative results are set to zero. Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks A kernel is convolved with an image as follows: Kernel = k11 k12 k13

k21 k22 k23 k31 k32 k33

Image =

The convolution computation of this 3x3 kernel with the pixels in the top left image corner yields:

i11 i12 i13 ...

i21 i22 i23 ...

i31 i32 i33 ...

... ... ... ...

i22' = (k11 × i11 + k12 × i12 + k13 × i13 +

k21 × i21 + k22 × i22 + k23 × i23 + k31 × i31 + k32 × i32 + k33 × i33) / nDivisor

20

Page 21: Video Savant Python function library - [email protected]

Negative results are optionally made positive. The kernel is convolved with the image starting at the top left, replacing the image pixel under the center of the kernel. The kernel is then translated one pixel to the right, and another convolution is performed. This is repeated until the right side of the image is reached, after which the kernel is placed on the left side of the image, one pixel row down, and another line of calculations are done. The maximum kernel size depends on the camera interface used. For most devices, this is large. numColInKernel and numRowInKernel must be less than or equal to the horizontal and vertical buffer size respectively. Results greater than (2pixel size - 1), are truncated to (2pixel size - 1). (output pixels are limited to the maximum value of the current pixel size) The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Examples

Example 1 Image convolution is performed on the image in buffer 3 using the predefined kernel "iCONVO_LOWPASS". Since the user defined kernel is set to NULL, it will be ignored. All other parameters are set to 0, because they are ignored when a predefined kernel is being used. The result is stored in buffer 5. vspython.iConvolve(3,3,5,5, iCONVO_LOWPASS, 0,0,NULL,0,0) Example 2 Image convolution is performed on the image in buffer 3 using a user defined kernel ("1,0,1,0,1,0,1,0,1,0,1,0,1,0,1") with 3 rows and 5 columns. The convolution result is divided by 1. In addition, boundaries are set to copy the nearest neighbor's result. The result is stored in buffer 5. vspython.iConvolve(3,3,5,5,0,3,5, "1,0,1,0,1,0,1,0,1,0,1,0,1,0,1",1, iCONVO_COPYNEWEDGES) iCopy

21

Page 22: Video Savant Python function library - [email protected]

Copy one image to another image. int iCopy(

int sourceStartBuf, // source start buffer of images to copy int sourceEndBuf, // source end buffer of images to copy int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers are the buffers to copy.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to store the copied images.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iCopyTo, iCopyToTargets Example Copy images from buffers 2,3,4,5 and store them in buffers 7,8,9,10. vspython.iCopy(2,5,7,10) iCopyTo Copy image pixels in the ROI to another (x,y) location. int iCopyTo(

int sourceStartBuf, // source start buffer to copy

22

Page 23: Video Savant Python function library - [email protected]

int sourceEndBuf, // source end buffer to copy int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int topXPos, // top-left x coordinate in destination int topYPos, // top-left y coordinate in destination optional int constantPixelValue, // constant to set to source optional int greenPixelValue, // green constant to set to source optional int bluePixelValue, // blue constant to set to source

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will have their images copied.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to store the copied images.

topXPos

The top-left corner X coordinate of the destination. This value can be positive or negative.

topYPos

The top-left corner Y coordinate of the destination. This value can be positive or negative.

constantPixelValue

If constantPixelValue is set, all the pixels in the source buffers will be set to constantPixelValue. If the image is a color image and greenPixelValue and bluePixelValue are not set, all of the pixels (red, green, and blue) will be set to constantPixelValue.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then the red pixel values in the source buffers will be set to constantPixelValue, the green pixel values in the source buffers will be set to greenPixelValue, and the blue pixel values in the source buffers will be set to bluePixelValue.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The source and destination can overlap.

23

Page 24: Video Savant Python function library - [email protected]

If the copied image ROI exceeds buffer boundaries in the destination, it is clipped. The image buffers do not have to be unique. iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iCopy, iCopyToTargets Examples

Example 1 The images at buffers 3,4 are copied to buffers 5,6 starting at position (25,45). The image is truncated to fit in the destination buffers(5,6). vspython.iCopyTo(3,4,5,6,25,45) Example 2 The image at buffer 3 is copied to buffer 5 starting at position (25,45). The image is truncated to fit in the destination buffer(5). In addition, the image at buffer 3 is overwritten with all red pixel values set to 0, all green pixel values set to 128, and all blue pixel values set to 255. vspython.iCopyTo(3,3,5,5,25,45,0,128,255) iCopyToTargets Copy image pixels in the ROI to multiple (x,y) locations. int iCopyToTargets(

int sourceStartBuf, // source start buffer to copy int sourceEndBuf, // source end buffer to copy int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results string destTargets, // destination coordinates for copy int numTargets, // number of targets for copy int oneTargetPerBuffer, // method for enumeration of targets optional int constantPixelValue, // constant to set to source optional int greenPixelValue, // green constant to set to source optional int bluePixelValue // blue constant to set to source

);

Parameters

24

Page 25: Video Savant Python function library - [email protected]

sourceStartBuf, sourceEndBuf The sequence between sourceStartBuf and sourceEndBuf buffers will have their images copied.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to store the copied images.

destTargets

A string containing the top-left corner coordinates of the target locations. The string separates each bracketed set of coordinates by commas. The format of the string is "(x1,y1),(x2,y2),(x3,y3),…,(xn,yn)". These locations can contain negative X and Y coordinates.

numTargets

The number of target locations. This number must match the number of (x,y) pairs specified in dest targets.

oneTargetPerBuffer

If set to zero, the source image will be copied to all target array locations in the destination buffer. If non-zero, the source image will be copied once per destination buffer, so that the image in the ith source buffer in the sequence sourceStartBuf..sourceEndBuf will be copied to the ith target array location in the ith destination buffer in the sequence destStartBuf..destEndBuf.

constantPixelValue

If constantPixelValue is set, all the pixels in the source buffers will be set to constantPixelValue. If the image is a color image and greenPixelValue and bluePixelValue are not set, all of the pixels (red, green, and blue) will be set to constantPixelValue.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then the red pixel values in the source buffers will be set to constantPixelValue, the green pixel values in the source buffers will be set to greenPixelValue, and the blue pixel values in the source buffers will be set to bluePixelValue.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The source and destination buffers can overlap.

25

Page 26: Video Savant Python function library - [email protected]

If the copied image ROI exceeds buffer boundaries in the destination, it is clipped. The image buffers do not have to be unique. iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iCopy, iCopyTo Examples Example 1 Copy image pixels from buffer 2 to the following 6 locations in buffer 5: (0,50), (0,75), (200,200), (511,0), (511, 50), (511, 479). Copy image pixels from buffer 3 from the same 6 locations as above to buffer 6. vspython.iCopyToTargets(2,3,5,6, "(0,50),(0,75),(200,200),(511,0),(511,50),(511,479)", 6, 0) Example 2 Copy image pixels from buffer 2 to location (0,50) of buffer 5. Copy image pixels from buffer 3 to location (200,200) of buffer 6. Set the red pixel values of buffers 2,3 to 75, the green pixel values of buffers 2,3 to 255, and the blue pixel values of buffers 2,3 to 125. vspython.iCopyToTargets(2,3,5,6, "(0,50),(200,200)",2,1,75,255,125) iCursorModeInfo

Extract cursor information from iActivateCursorMode list iCursorModeInfo( int cursor // location of the cursor information ); Parameters cursor

Location of the cursor information. cursor is obtained from the Callback function to iActivateCursorMode.

Return Value

26

Page 27: Video Savant Python function library - [email protected]

iCursorModeInfo returns a list with 6 elements: ELEMENT 1: Cursor Style ELEMENT 2: Cursor State ELEMENT 3: Cursor state is locked? ELEMENT 4: List containing x,y coordinates of cursor position ELEMENT 5: List containing the ending x,y coordinates of a line or

rectangle graphic ELEMENT 6: List containing two x,y pairs of the new x,y position of the

cursor or graphic See Also iActivateCursorMode Example See Example 2 from iActivateCursorMode iDisplayFrame

Display a single frame. int iDisplayFrame(

int DestBuf, // Buffer to display );

Parameters DestBuf DestBuf contains the buffer that is to be displayed Return Value

The return value is non-zero if successful. It is zero if an error occurred.

Example Display the image in buffer 14.

vspython.iDisplayFrame(14) iDivide Divide one image by another image to form a third image.

27

Page 28: Video Savant Python function library - [email protected]

int iDivide(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is divided by the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Because iDivide performs an integer division, any fractional portion of the result is discarded.

If a pixel in the sequence source2StartBuf..source2EndBuf is 0 (which would result in division by 0) the corresponding destination pixel is set to (2pixel size - 1). Example The image in buffer 3 is divided by the image in buffer 2 with the result stored in buffer 9, and the image in buffer 4 is divided by the image in buffer 2 with the result stored in buffer 10. vspython.iDivide(3,4,2,2,9,10)

28

Page 29: Video Savant Python function library - [email protected]

iEnumCountObjects Counts objects (blobs) in an image. Features:

• Calculates object areas, centroids and axes of rotation; • Labels objects;

• Paints counted objects;

• Draws bounding rectangles of objects; and

• Draws axes of rotation of objects.

long iEnumCountObjects(

int sourceBuf, // image buffer to analyse int destBuf, // image buffer to draw labels/graphics int lowThresholdPixelValue, // lowest value for ‘on’ pixels int highThresholdPixelValue, // highest value for ‘on’ pixels int Options, // options for measuring and annotating int minArea, // minimum area of blobs to count int maxArea, // maximum area of blobs to count string CallBackFunctionName, // Callback function name string CallBackModuleName // Callback Module name

);

Parameters sourceBuf

The image buffer to count objects in. destBuf

Image buffer to draw the blob graphics in. The blob graphics are optional. The type of blob graphic drawn is specified by the Options parameter.

lowThresholdPixelValue, highThresholdPixelValue

The range of gray scale values used to binarize the source image. Pixels with values greater than or equal to lowThresholdPixelValue, and less than or equal to highThresholdPixelValue, are on, otherwise pixels are off. If highThresholdPixelValue is less than lowThresholdPixelValue, pixels between 0 and highThresholdPixelValue, as well as pixels between lowThresholdPixelValue and the maximum value (255 on an 8-bit grayscale device) are considered on. The term Object, also referred to as Blob, denotes a group of connected on pixels in an image.

29

Page 30: Video Savant Python function library - [email protected]

Options

This parameter is set by performing a bitwise OR operation with any of the following constants: Value Meaning iCO_EXCLUDEEDGES Do not count objects which touch the sides of

an image buffer.

iCO_CALCAXES Calculate the axes of rotation of objects.

iCO_DRAWRESULT Set all the pixel locations in an object to the value 128. Objects which have been rejected for analysis are painted also.

iCO_DRAWAXES Draw the axes of rotation for each object. The iCO_CALCAXES flag must also be specified.

iCO_DRAWNUMBERS Draw number labels on each object.

iCO_DRAWBOUNDS Draw rectangle boundaries around each object. minArea, maxArea

Include objects with area greater than or equal to minArea and less than or equal to dwMaxArea in the analysis. Exclude objects with area outside this range from the analysis. Area is specified in square pixel units.

CallBackFunctionName

The function name of a callback function used to extract additional object count information. If additional count information is not needed, this parameter should be set to NULL or the empty string. Parameters index The object index. The first object will have an index of 0. center

An integer representing the position of the center of the object. To extract this value, center should be passed to iObjectCenter. See iObjectCenter for more information.

area The object area. This value is in square pixels. centroidAxes

30

Page 31: Video Savant Python function library - [email protected]

An integer representing the position of the major and minor centroid axes of the object. To extract this value, centroidAxes should be passed to iObjectCentroid. See iObjectCentroid for more information.

rectangle An integer representing the position of the bounding rectangle of the object. To extract this value, rectangle should be passed to iObjectRectangle. See iObjectRectangle for more information.

CallBackModuleName

The module name of a callback function used to extract additional object count information. If additional count information is not needed, this parameter should be set to NULL or the empty string. You may be required to specify the full path name of the module.

Return Value Returns the number of objects which were counted. Remarks This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iObjectCenter, iObjectCentroid, iObjectRectangle Example

In file “c:/test/sample.py” I define the following callback function: # sample callback function for iEnumCountObjects def objects(index, center, area, centroid, rectangle): import vspython print "Index is: ", index clist = vspython.iObjectCenter(center) print "Center is: ", clist print "Area is: ", area cdlist = vspython.iObjectCentroid(centroid) print "Centroid is: ", cdlist

31

Page 32: Video Savant Python function library - [email protected]

rlist = vspython.iObjectRectangle(rectangle) print "Rectangle is: ", rlist del clist del cdlist del rlist return 1 In my main module, I want to count all of the objects found in the image from buffer 3, where an object must have all its pixel values between 5 and 203. Also, I don't want to count any objects which touch the edge of the image, and I want to calculate and draw the resulting objects with their axes in buffer 5. Objects smaller than 100 square pixels or bigger than 5000 square pixels are not counted. I call the Callback function "objects" located in the module "sample" in the "c:/test" directory to extract each object's index, center, area, centroid axes, and bounding rectangle. Finally I store the number of objects found in the variable result. result = iEnumCountObjects(3,5,5,203,iCO_EXCLUDEEDGES | iCO_DRAWRESULT | iCO_DRAWAXES | iCO_CALCAXES, 100, 5000, "objects", "c:/test/sample") print "The number of objects found is:", result iEnumExtractContours Extract the path of iso-intensity lines (contours) in an image. int iEnumExtractContours(

int sourceBuffer, // image buffer to process int destBuffer, // image buffer for drawing contours int numOfContours, // number of contour levels to map int ptrToContourValues, // pointer to location of contour values int drawContourResults, // drawing contour graphics string CallbackFunctionName, // callback function name to extract contour

// info string CallbackModuleName // callback module name to extract contour

// info );

Parameters sourceBuffer

The source image buffer for finding contours. destBuffer

The destination image buffer for drawing the resulting contours.

32

Page 33: Video Savant Python function library - [email protected]

numOfContours

The number of contours to find in the image. ptrToContourValues

A pointer to a list containing the contour levels to search for in the image. The array contains (numOfContours+1) entries. To find the contours at gray levels c1, c2, and c3 (c1<=c2<=c3), the list is filled is follows:

import ListManip ptr = vspython.iAlloc(4, iPIXTYPECONTOURS) list = [] list.append(c1) list.append(c2) list.append(c3) list.append(255) ListManip.StoreList(ptr, list, iPIXTYPECONTOURS)

The last value is always set to maximum gray level (i.e. 255 for an 8-bit device; 65535 for a 16-bit device. ptrToContourValues must have been returned from a previous call to iAlloc with the number of contours as the size and iPIXTYPECONTOURS as the pixel type.

drawContourResults if drawContourResults is set to 1, the path of the extracted contours will be plotted in destBuf. Set drawContourResults to 0 if you do not want the path plotted.

CallBackFunctionName

The module name of a callback function used to extract contour information. Parameters contLevel This is the index of the contour level. The first index starts at 0. numContAtLevel This is the number of contours found at the current level. indexCurCont This is the index of the current contour. The first index starts at 0. lengthIndexCurCont This is the length of the current contour at indexCurCont. points

33

Page 34: Video Savant Python function library - [email protected]

The points parameter is an integer which represents the (x,y) coordinates located along the current contour at indexCurCont. To extract the list of coordinates, pass points to CreateList (in the ListManip module) with lengthIndexCurCont as the size of the list, and iPIXTYPEPOINT as the pixel type.

CallBackModuleName

The module name of a callback function used to extract contour information. You may be required to specify the full path name of the module.

Return Value This function returns 1 if at least one contour was found, and 0 otherwise. Remarks For color pixels, the pixel weight is calculated based on the average value of the current pixel color planes as specified by iSetRGBPlaneUsage. This operation is only performed on pixels in the current ROI. Example

In file “c:/test/sample.py” I define the following callback function: # sample callback function for iEnumExtractContours def contours(contLevel, numContAtLevel, indexCurCont, lengthIndexCurCont, points): import ListManip print "Contout Level: ", contLevel print "Number of contours at level: ", numContAtLevel print "Index Current Contour: ", indexCurCont print "Length of the current contour:", lengthIndexCurCont list = ListManip.CreateList(points, lengthIndexCurCont, iPIXTYPEPOINT) for count in xrange(lengthIndexCurCont): print list[count] del list return 1 In the main script, I want to extract the contours from the image in buffer 3. I am searching 3 contour levels (0 to 128, 129 to 200, 201 to 255). Also, the extracted contours will be drawn in buffer 5.

34

Page 35: Video Savant Python function library - [email protected]

import ListManip ptr = vspython.iAlloc(3, iPIXTYPECONTOURS) list = [] list.append(128) list.append(200) list.append(255) ListManip.StoreList(ptr, list, iPIXTYPECONTOURS) vspython.iEnumExtractContours(3,5,3,ptr,1,"contours","c:/test/sample") vspython.iFree(ptr) iExportAllData Write unformatted (raw binary) video data frames and stream filter data frames to a file. int iExportAllData(

string szFilename, // full path of output file int nStartBuf, // buffer to start exporting from int nEndBuf // buffer to stop exporting from

);

Parameters szFilename

String specifying the name of the output file to receive the data. nStartBuf

Data associated with the image buffer(s) specified by the range of buffers between nStartBuf and nEndBuf will be written to the data file specified by szFilename.

nEndBuf

Data associated with the image buffer(s) specified by the range of buffers between nStartBuf and nEndBuf will be written to the data file specified by szFilename.

Return Value The return value is non-zero if the function succeeds. Zero is returned if an error has occurred. Remarks Video data and stream filter data is written to the output file by the Video Savant engine. The stream filter data is not formatted by the stream filter modules. The general format of the output file is as follows

Video file header Raw binary data for first video frame Raw binary data for stream filter1 first data frame

35

Page 36: Video Savant Python function library - [email protected]

Raw binary data for stream filter2 first data frame ... Raw binary data for stream filtern first data frame Raw binary data for second video frame Raw binary data for stream filter1 second data frame Raw binary data for stream filter2 second data frame ... Raw binary data for stream filtern second data frame ...

Data is written on 4096-byte boundaries. See Also iExportFile, iExportStreamFilterData Example I want to export the raw image data and stream filter data from buffers 5,6, and 7 to the file "MyData.raw" in the "c:\test" directory. vspython.iExportAllData("c:\\test\\MyData.raw", 5, 7) iExportFile

Writes an image to a file. int iExportFile(

string filename, // name of the file to write string filetype, // name of the file format int sourceStartBuf, // starting buffer of the source sequence int sourceEndBuf, // ending buffer of the source sequence optional int useOutputLUT // use output LUT settings to export file optional string settingsFilePath // full path name of the settings file // to store specific format settings

)

Parameters filename

The name of the file to be written.

filetype Name of file format, e.g. "TIFF, AVI, BMP, JPEG, RAW, etc.".

sourceStartBuf, sourceEndBuf sourceStartBuf..sourceEndBuf is the sequence containing the images to

36

Page 37: Video Savant Python function library - [email protected]

write to the file. Only the first image buffer is used if only one image is being written to a file. If the file format supports multiple images (e.g. TIFF), one image is written from each buffer in the sequence to the file, appending each image to the end of the file as it is written.

useOutputLUT

If this parameter is set to 1, the image(s) will be exported using the current output look-up table settings. This feature is only available for 16-bit grayscale images. Remember to call one of the file type settings functions (see Remarks below) and set the pixel type to 8-bit grayscale before calling iExportFile if you plan to export the image(s) using the current output look-up table settings.

settingsFilePath

This parameter specifies the full path of a file that contains the specific export settings (like the compression codec to use for an AVI export). If the file does not exist, a dialog will appear so that the user can specify the export settings for this type of file. After the user has chosen the settings for the export settings, the settings will be written to the file specified in settingsFilePath. If the export settings need to be modified when you execute your script, you must first delete the existing settings file.

Return Value The return value is non-zero if the image was successfully written to the file. If unsuccessful, the function returns 0.

Remarks To import an image of type "RAW", the function iSetRAWExportSettings should called to give specific information about the RAW image file. Also, some specific file type settings can be set by using the functions iSetTIFFWriteSettings, iSetAVIWriteSettings, iSetBMPWriteSettings, iSetJPEGWriteSettings, and iSetRAWExportSettings. If these functions are not called, default settings will be used. T his operation is only performed on pixels in the current ROI. See Also iSetTIFFWriteSettings, iSetAVIWriteSettings, iSetBMPWriteSettings, iSetJPEGWriteSettings, iSetRAWExportSettings, iImportFile

37

Page 38: Video Savant Python function library - [email protected]

Example I want to export images from buffers 5,6, and 7 to the file "sample.tif" in the "c:\test" directory. vspython.iExportFile("C:\\test\\sample.tif","TIFF",5,7) I want to export images from buffers 4, 5, and 6 to the file sample.avi in the “c:\test” directory. Also, I want to specify the AVI settings including the compression codec by using the provided settings dialog. These settings will be stored in a file called AVISettings.set which will be used for all future executions of this script. (unless the file is deleted in which case the settings dialog will appear again) vspython.iExportFile("C:\\test\\sample.avi","AVI",4,6,0,"C:\\test\\AVISettings.set") iExportStreamFilterData Write formatted stream filter data to a file. int iExportStreamFilterData(

string szFilename, // full path of output file int nStartBuf, // buffer to start exporting from int nEndBuf, // buffer to end exporting on optional string szFilterName // identifier of stream filter

);

Parameters szFilename

String specifying the name of the output file to receive the stream filter data. nStartBuf

Stream filter data associated with the image buffer(s) specified by the range of buffers between nStartBuf and nEndBuf will be written to the data file specified by szFilename.

nEndBuf

Stream filter data associated with the image buffer(s) specified by the range of buffers between nStartBuf and nEndBuf will be written to the data file specified by szFilename.

szFilterIdentifier

String specifying the identifier of the stream filter you are exporting data for. Refer to the release notes for a stream filter to obtain its name identifier. If this value is not specified, the first record stream filter in your list will be used.

Return Value The return value is non-zero if the function succeeds. Zero is returned if an error has

38

Page 39: Video Savant Python function library - [email protected]

occurred. Remarks The stream filter is responsible for formatting the output of stream filter data associated with it. See Also iExportFile, iExportAllData I want to export the date time stream filter data from buffers 5,6, and 7 to the file "MyData.txt" in the "c:\test" directory. (Of course the date/time stream filter must already be installed) vspython.iExportStreamFilterData("C:\\test\\MyData.txt",5,7, "Date/Time") iExtractCentroid Calculates the (x, y) location of the centroid in an image. The object's axes of rotation are also calculated. list iExtractCentroid(

int sourceBuffer, // image buffer to analyse int thresholdValue // threshold for ‘on’ pixels

);

Parameters sourceBuffer

The centroid will be calculated using this image buffer. thresholdValue

Pixels with values greater than or equal to thresholdValue are counted as 'on' in the centroid calculation. Pixels with values less than thresholdValue are ignored.

Return Value

iExtractCentroid returns a list with 3 elements: ELEMENT 1: x,y pair which is the center of the centroid ELEMENT 2: Two x,y pairs which represent the start and end points of the

major axis of the centroid ELEMENT 3: Two x,y pairs which represent the start and end points of the

39

Page 40: Video Savant Python function library - [email protected]

minor axis of the centroid Remarks The image is interpreted as a binary image, meaning that pixels with values greater than or equal to thresholdValue are considered to have a weight of 1, and pixels with values less than thresholdValue are considered to have a weight of zero. For color pixels, the pixel weight is calculated by comparing the average value of all selected pixel color planes (as specified by iSetRGBPlaneUsage) against thresholdValue. The centroid X position is computed by summing the X coordinates of all pixels with weight equal to 1 and dividing by the total number of pixels with weight equal to 1. The centroid Y position is computed by summing the Y coordinates of all pixels with weight equal to 1 and dividing by the total number of pixels with weight equal to 1. This operation is only performed on pixels in the current ROI. Example The center, major axis, and minor axis of the centroid in the image in buffer 3 are calculated by using pixels greater than or equal to 128 as part of the centroid. The center, major axis, and minor axis of the centroid are stored in the variable result. result = vspython.iExtractCentroid(3,128) print "Center, Major Centroid Axis, Minor Centroid Axis:",result

iExtractHistogram Calculate the frequency histogram of pixel values in an image. string iExtractHistogram(

int sourceBufferStart, // image buffer sequence to int sourceBufferEnd, // analyse optional int numIndexBits, // number of index bits optional int numBitsToShift, // Number of bit positions the Index.

// Bits are left-shifted from the least // significant bit.

optional int valueClassBits // value of the class bits );

40

Page 41: Video Savant Python function library - [email protected]

Parameters

sourceBufferStart, sourceBufferEnd

The sequence sourceBufferStart..sourceBufferEnd buffers to analyse.

numIndexBits, numBitsToShift, valueClassBits If numIndexBits, numBitsToShift, and valueClassBits are not set, a pixel with value p will be counted in the pth element of the results in the return value

We want to count only those pixels having a subset of bits equal to a particular value or Class.

The bits in an image pixel value are divided into Index Bits and Class Bits. If the Class Bits in a pixel value equals valueClassBits, the element indexed by the value stored in Index Bits will be incremented by 1.

If the number of Class Bits equals 0, all image pixels will be counted in the histogram calculation.

Either all of numIndexBits, numBitsToShift, and valueClassBits are specified or none of them are.

Return Value

The return value is a string of numbers separated by commas that represents the resulting histogram. To convert this string into a list of integers, call the function "StringToList" (part of the ListManip module).

Remarks For color pixels, the value of a pixel is calculated as the average value of the current pixel color planes as specified by iSetRGBPlaneUsage. The individual histograms of each image buffer in the sourceBufferStart..sourceBufferEnd sequence are added together and stored in the resulting string returned from iExtractHistogram. This operation is only performed on pixels in the current ROI. Examples Example 1 I want to count the number of occurrences of each pixel value in buffer 3. In addition, I want to convert the string return value into a list.

41

Page 42: Video Savant Python function library - [email protected]

import ListManip stringResult = iExtractHistogram(3,3) listResult = ListManip.StringToList(stringResult) print "Pixel Value:Num of Occurrences" for count in xrange(len(listResult)): print count, ":",listResult[count] Example 2 Assume we are using 8 bit monochrome. I want to count the number of occurrences of each group of 16 pixel values. (0 to 15, 16 to 31, etc.) I will use 4 index bits so that I get 24 values returned from iExtractHistogram. However, I want to look at the 4 most significant bits so I shift 4 bits. import ListManip stringResult = iExtractHistogram(3,3,4,4,0) listResult = ListManip.StringToList(stringResult) print "Pixel Value:Num of Occurrences" for count in xrange(len(listResult)): print count*16, "to", (count+1)*16 - 1, ":", listResult[count] Example 3 Assume we are using 16 bit monochrome. I am analysing the image in buffer 3. I have a camera that never uses pixel values greater than 10 bits. I want to use the 8 most significant bits of the 10 bits and ignore the upper 6 bits that were never used. Since I need to work with 8 bits, I set my index bits to 8. In order to get the most significant 8 bits of the 10 bits that the camera used, I shift 2 bits. To ignore the upper 6 bits of the total 16 bits that were never used I set the value of the class bits to 0. import ListManip stringResult = iExtractHistogram(3,3,8,2,0) listResult = ListManip.StringToList(stringResult) print "Pixel Value:Num of Occurrences" for count in xrange(len(listResult)): print count*4, "to", (count+1)*4 - 1, ":", listResult[count] iExtractProjectionCols Calculate the sums of pixel values along image columns (vertical lines). string iExtractProjectionCols(

42

Page 43: Video Savant Python function library - [email protected]

int sourceBufferStart, // image buffer sequence to int sourceBufferEnd // analyse

);

Parameters sourceBufferStart, sourceBufferEnd

The sequence sourceBufferStart..sourceBufferEnd buffers to analyse. Return Value

iExtractProjectionCols returns a string of numbers separated by commas representing the sums of pixel values along image columns for each column in the ROI. To convert this string into a list of integers, call the function "StringToList" (part of the ListManip module). Remarks For color pixels, the value of a pixel is calculated as the average value of the current pixel color planes as specified by iSetRGBPlaneUsage. The individual projections of each image buffer in the sourceBufferStart..sourceBufferEnd sequence are added together and stored in the resulting string. This operation is only performed on pixels in the current ROI. See Also iExtractProjectionRows Example I want to calculate the sum of all the pixels along image columns from images in buffers 3. import ListManip stringResult = iExtractProjectionCols(3,3) listResult = ListManip.StringToList(stringResult) print "Sum of columns are" for count in xrange(len(listResult)): print listResult[count] del listResult iExtractProjectionRows

43

Page 44: Video Savant Python function library - [email protected]

Calculate the sums of pixel values along image rows (horizontal lines). string iExtractProjectionRows(

int sourceBufferStart, // image buffer sequence to int sourceBufferEnd, // analyse

);

Parameters sourceBufferStart, sourceBufferEnd

The sequence sourceBufferStart..sourceBufferEnd buffers to analyse. Return Value iExtractProjectionRows returns a string of numbers separated by commas representing the sums of pixel values along image rows for each row in the ROI. To convert this string into a list of integers, call the function "StringToList" (part of the ListManip module). Remarks For color pixels, the value of a pixel is calculated as the average value of the current pixel color planes as specified by iSetRGBPlaneUsage. The individual projections of each image buffer in the sourceBufferStart..sourceBufferEnd sequence are added together and stored in the results array. This operation is only performed on pixels in the current ROI. See Also iExtractProjectionCols Example I want to calculate the sum of all the pixels along image rows from images in buffers 3. import ListManip stringResult = iExtractProjectionRows(3,3) listResult = ListManip.StringToList(stringResult) print "Sum of rows are" for count in xrange(len(listResult)): print listResult[count] del listResult

44

Page 45: Video Savant Python function library - [email protected]

iFill Write a constant value to each pixel in an image. int iFill(

int startBuf, // start buffer int endBuf, // end buffer int constantPixelValue, // constant to add to pixels optional int greenPixelValue, // green constant to add to pixels optional int bluePixelValue // blue constant to add to pixels

);

Parameters startBuf, endBuf

The sequence between startBuf and endBuf buffers will be filled with constantPixelValue.

constantPixelValue

The constant value to set all the pixels in the images in the sequence between sourceStartBuf and sourceEndBuf to. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be set to all pixels in all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be set to the corresponding pixels in the destination buffers

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. Examples Example 1 I want to set all the pixels in buffers 9,10,11,12 to the pixel value 128 vspython.iFill(9,12,128)

45

Page 46: Video Savant Python function library - [email protected]

Example 2 I want to set all the red, green, and blue pixels in buffers 9,10,11,12 to the pixel values 45, 55,and 65 respectively vspython.iFill(9,12,45,55,65) iFree Free memory used to allocate space for a storage block of data. void iFree(

int ptrStorage // location of the storage block of data )

Parameters ptrStorage

The location of the storage block of data. A call to iAlloc must be made prior to calling this function. The return value of iAlloc is ptrStorage.

Return Value None. See Also iAlloc, iReadBlock, iReadElement, iReadRGBBlock, iReadLine, iWriteBlock, iWriteElement, iWriteRGBBlock, iEnumExtractContours, iGetLinePoints, iTableTransform Example See examples for all the functions in the See Also section. iGetBufferSizeHorz Get the horizontal size of an image buffer, in pixels. int iGetBufferSizeHorz( );

46

Page 47: Video Savant Python function library - [email protected]

Parameters None.

Return Value The return value is the horizontal size of an image buffer, in pixels. Remarks All of the image buffers on a device have the same size.

This function is useful for determining the maximum dimensions of an image. See Also iGetBufferSizeVert Example I want the horizontal size of an image buffer, in pixels. hSize = vspython.iGetBufferSizeHorz() print "Horizontal size of buffers is: ",hSize iGetBufferSizeVert Get the vertical size of an image buffer, in pixels. int iGetBufferSizeVert( );

Parameters None. Return Value The return value is the vertical size of an image buffer in pixels. Remarks All of the image buffers on a device have the same size.

This function is useful for determining the maximum dimensions of an image.

47

Page 48: Video Savant Python function library - [email protected]

See Also iGetBufferSizeHorz Example I want the vertical size of an image buffer, in pixels. vSize = vspython.iGetBufferSizeVert() print "Vertical size of buffers is: ",vSize iGetDisplayBuffer Get the buffer number of the current buffer. If a sequence of buffers are selected, the buffer number of the first buffer will be returned. int iGetDisplayBuffer( );

Parameters None. Return Value The return value is the buffer number of the current buffer. If a sequence of buffers are selected, the buffer number of the first buffer will be returned. Example I want the buffer number of the current buffer. bufNum = vspython.iGetDisplayBuffer() print "The current display buffer is: ",bufNum iGetGraphicAttributes Sets the pen attributes used for drawing graphics with the iGraphic functions. list iGetGraphicAttributes( );

48

Page 49: Video Savant Python function library - [email protected]

Parameters None. Return Value This function returns a list with two elements. ELEMENT 1: An integer representing the current operation value. It can

be one of the following:

Value Meaning

iGRAPHICOP_SET Set the pixels to the constant pixel value

iGRAPHICOP_XOR Perform an exclusive OR operation between the constant pixel value and the current pixel value replacing the previous pixel value.

ELEMENT 2: An integer representing the current pen color. If color

images are being used, ELEMENT 2 will be a list containing the red, green, and blue pen colors.

Remarks Call iSetGraphicAttributes to set the current graphic attributes. See Also iSetGraphicAttributes Example I want to get the current pen color and current pen operation attr = vspython.iGetGraphicAttributes() print "Pen operation, Pen color",attr iGetLineLength Get the number of pixels located along a line in an image buffer. int iGetLineLength(

49

Page 50: Video Savant Python function library - [email protected]

int x1, // start point x coordinate int y1, // start point y coordinate int x2, // end point x coordinate int y2 // end point y coordinate

);

Parameters

x1, y1

The coordinates of the start point of the line.

x2, y2 The coordinates of the end point of the line.

Return Value The return value is the number of pixels located along the line. The return value is zero if no pixels on the line are in image buffer boundaries. Remarks This function can be used to determine the storage requirements before calling iReadLine to read and store the pixels located along a line. If no portion of the line is within the edges of an image buffer, no attempt should be made to read the line.

The line is clipped to the edges of an image buffer. This is done in the same manner as iReadLine, so that this function always returns an accurate count of the number of pixels available to be read in a line. See Also iReadLine Example

I want to get the length of a line starting at position (6,9) and finishing at position (300,406) Length = vspython.iGetLineLength(6,9,300,406) print "The length of the line is", Length iGetLinePoints Gets information about the pixels on a given line.

50

Page 51: Video Savant Python function library - [email protected]

int iGetLinePoints( int resultPtr, // pointer to location to store (x,y) coordinates int x1, // starting x-coordinate int y1, // starting y-coordinate int x2, // ending x-coordinate int y2 // ending y-coordinate

)

Parameters resultPtr Integer representing the location to store the (x,y) coordinates found on the line between (x1,y1) and (x2,y2). resultPtr must first be passed to iAlloc with iGetLineLength(x1,y1,x2,y2) as the size and iPIXTYPEPOINT as the pixel type to create the storage space needed. x1, y1, x2, y2 Coordinates of the end-points of the line. Return Value This function returns 1 if successful, and 0 otherwise. Remarks This function fills in the storage location indicated by resultPtr with the points on the line. To create a list of these (x,y) coordinates call CreateList (part of the ListManip module) with with iGetLineLength(x1,y1,x2,y2) as the size and iPIXTYPEPOINT as the pixel type. See Also iGetLineLength Example I want to get a list of the (x,y) coordinates found on the line between location (0,0) and (511,479) import ListManip Size = vspython.iGetLineLength(0,0,511,479) Results = vspython.iAlloc(Size,iPIXTYPEPOINT) vspython.iGetLinePoints(Results,0,0,511,479) listResult = ListManip.CreateList(Results, Size,iPIXTYPEPOINT) print "Coordinates found are:" for index in xrange(len(listResult)):

print listResult[index] vspython.iFree(Results)

51

Page 52: Video Savant Python function library - [email protected]

iGetNumBuffers Get the number of image buffers in a device. int iGetNumBuffers( );

Parameters None. Return Value A non-zero return value is the number of image buffers. The return value is zero if an error has occurred. Example I want to find out the number of buffers in a device bufs = vspython.iGetNumBuffers() print "Number of buffers is: ", bufs iGetPixelSize Get the number of storage bits per pixel color plane. int iGetPixelSize( );

Parameters None. Return Value If successful, returns the non-zero number of bits per pixel color plane. Returns zero if an error occurred. The number of bits per pixel for grayscale devices is either 8 or 16. For instance, if all bits are being acquired from a 10 bit camera, the returned value will be 16

52

Page 53: Video Savant Python function library - [email protected]

even though not all 16 bits contain data acquired from the camera. Remarks For non-color devices, the number of bits per pixel color plane is the same as the number of bits per pixel. Example I want to get the number of bits per color plane size = vspython.iGetPixelSize() print "Number of bits is: ", size iGetRGBPlaneUsage Determine which pixel color planes are currently used for image processing. list iGetRGBPlaneUsage( );

Parameters None. Return Value iGetRGBPlaneUsage returns a list with 3 elements ELEMENT 1: red color plane is included in image processing (1 TRUE, 0

FALSE) ELEMENT 2: green color plane is included in image processing (1 TRUE,

0 FALSE) ELEMENT 3: blue color plane is included in image processing (1 TRUE, 0

FALSE) Remarks This function is useful only for camera interfaces which store true color images.

Images on a true color camera interface are stored in red, green, and blue planes. Any combination of the above planes may be used, except none, when processing images. Processing one color plane has no effect on the other two color planes.

See Also

53

Page 54: Video Savant Python function library - [email protected]

iSetRGBPlaneUsage Example I want to get the RGB plane usage information usage = vspython.iGetRGBPlaneUsage() print "Red usage?, Green usage?, Blue usage? ", usage iGetROI Get information about the region-of-interest (ROI) used for image processing. list iGetROI( ); Parameters None. Return Value iGetROI returns a list with 3 elements. ELEMENT 1: topleftX, topleftY, width, height (for the Current ROI) ELEMENT 2: ignoreROIFlag -- iGetROI will return a zero value if the

current ROI coordinates are those specified in the previous call to iSetROI. A non-zero value will be returned if iIgnoreROI has been called to override the previous call to iSetROI

ELEMENT 3: topleftX, topleftY, width, height (for the Old ROI) Remarks The region-of-interest (ROI) is a rectangular area of the screen, used to limit image operations to the relevant portion of the screen. For example, an iFill operation will only fill the rectangle bounded by the current ROI. See Also iSetROI, iIgnoreROI, iShowROIOutline

Example I want to get the ROI information ROIInfo = vspython.iGetROI()

54

Page 55: Video Savant Python function library - [email protected]

print "Current ROI, Ignore Flag, Old ROI: ",ROIInfo iGetTextSize Determines the width and height (in pixels) of the bounding rectangle of a text graphic. list iGetTextSize(

int fontHeight, // Height of the font string typefaceName, // Typeface name string textStringToDraw // text string

)

Parameters fontHeight

The height of the font to set. Set this value to 0 to retrieve the size of a predefined, fixed pitch Windows font, "ANSI_FIXED_FONT".

typefaceName

The typeface name of the font to set. Set this value to NULL to use the predefined, fixed pitch Windows font, "ANSI_FIXED_FONT". A default size will also be used if you set this value to NULL.

textStringToDraw

The text which will be drawn. Return Value iGetTextSize returns 2 elements: ELEMENT 1: The height of textStringToDraw in pixels ELEMENT 2: The width of textStringToDraw in pixels Remarks iGetTextSize is used in conjunction with iGraphicText to position text, and/or ensure that text fits within the edges of an image buffer. See Also iGraphicText Example I want to get the height and width of the string "This is a test", with Courier typeface name and a font height of 12.

55

Page 56: Video Savant Python function library - [email protected]

size = vspython.iGetTextSize(12, "Courier", "This is a test") print "Height of text, Width of text: ", size iGrabContinuousStart

Perform continuous image capture with display. int iGrabContinuousStart(

int DestBuf, // Buffer to start live display on );

Parameters DestBuf

Continous image capture will be displayed, beginning with the buffer specified in DestBuf

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Start continuous capture with display, starting at buffer 7

vspython.iGrabContinuousStart(7) iGrabContinuousStop

Stop continuous image capture with display. int iGrabContinuousStop( );

Parameters None. Return Value A non-zero value is returned if the operation was successful. Zero is returned if

56

Page 57: Video Savant Python function library - [email protected]

an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Stop continuous capture.

vspython.iGrabContinuousStop() iGrabFrame

Perform single frame capture. int iGrabFrame(

int DestBuf, // Buffer to store acquired frame in );

Parameters DestBuf DestBuf contains the buffer to store the current image from the camera. Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Capture the current image from the camera and store it in buffer 14

vspython.iGrabFrame(14) iGraphicEllipse Draw an ellipse (or circle) graphic on the image using the current graphic attributes. void iGraphicEllipse(

int destStartBuf, // image start buffer for drawing graphics int destEndBuf, // image end buffer for drawing graphics int filledEllipse, // solid graphic drawing option int x1, int y1, // destination location of upper-left

// corner of bounding rectangle int x2, int y2 // destination location of lower-right

// corner of bounding rectangle

57

Page 58: Video Savant Python function library - [email protected]

)

Parameters destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the graphic.

filledEllipse

If this parameter is non-zero, a filled graphic is drawn; if it is zero, only the outline of the graphic is drawn.

x1, y1

The coordinates of the upper-left corner of the bounding rectangle in the destination image buffer(s).

x2, y2

The coordinates of the lower-right corner of the bounding rectangle in the destination image buffer(s).

Return Value None. Remarks This function uses the current drawing color and mode, as set by iSetGraphicAttributes.

The circle or ellipse will be drawn so that it is tangent with the four sides of the bounding rectangle. The apparent eccentricity of the graphic is affected by the aspect ratio of the display device.

The graphic is clipped to image buffer boundaries.

The current ROI is ignored. iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iSetGraphicAttributes Example I want to draw a black(pixel value 0) filled ellipse with top left corner at position (45,45) and bottom right corner at position (255,255) into buffers 9 and

58

Page 59: Video Savant Python function library - [email protected]

10 . vspython.iSetGraphicAttributes(iGRAPHICOP_SET,0) vspython.iGraphicEllipse(9,10,1,45,45,255,255) iGraphicLine Draw a line graphic on the image using the current graphic attributes. void iGraphicLine(

int destStartBuf, // starting image buffer for drawing graphics int destEndBuf, // ending image buffer for drawing graphics int x1, int y1, // destination location of starting

// point of line int x2, int y2 // destination location of ending

// point of line )

Parameters

destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the graphic.

x1, y1

The coordinates of the starting point of the line in the destination image buffer(s).

x2, y2

The coordinates of the ending point of the line in the destination image buffer(s).

Return Value None. Remarks The line is drawn in the current drawing color and mode, as set by iSetGraphicAttributes. The graphic is clipped to image buffer boundaries. The current ROI is ignored. iSetRGBPlaneUsage sets the color planes affected by this operation.

59

Page 60: Video Savant Python function library - [email protected]

See Also iSetGraphicAttributes Example I want to draw a red line from position (200,100) to position (300,150) onto buffers 9 and 10. NOTE: to get a red line on 16 bit monochrome, the value 255 should be replaced with 65535. vspython.iSetGraphicAttributes(iGRAPHICOP_SET,255,0,0) vspython.iGraphicLine(9,10,200,100,300,150) iGraphicRectangle Draw a rectangle graphic on the image using the current graphic attributes. void iGraphicRectangle(

int destStartBuf, // image start buffer for drawing graphics int destEndBuf, // image end buffer for drawing graphics int filledRectangle, // solid graphic drawing option int x1, int y1, // destination location of upper-left

// corner of bounding rectangle int x2, int y2 // destination location of lower-right

// corner of bounding rectangle )

Parameters destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the graphic.

filledRectangle

If this parameter is non-zero, a filled graphic is drawn; if it is zero, only the outline of the graphic is drawn.

x1, y1

The coordinates of the upper-left corner of the bounding rectangle in the destination image buffer(s).

x2, y2

The coordinates of the lower-right corner of the bounding rectangle in the destination image buffer(s).

60

Page 61: Video Savant Python function library - [email protected]

Return Value None Remarks The rectangle is drawn in the current drawing color and mode, as set by iSetGraphicAttributes.

The graphic is clipped to image buffer boundaries.

The current ROI is ignored.

iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iSetGraphicAttributes Example I want to draw a green rectangle outline with top left position (200,100) and bottom right position (300,150) onto buffers 9 and 10. NOTE: to get a green rectangle on 16 bit monochrome, the value 255 should be replaced with 65535. vspython.iSetGraphicAttributes(iGRAPHICOP_SET,0,255,0) vspython.iGraphicRectangle(9,10,0,200,100,300,150) iGraphicText Draw a text graphic on the image using the current graphic attributes. int iGraphicText(

int destStartBuf, // image start buffer for drawing graphics int destEndBuf, // image end buffer for drawing graphics int fontHeight, // Height of the font string typefaceName, // Typeface name string textStringToDraw , // text string int xpos, int ypos // location of upper-left corner of the

// bounding rectangle of the text )

Parameters destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place

61

Page 62: Video Savant Python function library - [email protected]

the graphic.

fontHeight The height of the font to set. Set this value to 0 to retrieve the size of a predefined, fixed pitch Windows font, "ANSI_FIXED_FONT".

typefaceName

The typeface name of the font to set. Set this value to NULL to use the predefined, fixed pitch Windows font, "ANSI_FIXED_FONT". A default size will also be used if you set this value to NULL.

textStringToDraw

The text which will be drawn.

xpos, ypos The coordinates of the upper-left corner of the bounding rectangle of the text. The size of this rectangle can be determined with iGetTextSize.

Return Value The return value will be non-zero if the text was drawn successfully. If it is zero, the text was not drawn, most likely because of a lack of memory for internal processing. Remarks The text is drawn in the current drawing color and mode, as set by iSetGraphicAttributes. The graphic is clipped to image buffer boundaries. The current ROI is ignored.

iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iSetGraphicAttributes, iGetTextSize

Example

I want to write the text "Video Savant" using typeface "Courier" with a font height of 20. The white (pixel value 255) colored text is to be written starting at position (200,0) into buffers 9 and 10. NOTE: to get white text on 16 bit monochrome, the value 255 should be replaced with 65535. vspython.iSetGraphicAttributes(iGRAPHICOP_SET,255)

62

Page 63: Video Savant Python function library - [email protected]

vspython.iGraphicText(9,10,20, "Courier", "Video Savant",200,0) iIgnoreROI Set the active ROI either to the full image buffer size or to the previous value as set by the previous call to iSetROI. void iIgnoreROI(

int ignoreState // flag to ignore current ROI )

Parameters

ignoreState

Set to a non-zero value if the true ROI should be ignored, and zero if it should be used.

Return Value None. Remarks The region-of-interest (ROI) is a rectangular area of an image buffer, used to limit image operations to a sub-area of an image. For example, an iFill operation would only fill the rectangle bounded by the current ROI; but by calling iIgnoreROI, the entire image buffer can be filled by temporarily overriding the previously set ROI. See Also iGetROI, iSetROI Example

I want to ignore the current region of interest setting (which has a top left corner (25,45) with a width of 70 pixels and a height of 65 pixels) and fill the entire buffer 11 with the pixel value 255.

vspython.iSetROI(25,45,70,65) vspython.iIgnoreROI(1) vspython.iFill(11,11,255) iImportFile

63

Page 64: Video Savant Python function library - [email protected]

Read image(s) from an image file into an image buffer. int iImportFile(

string Filename, // name of image file to read string FileType, // type of image file to read int destStartBuf, // first buffer in destination to store image(s) string buffersToImport, // buffers to import from the image file int Erase // flag to erase image buffer background

)

Parameters Filename

The complete file path of the image file to be read.

FileType Sets the image file type to be read. File types include AVI, BMP, TIFF, JPEG, RAW, etc.

destStartBuf

All of the buffers specified in buffersToImport will be loaded into the Video Savant buffers starting at destStartBuf and continuing with the next buffers in sequence until all of the buffers in buffersToImport have been imported.

buffersToImport

The buffers to read in from the file. Each buffer in the string is separated by a comma, and each buffer in the string must be greater than the previous one. This string can be set to NULL or the empty string if only one image is being imported.

Erase

If set to a non-zero value, the pixels in the ROI of the destination image buffer will be set to zero before the image is read from the file. Otherwise, no erasing is done.

Return Value The return value is non-zero if an image was read from the file. Otherwise zero is returned, indicating an error occurred. Remarks To import an image of type "RAW", the function iSetRAWImportSettings should called to give specific information about the RAW image file. This operation is only performed on pixels in the current ROI.

64

Page 65: Video Savant Python function library - [email protected]

iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iSetRAWImportSettings, iExportFile Example

I want to read in buffers 0, 3, and 7 from the TIFF image file "C:\test\100.tif" and store them in buffers 9,10, and 11. I want to clear buffers 9, 10, and 11 before importing the new images. vspython.iImportFile("C:\\test\\100.tif", "TIFF", 9, "0,3,7", 1) iIsROIVisible Determine if the ROI outline is currently visible on the display. int iIsROIVisible( )

Parameters None. Return Value The return value is non-zero if the ROI is currently outlined, and zero if it isn't. Remarks The ROI outline is shown when iShowROIOutline is called. The ROI outline is never shown in thumbnail mode. See Also iShowROIOutline, iSetROI, iGetROI

Example

I want to determine whether or not the region of interest is currently visible.

check = vspython.iIsROIVisible() if check == 0:

65

Page 66: Video Savant Python function library - [email protected]

print "Region of interest is not visible" else: print "Region of interest is visible" iMax Calculate the maximum of two images, on a pixel by pixel basis, to form a third image. int iMax(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is compared with the sequence between source2StartBuf and source2EndBuf buffers on a pixel by pixel basis to calculate the maximum of the images.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks

The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Example I want to find the maximum of images 2 and 4 and then store the result in buffer 9. Also I want to calculate the maximum of images 3 and 5 and then store

66

Page 67: Video Savant Python function library - [email protected]

the result in buffer 10. vspython.iMax(2,3,4,5,9,10) iMin Calculate the minimum of two images, on a pixel by pixel basis, to form a third image. int iMin(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is compared with the sequence between source2StartBuf and source2EndBuf buffers on a pixel by pixel basis to calculate the minimum of the images.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Example I want to find the minimum of images 2 and 5, images 3 and 5, and images 4 and 5 and then store the results in buffers 9,10, and 11.

67

Page 68: Video Savant Python function library - [email protected]

vspython.iMin(2,4,5,5,9,11) iMorphOperation Perform one of five image morphology operations. int iMorphOperation(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int Operation // morphology operation to perform

)

Parameters sourceStartBuf, sourceEndBuf

sourceStartBuf..sourceEndBuf is the sequence containing image buffers to process.

destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the results.

Operation

The morphological transformation to be performed. The possible transformations are performed by setting the following constants:

Value Meaning iMORPH_BOUND Morphology boundary iMORPH_ERODE Morphology erosion iMORPH_DILATE Morphology dilation iMORPH_OPEN Morphology open iMORPH_CLOSE Morphology close

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

68

Page 69: Video Savant Python function library - [email protected]

Remarks The morphology operators are 3x3 pixel masks.

The image buffers do not have to be unique.

This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. Example I want to perform the Morphology erosion operation on buffers 3 and 4 and store the results in buffers 9 and 10. vspython.iMorphOperation(3,4,9,10, iMORPH_ERODE) iMulDiv Multiply two images by a fractional constant to produce a third image. int iMulDiv(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constNumerator, // numerator of constant multiplier int constDenominator // denominator of constant multiplier

)

Parameters sourceStartBuf, sourceEndBuf

sourceStartBuf..sourceEndBuf is the sequence containing image buffers to process.

destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers for placing results.

constNumerator

The numerator of the constant value to multiply the pixels in the source buffers by.

constDenominator

The denominator of the constant value to divide the pixels in the source

69

Page 70: Video Savant Python function library - [email protected]

buffers by. Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers do not have to be unique.

This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. The multiplication is always performed first, and then the division. This gives a more accurate result when multiplying by 2/3 (for example), since this function uses integer arithmetic. If the final result would exceed (2pixel size - 1), it is set to (2pixel size - 1). See Also iShiftBits Example I want to multiply all the pixels in buffers 3 and 4 by 2/5 and store the result in buffers 9 and 10. vspython.iMulDiv(3,4,9,10,2,5) iMultiply Multiply two images to form a third image. int iMultiply(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters

70

Page 71: Video Savant Python function library - [email protected]

source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf The sequence between source1StartBuf and source1EndBuf buffers is multiplied together with the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. If the product of two corresponding pixels from source1StartBuf..source1EndBuf and source2StartBuf..source2EndBuf would be greater than (2pixel size - 1), the destination pixel is set to (2pixel size - 1). Example I want to multiply all the pixels in buffers 3 and 4 by the pixels in buffer 9 and store the result in buffers 10 and 11. vspython.iMultiply(3,4,9,9,10,11) iNegate Perform a 2's-complement negation on an image to form a second image. int iNegate(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

)

71

Page 72: Video Savant Python function library - [email protected]

Parameters sourceStartBuf, sourceEndBuf

sourceStartBuf..sourceEndBuf is the sequence containing image buffers to process with negate operation.

destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks

The image buffers do not have to be unique.

This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation.

This is equivalent to performing a bitwise NOT (see iNOT) and then incrementing each result by 1. Example I want to negate the values in buffers 3 and 4 and store the results in buffers 9 and 10. vspython.iNegate(3,4,9,10) iNOT Perform a bitwise NOT of an image to form a second image. int iNOT(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

)

72

Page 73: Video Savant Python function library - [email protected]

Parameters sourceStartBuf, sourceEndBuf

sourceStartBuf..sourceEndBuf is the sequence containing image buffers to process with NOT operation.

destStartBuf, destEndBuf

destStartBuf..destEndBuf is the sequence containing image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The image buffers in (sSrc and sDest) do not have to be unique.

This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise NOT examines the pixel values in the source bit-by-bit, and sets the destination pixel bits according to this table: Source1 Destination NOT 0 = 1 NOT 1 = 0 Example I want to perform a bitwise NOT of buffers 3 and 4 and store the result in buffers 9 and 10 vspython.iNOT(3,4,9,10) iObjectCenter Extract object information about the center of an object from iEnumCountObjects list iObjectCenter( int center // location of the center of the object );

73

Page 74: Video Savant Python function library - [email protected]

Parameters center

Location of the object information for the center of the object. center is obtained from the Callback function to iEnumCountObjects.

Return Value iObjectCenter returns a list with 2 elements: ELEMENT 1: x coordinate of the center of the object ELEMENT 2: y coordinate of the center of the object See Also iEnumCountObjects, iObjectRectangle, iObjectCentroid Example See Example from iEnumCountObjects iObjectCentroid Extract object information about the centroid axes of an object from iEnumCountObjects list iObjectCentroid(

int centroid // location of the information regarding the // object's centriod axes

); Parameters centroid

Location of the object information for the centroid axes of the object. centroid is obtained from the Callback function to iEnumCountObjects.

Return Value iObjectCentroid returns a list with 2 elements: ELEMENT 1: list representing the major axes of the centroid of the object.

The list contains two (x,y) coordinates which represents the start and end points of the major axes of the centroid. ((x1,y1),(x2,y2))

ELEMENT 2: list representing the minor axes of the centroid of the object.

74

Page 75: Video Savant Python function library - [email protected]

The list contains two (x,y) coordinates which represents the start and end points of the minor axes of the centroid. ((x1,y1),(x2,y2))

See Also iEnumCountObjects, iObjectRectangle, iObjectCenter Example See Example from iEnumCountObjects iObjectRectangle

Extract object information about the bounding rectangle of an object from iEnumCountObjects list iObjectRectangle( int rectangle // location of the bounding rectangle of the object ); Parameters rectangle

Location of the object information for the bounding rectangle of the object. rectangle is obtained from the Callback function to iEnumCountObjects.

Return Value iObjectRectangle returns a list with 4 elements: ELEMENT 1: left x coordinate of the bounding rectangle of the object ELEMENT 2: top y coordinate of the bounding rectangle of the object ELEMENT 3: right x coordinate of the bounding rectangle of the object ELEMENT 4: bottom y coordinate of the bounding rectangle of the object See Also iEnumCountObjects, iObjectRectangle, iObjectCentroid Example See Example from iEnumCountObjects iOR

75

Page 76: Video Savant Python function library - [email protected]

Perform a bitwise OR between two images to form a third image. int iOR(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters

source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is ORed together with the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks

The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise OR examines the pixel values in the sources bit-by-bit, and sets the bits in the destination value according to this table: Source1 Source 2 Destination 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1 Example I want to perform a bitwise OR between images 3 and 5 and images 4 and 5 and store the result in buffers 9 and 10

76

Page 77: Video Savant Python function library - [email protected]

vspython.iOR(3,4,5,5,9,10) iORConstant Perform a bitwise OR between an image and a constant value to form a second image. int iORConstant(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constantPixelValue, // constant to OR with pixels optional int greenPixelValue, // green constant to OR with pixels optional int bluePixelValue // blue constant to OR with pixels

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will be ORed with the constant value.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

constantPixelValue

The constant value to OR with the pixels in the images in the sequence between sourceStartBuf and sourceEndBuf. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be ORed with all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be ORed with the corresponding color in the source buffers.

Return Value The return value is non-zero if successful, and zero if an error occurred.

Remarks

77

Page 78: Video Savant Python function library - [email protected]

The image buffers do not have to be unique.

This operation is only performed on pixels in the current ROI.

iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise OR examines the pixel values in the source and the constant value bit-by-bit, and sets the destination pixel bits according to this table: Source Constant Destination 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1 Examples Example 1

ORing the constant(50) to the images in the sequence 2,3 and storing the result in buffers 7,8. vspython.iORConstant(2,3,7,8,50) Example 2 ORing the constant(128) to the red pixel values, constant(255) to the green pixel values, and constant(0) to the blue pixel values of the image in buffer 2. The result will be stored in buffer 7. vspython.iORConstant(2,2,7,7,128,255,0) iPlay

Display an image buffer, or playback a sequence of image buffers on the display device. int iPlay(

int StartBuf, // Buffer to start playing on int NumberOfFrames, // Number of frames to play string ElapsedTime, // Length of time to play for int LastBuf, // Play until last buffer? int method, // Method of playing int MethodValue // value of the playing method

);

78

Page 79: Video Savant Python function library - [email protected]

Parameters StartBuf

Playing will start on this buffer. NumberOfFrames

Playing will stop after NumberOfFrames images have been played or if one of the other stopping conditions has been met. (see ElapsedTime and LastBuf) NumberOfFrames will be ignored if set to 0.

ElapsedTime

Elapsed time is a string containing the hours, minutes, and seconds (separated by colons). Playing will stop after the Elapsed Time is up or if one of the other stopping conditions has been met. (see NumberOfFrames and LastBuf) If only minutes and seconds are given, hours will be assumed to be zero; if only seconds are given, hours and minutes will be assumed to be zero. Elapsed time is ignored if set to the empty string.

LastBuf

If LastBuf is set to one, playing will stop after the last buffer has been played or if one of the other stopping conditions has been met. (see NumberOfFrames and ElapsedTime) If LastBuf is set to zero, LastBuf is ignored.

method

The type of playing to be done. Set to one of the following constants:

Value Meaning MAX_SPEED Play images at maximum speed. MethodValue is

ignored if MAX_SPEED is set. FRAME_SKIP Skip playing frames at a regular interval. To skip n

frames out of n+1 frames, set MethodValue to n. FRAME_RATE Specify a frame rate. Use MethodValue to specify the

frame rate you want. FRAME_DELAY Wait a designated period of time before playing the next

image. The value (in milliseconds) is set in MethodValue

MethodValue

Please read the description of method above to determine what to set MethodValue to.

79

Page 80: Video Savant Python function library - [email protected]

Return Value The return value is non-zero if successful. It is zero if an error occurred. Example

Start playing in buffer 0. Stop playing after 30 seconds have passed, or the last buffer has been played. (whichever occurs first). Wait 2000 milliseconds (2 seconds) between playing images.

vspython.iPlay(0,0,"0:0:30",1,FRAME_DELAY,2000) iPlayUntilElapsedTime

Playback a sequence of image buffers for a specified amount of time. int iPlayUntilElapsedTime(

int StartBuf, // Buffer to start playing on string ElapsedTime // Length of time to play for

);

Parameters StartBuf

Playing will start on this buffer. ElapsedTime

Elapsed time is a string containing the hours, minutes, and seconds (separated by colons). Playing will stop after the Elapsed Time is up, or if the last buffer is reached (whichever occurs first). If only minutes and seconds are given, hours will be assumed to be zero; if only seconds are given, hours and minutes will be assumed to be zero.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred.

Example

Start playing in buffer 5. Stop playing after 1 minute and 45 seconds have passed, or when we have played the last buffer. vspython.iPlayUntilElapsedTime(5,"0:1:45") iPlayUntilLastStorageBuffer

80

Page 81: Video Savant Python function library - [email protected]

Playback a sequence of image buffers until the last buffer has been played. int iPlayUntilLastStorageBuffer(

int StartBuf // Buffer to start image playing on );

Parameters StartBuf

Image playing will begin on the image buffer specified in StartBuf and will end on the last image buffer in Video Savant.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred.

Example

Play images from buffer 8 to the last buffer

vspython.iPlayUntilLastStorageBuffer(8) iPlayUntilNumberOfFrames

Playback a sequence of image buffers until a specified number of images have been played. int iPlayUntilNumberOfFrames(

int StartBuf, // Buffer to start playing on int NumberOfFrames // Number of frames to play

);

Parameters StartBuf

Playing will start on this buffer. NumberOfFrames

Playing will stop after NumberOfFrames images have been played, or when the last buffer has been played (whichever occurs first).

81

Page 82: Video Savant Python function library - [email protected]

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred.

Example

Start playing in buffer 24. Stop playing after 10 images have been played, or after the last buffer has been played.

vspython.iPlayUntilNumberOfFrames(24,10) iReadBlock Read a block of pixels in an image buffer window. int iReadBlock(

int sourceBuf, // source buffer int pixelType, // pixel type int xpos, // top-left x-coordinate of image window

// to be read int ypos, // top-left y-coordinate of image window // to be read int width, // width of image window to be read int height, // height of image window to be read int ptrStorage // integer representing storage location to store

// data

)

Parameters sourceBuf

Read data from this buffer.

pixelType The type of pixel data to be placed in the storage location referred to by ptrStorage. The possible types are:

Value Meaning iPIXTYPE8 Stores pixels as 8 bit gray scale values. For

color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Stores pixels as 16 bit gray scale values. For 8

82

Page 83: Video Savant Python function library - [email protected]

bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Stores pixels as three 8 bit values in the order:

red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Stores pixels as 8 bit gray scale values on 8 bit

devices (including 24 bit color devices). Stores pixels as 16 bit gray scale values on 16 bit devices.

xpos, ypos

The upper-left hand corner of the rectangle to read data from.

width, height The width and height of the rectangle of data to read.

ptrStorage

ptrStorage represents the location of the storage space for the iReadBlock information. ptrStorage must first be passed to iAlloc with width*height as the size and pixelType as the pixel type to create the storage space needed to store the result from iReadBlock

Return Value The return value is non-zero if the data has been successfully read. It is zero if an error occurred. Remarks This function fills in the storage location indicated by ptrStorage with the block of pixel values found in sourceBuf. To create a list of these pixel values call CreateList (part of the ListManip module) with width*height as the size and pixelType as the pixel type. iSetRGBPlaneUsage is used to set which color planes are averaged if pixels on a color device are to be stored as 8 bit gray scale or 16 bit gray scale values. See Also iWriteBlock, iReadRGBBlock, iSetRGBPlaneUsage Example I want to get all the pixel values from the rectangular area in buffer 3

83

Page 84: Video Savant Python function library - [email protected]

starting at position (0,0) with a width of 100 pixels and a height of 20 pixels. I am using 8 bit monochrome. import ListManip Size = 100*20 result = vspython.iAlloc(Size,iPIXTYPE8) vspython.iReadBlock(3,iPIXTYPE8,0,0,100,20,result) pixelList = ListManip.CreateList(result, Size, iPIXTYPE8) print "Pixel values found" for count in xrange(Size): print pixelList[count] vspython.iFree(result) iReadElement Get the value stored at a particular index of a storage block of data. [int or list] iReadElement(

int ptrStorage, // integer representing storage location of stored // data

int index, // index of ptrStorage to access int pixelType // pixel type

)

Parameters ptrStorage

ptrStorage represents the location of the storage block of data. ptrStorage must first have been passed to iAlloc with the appropriate size (see iAlloc for more information) and pixelType as the pixel type.

index

The index of ptrStorage to access. The first index is always at position 0 and index must be a valid index.

pixelType

The type of data located in the storage location referred to by ptrStorage. The possible types are:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

84

Page 85: Video Savant Python function library - [email protected]

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

iPIXTYPEPOINT Data is stored as (x,y) coordinate pairs.

iPIXTYPECONTOURS Data is stored as contour values.

Return Value The return value is an integer if the pixelType is not iPIXTYPEPOINT. This integer represents the value located at index in ptrStorage. If the pixelType is iPIXTYPEPOINT, the return value is a list with two elements. These elements are the x and y coordinates of an (x,y) pair. See Also iReadBlock, iWriteBlock, iReadRGBBlock Example I want to get the pixel value from the 4th index in the storage block of data. import ListManip Size = 100*20 result = vspython.iAlloc(Size,iPIXTYPE8) vspython.iReadBlock(3,iPIXTYPE8,0,0,100,20,result) value = vspython.iReadElement(result, 4, iPIXTYPE8) print "Pixel value found is: ", value vspython.iFree(result) iReadLine Reads pixels located along a line in an image buffer.

85

Page 86: Video Savant Python function library - [email protected]

int iReadLine(

int sourceBuf, // image for reading line int x1, // x coordinate of first point on line int y1, // y coordinate of first point on line int x2, // x coordinate of last point on line int y2, // y coordinate of last point on line int pixelType, // image pixel type int ptrStorage // storage location for pixels

)

Parameters.

sourceBuf

The image buffer for reading the line.

x1, y1 The coordinates of the starting point of the line.

x2, y2

The coordinates of the ending point of the line.

pixelType The type of pixel data to be placed in the location referred to by ptrStorage.

ptrStorage

ptrStorage represents the location of the storage space for the iReadLine information. This location will contain the pixel values for the points found on the line specified. ptrStorage must first be passed to iAlloc with iGetLineLength(x1,y1,x2,y2) as the size and pixelType as the pixel type to create the storage space needed to store the result from iReadLine.

Return Value The return value is non-zero if the data has been successfully read. It is zero if an error occurred. Remarks This function fills in the storage location indicated by ptrStorage with the block of pixel values found in sourceBuf. To create a list of these pixel values call CreateList (part of the ListManip module) with iGetLineLength(x1,y1,x2,y2) as the size and pixelType as the pixel type. No pixels are read at pixel positions located outside image buffer boundaries.

For camera interfaces which store true color images, iReadLine returns an

86

Page 87: Video Savant Python function library - [email protected]

average of the red, green and blue pixels in the location referred to by ptrStorage. iSetRGBPlaneUsage is used to set which color planes are averaged. See Also

iReadPixel, iWritePixel, iGetLineLength Example I want to get all the pixel values along the line starting at position (0,0) and ending at position (511,479) of buffer 3. Since this is a color image, 3 pixel values (Red,Green,Blue) are returned for each point on the line. import ListManip Size = vspython.iGetLineLength(0,0,511,479) result = vspython.iAlloc(Size, iPIXTYPERGB) vspython.iReadLine(3,0,0,511,479,iPIXTYPERGB,result) pixelList = ListManip.CreateList(result, Size, iPIXTYPERGB) print "The pixel values found on the line are: " for count in xrange(len(pixelList)/3):

print "Red pixel value: ", pixelList[count*3] print "Green pixel value: ", pixelList[count*3 + 1] print "Blue pixel value: ", pixelList[count*3 + 2]

vspython.iFree(result) iReadPixel Read a single pixel in an image buffer. [int or list] iReadPixel(

int sourceBuf, // image buffer for reading pixel int xpos, // x coordinate of pixel in image int ypos // y coordinate of pixel in image

)

Parameters sourceBuf

The pixel will be read from this buffer. xpos, ypos

The coordinates of the pixel to read. Return Value

87

Page 88: Video Savant Python function library - [email protected]

The return value is the value of the pixel read. If the pixel is part of a color image, iReadPixel will return a list with 3 elements which contains the red, green, and blue pixels values of the pixel read. Otherwise, if the pixel is part of a gray scale image, the single integer pixel value will be returned.

Remarks If multiple pixels are being read, this function can become extremely inefficient. In many cases, the functions iReadBlock (which reads a rectangular block of pixels) or iReadLine (which reads all pixels along a given line), are much more efficient. See Also iReadBlock, iReadLine Example

I want to get the pixel value found at location (45,45) of image buffer 3.

value = vspython.iReadPixel(3,45,45) print "Pixel value is: ", value iReadRGBBlock Read the red, green and/or blue color components of a block of pixels in an image buffer window. int iReadRGBBlock(

int sourceBuf, // image for reading block of pixels int xpos, // top-left x-coordinate of image window int ypos, // top-left y-coordinate of image window

// to be read

// to be read int width, // width of image window to be read int height, // height of image window to be read int ptrRedStorage, // integer representing storage location to store

// red values int ptrGreenStorage, // integer representing storage location to store

// green values int ptrBlueStorage // integer representing storage location to store

// blue values ) Parameters

88

Page 89: Video Savant Python function library - [email protected]

sourceBuf Read data from this image buffer.

xpos, ypos

The upper-left hand corner of the image window to be read. width, height

The width and height of the image window to be read. ptrRedStorage, ptrGreenStorage, ptrBlueStorage

ptrRedStorage represents the location of the storage space for the iReadRGBBlock red pixel value information. ptrRedStorage must first be passed to iAlloc with width*height as the size and iPIXTYPE8 as the pixel type to create the storage space needed to store the red pixel value result from iReadRGBBlock. ptrGreenStorage and ptrBlueStorage are indentically defined as ptrRedStorage except for the green and blue pixels.

Return Value The return value is non-zero if the data has been successfully read. It is zero if an error occurred. Remarks Pass ptrRedStorage, ptrGreenStorage, and ptrBlueStorage to the python function CreateList (in the ListManip module) with a size of width*height and a pixel type of iPIXTYPE8 to access the lists containing the pixel values read in from the buffer. An application normally uses this function when reading true color image data from a true color camera interface. However, an application can call this function if a gray scale device is used. For a gray scale device, the pixel value is replicated in the red, green and blue host memory buffers. For 16 bit gray scale devices, only the high-order pixel bytes are stored in the host memory buffers.

iReadBlock can be used to return an average of the color planes set by iSetRGBPlaneUsage in a single host memory buffer.

See the comments following iReadBlock. See Also iWriteRGBBlock, iReadBlock, iSetRGBPlaneUsage

89

Page 90: Video Savant Python function library - [email protected]

Example I want to get all the color pixel values from the rectangular area in buffer 3 starting at position (0,0) with a width of 5 pixels and a height of 6 pixels. import ListManip Size = 5*6 RedStorage = vspython.iAlloc(Size, iPIXTYPE8) GreenStorage = vspython.iAlloc(Size, iPIXTYPE8) BlueStorage = vspython.iAlloc(Size, iPIXTYPE8) vspython.iReadRGBBlock(3,0,0,5,6,RedStorage,GreenStorage,BlueStorage) RedList = ListManip.CreateList(RedStorage, Size, iPIXTYPE8) GreenList = ListManip.CreateList(GreenStorage, Size, iPIXTYPE8) BlueList = ListManip.CreateList(BlueStorage, Size, iPIXTYPE8) print "Red pixel values" for count in xrange(len(RedList)): print RedList[count] print "Green pixel values" for count in xrange(len(GreenList)): print GreenList[count] print "Blue pixel values" for count in xrange(len(BlueList)): print BlueList[count] vspython.iFree(RedStorage) vspython.iFree(GreenStorage) vspython.iFree(BlueStorage) del RedList del GreenList del BlueList iRecord

Perform single frame capture or image sequence capture. int iRecord(

int startBuf, // Buffer to start recording on int numberOfFrames, // Number of frames to record string elapsedTime, // Length of time to record for int lastBuf, // Record until last buffer? int method, // Method of recording int methodValue, // value of the recording method int options, // Sequence capture options optional int preTrigger, // Pre trigger buffer selection optional int preTriggerCount, // Size of the pre trigger buffer optional int startTrigger, // Start trigger settings optional int endTrigger, // End trigger settings optional int repeated, // Repeat sequence capture

90

Page 91: Video Savant Python function library - [email protected]

optional int triggerType, // Type of triggering to use optional string triggerKey // The triggering key

);

Parameters startBuf

Recording will start on this buffer. numberOfFrames

Recording will stop after NumberOfFrames images have been recorded or if one of the other stopping conditions has been met. (see ElapsedTime and LastBuf) NumberOfFrames will be ignored if set to 0.

elapsedTime

elapsedTime is a string containing the hours, minutes, and seconds (separated by colons). Recording will stop after the elapsed time is up or if one of the other stopping conditions has been met. (see numberOfFrames and lastBuf) If only minutes and seconds are given, hours will be assumed to be zero; if only seconds are given, hours and minutes will be assumed to be zero. elapsedTime is ignored if set to the empty string.

lastBuf

If lastBuf is set to one, recording will stop after the last buffer has been recorded or if one of the other stopping conditions has been met. (see numberOfFrames and elapsedTime) If lastBuf is set to zero, lastBuf is ignored.

method

The type of recording to be done. Set to one of the following constants:

Value Meaning MAX_SPEED Acquire images at maximum speed. methodValue is

ignored if MAX_SPEED is set. FRAME_SKIP Skip recording frames at a regular interval. To skip n

frames out of n+1 frames, set methodValue to n. FRAME_RATE Specify a frame rate. Use methodValue to specify the

frame rate you want. FRAME_DELAY Wait a designated period of time before capturing the

next image. The value (in milliseconds) is set in methodValue.

TRIGGER Use a trigger to start/stop recording. methodValue is not

used for triggering. It will be ignored.

91

Page 92: Video Savant Python function library - [email protected]

methodValue Please read the description of method above to determine what to set methodValue to.

options

Sequence capture options. Can be any bitwise Ored combination of the following:

Value Meaning iACQUIRESEQUENCE_OPTION_FILTERALL All frames captured are to be processed by the stream

filters, even the ones that are discarded when a FRAME_SKIP is set.

NOTE: All of the remaining parameters are optional. These parameters only need to be set if method is set to TRIGGER. The triggerKey parameter only needs to be set if triggerType is set to iREC_TRIGGERTYPE_KEYBOARD.

preTrigger

Pre-trigger buffer options. This parameter must be set to one of the following: Value Meaning

iREC_TRIGGERPRENONE No pre-triggering is done

iREC_TRIGGERPREORDERED Pre-triggering is done and the frames are reordered

after capture

iREC_TRIGGERPREUNORDERED Pre-triggering is done but the frames are not reordered after capture

preTriggerCount

This is the size of the pre-trigger circular buffer that will be used. Images will be captured into this buffer continuously until a trigger is received to start the capture process. This is a circular buffer so only the preTriggerCount images directly before the trigger to start capture will be contained in the image buffers. Any frames before those will have been overwritten.

startTrigger

The starting trigger options. This parameter must be set to one of the following: Value Meaning

iREC_TRIGGERONNONE No starting trigger. Begin recording immediately

iREC_TRIGGERONRISING Start recording on rising edge of trigger specified in

triggerType.

92

Page 93: Video Savant Python function library - [email protected]

iREC_TRIGGERONFALLING Start recording on falling edge of trigger specified in

triggerType

endTrigger The stopping trigger options. This parameter must be set to one of the following: Value Meaning

iREC_TRIGGERONNONE No stopping trigger. Continue recording until some

other stopping condition is met

iREC_TRIGGERONRISING Stop recording on rising edge of trigger specified in triggerType

iREC_TRIGGERONFALLING Stop recording on falling edge of trigger specified in

triggerType

iREC_TRIGGERONONEBUFFER Stop recording after one frame of video has been captured

fRepeated

If this field is set to non-zero then the sequence capture is repeated over and over again until a stopping condition other than the one specified in endTrigger is met. Combine this option with endTrigger set to iREC_TRIGGERONONEBUFFER to trigger every frame.

triggerType

The trigger type options. This parameter must be set to one of the following

Value Meaning

iREC_TRIGGERTYPE_PARALLELPORT Trigger through the parallel port

iREC_TRIGGERTYPE_FRAMEGRABBER

Trigger through the frame grabber

iREC_TRIGGERTYPE_KEYBOARD Trigger through the keyboard

triggerKey If triggerType is set to iREC_TRIGGERTYPE_KEYBOARD, the keyboard key to be used as the trigger should be set here. If you are using a keyboard trigger, you must set this value to one of the following text strings:

Value Meaning

"F1" Use the F1 key as the triggering key "F2" Use the F2 key as the triggering key "F3" Use the F3 key as the triggering key

93

Page 94: Video Savant Python function library - [email protected]

"F4" Use the F4 key as the triggering key "F5" Use the F5 key as the triggering key "F6" Use the F6 key as the triggering key "F7" Use the F7 key as the triggering key "F8" Use the F8 key as the triggering key "F9" Use the F9 key as the triggering key "SPACE" Use the Spacebar as the triggering key "ESC" Use the Esc key as the triggering key

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example #1 Start recording in buffer 0. Stop recording after 15 images have been captured, or 45 seconds have passed, or the last buffer has been recorded. (whichever occurs first). Record at maximum speed.

vspython.iRecord(0,15,"0:0:45",1,MAX_SPEED,0,0) Example #2 Start recording in buffer 7 after the keyboard trigger "F3" has been pressed. Continue recording until "F3" has been pressed again or until the last buffer has been reached. vspython.iRecord(7,0,"",1,TRIGGER,0,0,iREC_TRIGGERPRENONE,0,iREC_TRIGGERONRISING,iREC_TRIGGERONRISING,0,iREC_TRIGGERTYPE_KEYBOARD,"F3") iRecordUntilElapsedTime

Perform image sequence capture for a specified amount of time. int iRecordUntilElapsedTime(

int StartBuf, // Buffer to start recording on string ElapsedTime, // Length of time to record for

);

Parameters StartBuf

Recording will start on this buffer. ElapsedTime

94

Page 95: Video Savant Python function library - [email protected]

Elapsed time is a string containing the hours, minutes, and seconds (separated by colons). Recording will stop after the Elapsed Time is up, or if the last buffer is reached (whichever occurs first). If only minutes and seconds are given, hours will be assumed to be zero; if only seconds are given, hours and minutes will be assumed to be zero.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Start recording in buffer 5. Stop recording after 1 minute and 45 seconds have passed, or when we have reached the last buffer.

vspython.iRecordUntilElapsedTime(5,"0:1:45") iRecordUntilLastStorageBuffer

Perform image sequence capture until the last buffer has been reached. int iRecordUntilLastStorageBuffer(

int StartBuf, // Buffer to start image capturing on );

Parameters StartBuf

Image capturing will begin on the image buffer specified in StartBuf and will end on the last image buffer in Video Savant.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Capture images from buffer 8 to the last buffer

vspython.iRecordUntilLastStorageBuffer(8)

95

Page 96: Video Savant Python function library - [email protected]

iRecordUntilNumberOfFrames

Perform image sequence capture until a specified number of images are captured. int iRecordUntilNumberOfFrames(

int StartBuf, // Buffer to start recording on int NumberOfFrames, // Number of frames to record

);

Parameters StartBuf

Recording will start on this buffer. NumberOfFrames

Recording will stop after NumberOfFrames images have been recorded, or when the last buffer has been reached (whichever occurs first).

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. If an error occurs, ensure that the acquisition device is turned on and all cables are securely fastened.

Example

Start recording in buffer 24. Stop recording after 10 images have been captured, or after the last buffer has been reached.

vspython.iRecordUntilNumberOfFrames(24,10) iReflect Swap pixels in an image about a reflection plane and copy to another location. int iReflect(

int sourceStartBuf, // source start buffer of the image(s) to process int sourceEndBuf, // source end buffer of the image(s) to process int destStartBuf, // starting storage buffer of the location(s) for

// results int destEndBuf, // Ending storage buffer of the location(s) for

// results int xLoc, // x-coordinate of top-left corner of

// image window when stored in // destination

int yLoc, // y-coordinate of top-left corner of // image window when stored in

96

Page 97: Video Savant Python function library - [email protected]

// destination int operation // reflection operation to perform

optional int constPixelValue, // constant pixel value to use in

// erasing background optional int greenPixelValue, // green constant pixel value to use in

// erasing background optional int bluePixelValue // blue constant pixel value to use in

// erasing background )

Parameters sourceStartBuf, sourceEndBuf

The sequence sourceStartBuf..sourceEndBuf contains the image buffers to process.

destStartBuf, destEndBuf

The sequence destStartBuf..destEndBuf contains the image buffers to store the processed image(s).

xLoc, yLoc

The location for storing the processed image window in the destination image buffer. xLoc and yLoc are the coordinates of the top-left corner of the destination location. Note that the source image window location is defined by the ROI setting (see iSetROI).

operation

The reflection operation. This is set to one of the following constants: Value Meaning iGEO_REFVERT Vertical reflection plane

iGEO_REFHORZ Horizontal reflection plane

constPixelValue

If this parameter is set, the color of the source pixels will be set to this pixelValue after processing.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are set, then the color of the red source pixels will be set to constPixelValue and the green and blue source pixels will be set to greenPixelValue and bluePixelValue respectively.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error

97

Page 98: Video Savant Python function library - [email protected]

occurred. Remarks The reflection plane is located in the middle of the ROI.

The source and destination can overlap. Pixels in the source ROI can be overwritten with a constant pixel value.

If the copied image ROI exceeds buffer boundaries in the destination, it is clipped.

The image buffers do not have to be unique.

iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iCopyTo, iRotate, iTranspose Examples Example 1 I want to reflect the images in buffers 3 and 4 vertically and store the resulting images in buffers 9 and 10 respectively starting at position (25,45). vspython.iReflect(3,4,9,10,25,45,iGEO_REFVERT) Example 2 I want to reflect the image in buffer 2 horizontally and store the resulting image in buffer 9 starting at the top left corner of the resulting image. I want to set all the pixels in buffer 2 to the pixel value 128. vspython.iReflect(2,2,9,9,0,0,iGEO_REFHORZ,128) Example 3 Same as the previous example except that I will set the source buffer pixels as follows: Red pixels set to 125, green pixels set to 150, and blue pixels set to 255. vspython.iReflect(2,2,9,9,0,0,iGEO_REFHORZ,125,150,255) iRotate

98

Page 99: Video Savant Python function library - [email protected]

Rotate image pixels and copy to another location. int iRotate(

int sourceStartBuf, // source start buffer of the image(s) to process int sourceEndBuf, // source end buffer of the image(s) to process int destStartBuf, // starting storage buffer of the location(s) for

// results int destEndBuf, // Ending storage buffer of the location(s) for

// results int xLoc, // x-coordinate of top-left corner of

// image window when stored in // destination

int yLoc, // y-coordinate of top-left corner of // image window when stored in

// destination int operation // rotation operation to perform

optional int constPixelValue, // constant pixel value to use in

// erasing background optional int greenPixelValue, // green constant pixel value to use in

// erasing background optional int bluePixelValue // blue constant pixel value to use in

// erasing background )

Parameters sourceStartBuf, sourceEndBuf

The sequence sourceStartBuf..sourceEndBuf contains the image buffers to process.

destStartBuf, destEndBuf

The sequence destStartBuf..destEndBuf contains the image buffers to store the processed image(s).

xLoc, yLoc

The location for storing the processed image window in the destination image buffer. xLoc and yLoc are the coordinates of the top-left corner of the destination location. Note that the source image window location is defined by the ROI setting (see iSetROI).

operation

The rotation operation. This is set to one of the following constants: Value Meaning iGEO_ROT90CW rotate 90 degrees clockwise

iGEO_ROT90CCW rotate 90 degrees counterclockwise

iGEO_ROT180 rotate 180 degrees

99

Page 100: Video Savant Python function library - [email protected]

constPixelValue

If this parameter is set, the color of the source pixels will be set to this pixelValue after processing.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are set, then the color of the red source pixels will be set to constPixelValue and the green and blue source pixels will be set to greenPixelValue and bluePixelValue respectively.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred. Remarks The source and destination can overlap.

Pixels in the source ROI can be overwritten with a constant pixel value.

If the copied image ROI exceeds buffer boundaries in the destination, it is clipped.

The image buffers do not have to be unique.

iSetRGBPlaneUsage sets the color planes affected by this operation. See Also iCopyTo, iReflect, iTranspose Examples Example 1 I want to rotate the images in buffers 3 and 4 ninety degrees clockwise and store the resulting images in buffers 9 and 10 respectively starting at position (25,45). vspython.iRotate(3,4,9,10,25,45, iGEO_ROT90CW) Example 2 I want to rotate the image in buffer 2 one hundred and eighty degrees and store the resulting image in buffer 9 starting at the top left corner of the resulting image. I want to set all the pixels in buffer 2 to the pixel value 128. vspython.iRotate(2,2,9,9,0,0,iGEO_ROT180,128)

100

Page 101: Video Savant Python function library - [email protected]

Example 3 Same as the previous example except that I will set the source buffer pixels as follows: Red pixels set to 125, green pixels set to 150, and blue pixels set to 255. vspython.iRotate(2,2,9,9,0,0,iGEO_ROT180,125,150,255)

iSetAVIWriteSettings Change the way that AVI images are exported into an image file int iSetAVIWriteSettings(

int pixelType, // export AVI images to this pixel type int framesPerSecond // frames per second

)

Parameters pixelType

Force all calls to iExportFile to export AVI images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values. framesPerSecond

Set this value to the number of frames per second the AVI images can be captured at.

Return Value

101

Page 102: Video Savant Python function library - [email protected]

The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred. See Also iSetRAWExportSettings, iExportFile, iSetTIFFWriteSettings, iSetBMPWriteSettings, iSetJPEGWriteSettings Example

I want to export buffers 3,4,5,6,and 7 from Video Savant into the file "C:\test\sample.avi" and store those images as 8 bit monochrome, marked with being captured at 30 frames per second. vspython.iSetAVIWriteSettings(iPIXTYPE8,30) vspython.iExportFile("C:\\test\\sample.avi","AVI",3,7) iSetBMPWriteSettings Change the way that BMP images are exported into an image file int iSetBMPWriteSettings(

int pixelType // export BMP images to this pixel type )

Parameters pixelType

Force all calls to iExportFile to export BMP images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values.

102

Page 103: Video Savant Python function library - [email protected]

Return Value The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred. See Also iSetRAWExportSettings, iExportFile, iSetTIFFWriteSettings, iSetAVIWriteSettings, iSetJPEGWriteSettings Example

I want to export buffer 0 from Video Savant into the file "C:\test\sample.BMP" and store that image as 24 bit color. vspython.iSetBMPWriteSettings(iPIXTYPERGB) vspython.iExportFile("c:\\test\\sample.BMP","BMP",0,0) iSetGraphicAttributes Sets the pen attributes used for drawing graphics with the iGraphic... functions. int iSetGraphicAttributes(

int operation, // operation for graphics pen int penColor, // pen color optional int greenPenColor, // pen color optional int bluePenColor // pen color

)

Parameters operation

The operation performed by the pen when drawing graphics.

Value Meaning

iGRAPHICOP_SET set each pixel to the value penColor iGRAPHICOP_XOR set each pixel to the result of an XOR

operation between the pixel and the value penColor

penColor

A constant used in setting the pixel values when graphics are drawn. The value of operation determines how penColor is used.

103

Page 104: Video Savant Python function library - [email protected]

greenPenColor, bluePenColor If greenPenColor and bluePenColor are set, the penColor described in operation will have penColor as the red pixel value and greenPenColor and bluePenColor as the blue and green pixel values of the pen color.

Return Value A non-zero return value indicates success. A zero return value indicates failure. Remarks The current graphics attributes can be read at any time with iGetGraphicAttributes. See Also iGetGraphicAttributes, iGraphicRectangle, iGraphicLine, iGraphicText, iGraphicEllipse Examples Example 1 I want to write with the pixel value 128 as the pen color. vspython.iSetGraphicAttributes(iGRAPHICOP_SET, 128) Example 2 I want to write with the pen where the pen color is the result of an XOR operation between the current pixel value and the following pixel values: red pixel value 45, green pixel value 0, and blue pixel value 255. vspython.iSetGraphicAttributes(iGRAPHICOP_XOR, 45, 0, 255) iSetJPEGWriteSettings Change the way that JPEG images are exported into an image file int iSetJPEGWriteSettings(

int pixelType, // export JPEG images to this pixel type int qualityPercentage // quality percentage desired

)

Parameters pixelType

104

Page 105: Video Savant Python function library - [email protected]

Force all calls to iExportFile to export JPEG images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values. qualityPercentage

Set this value to the quality percentage desired when exported JPEG images. This value should be in the range 1 to 100.

Return Value The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred. See Also iSetRAWExportSettings, iExportFile, iSetTIFFWriteSettings, iSetBMPWriteSettings, iSetAVIWriteSettings Example

I want to export buffer 1 from Video Savant into the file "C:\test\sample.jpg" and store that image as 8 bit monochrome with a quality percentage of 50%. vspython.iSetJPEGWriteSettings(iPIXTYPE8,50) vspython.iExportFile("C:\\test\\sample.jpg","JPEG",1,1) iSetRAWExportSettings Change the way that RAW images are exported to an image file

105

Page 106: Video Savant Python function library - [email protected]

int iSetRAWExportSettings(

int pixelType, // export RAW images to this pixel type int location, // Header footer location string componentTypes, // Component types string componentSizes // Component sizes

)

Parameters pixelType

Force all calls to iExportFile to export RAW images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale

values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

location

Set location to one of the following values:

Value Meaning 0 No header or footer is created. 1 Create a header for this file. Get the

information to store in the header from componentTypes and componentSizes.

2 Create a footer for this file. Get the information

106

Page 107: Video Savant Python function library - [email protected]

to store the footer from componentTypes and componentSizes.

componentTypes

componentTypes is a string of values separated by commas. The values represent what kind of data you want to store in the header/footer. You can set this string to NULL or the empty string if location is 0. The possible values for componentTypes are: Value Meaning 0 Height of the images 1 Width of the images

2 Pixel type

3 Number of images

4 Unused

componentSizes

componentSizes is a string of values separated by commas. The values represent how much space in bytes you need to store each of the component types. There is no reason to set any size greater than 4 bytes, because each of the componentTypes will easily fit in that space. You can set this string to NULL or the empty string if location is 0. You must specify a size for each of the componentTypes which you have specified in componentTypes.

Return Value The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred. See Also iSetTIFFWriteSettings, iExportFile, iSetAVIWriteSettings, iSetBMPWriteSettings, iSetJPEGWriteSettings

107

Page 108: Video Savant Python function library - [email protected]

Example I want to export buffers 3 and 4 from Video Savant into the file

"C:\test\sample.raw" and store those images as 8 bit monochrome. My image file will contain a footer which stores the height of the images, width of the images, pixel type, and number of images. I will use 4 bytes to store each entry in my footer. vspython.iSetRAWExportSettings(iPIXTYPE8,2,"0,1,2,3","4,4,4,4") vspython.iExportFile("C:\\test\\sample.raw","RAW",3,4) iSetRAWImportSettings Change the way that RAW images are imported from an image file int iSetRAWImportSettings(

int imageWidth, // Width of the images int imageHeight, // Height of the images int offset, // Offset from start of images int numOfImages, // Number of Images int location, // Header footer location string componentTypes, // Component types string componentSizes, // Component sizes optional int pixelType // import RAW images as this pixel type

)

Parameters imageWidth Width of the images in the image file. If you are getting width information

from the header or footer, set this value to 0. imageHeight Height of the images in the image file. If you are getting height information

from the header or footer, set this value to 0. offset Offset from the start of the images in the image file. If you are getting

information from the header or footer, set this value to 0. numOfImages Number of images in the image file. If you are getting the number of images

information from the header or footer, set this value to 0. location

Set location to one of the following values:

108

Page 109: Video Savant Python function library - [email protected]

Value Meaning 0 Not reading a header or footer. 1 A header exists for this file. Get the

information to read in from the header from componentTypes and componentSizes.

2 A footer exists for this file. Get the information

to read in from the footer from componentTypes and componentSizes.

componentTypes

componentTypes is a string of values separated by commas. The values represent what kind of data you want to read in from the header/footer. You can set this string to NULL or the empty string if location is 0. The possible values for componentTypes are: Value Meaning 0 Height of the images 1 Width of the images

2 Pixel type

3 Number of images

4 Unused

componentSizes

componentSizes is a string of values separated by commas. The values represent how much space in bytes was used to store each of the component types. You can set this string to NULL or the empty string if location is 0. You must specify a size for each of the componentTypes which you have specified in componentTypes.

pixelType

Only specify this value if you want to override the header or footer value for pixelType or if you are not reading in the header or footer. Force all calls to iImportFile to import RAW images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

109

Page 110: Video Savant Python function library - [email protected]

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale

values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

Return Value The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred. See Also iImportFile Example

I want to import buffers 0 and 1 from the file "C:\test\sample.raw" and store those images in buffers 13 and 14. My image file will contain a footer which stores the height of the images, width of the images, pixel type, and number of images. Each entry uses 4 bytes of space. Since I am extracting this information from the footer, I do not need to specify the width of the images, height of the images, offset, number of images, or pixel type. vspython.iSetRAWImportSettings(0,0,0,0,2,"0,1,2,3","4,4,4,4") vspython.iImportFile("C:\\test\\sample.raw","RAW",13,"0,1",1) iSetRGBPlaneUsage Specify which pixel color planes are to be used for image processing.

110

Page 111: Video Savant Python function library - [email protected]

int iSetRGBPlaneUsage( int useRedPlane, // use red color plane for image processing int useGreenPlane, // use green color plane for image processing int useBluePlane // use blue color plane for image processing

)

Parameters useRedPlane, useGreenPlane, useBluePlane

A non zero value specified means to use that color plane for processing, a zero value specified means that plane is not to be used in image processing.

Return Value On success, returns non-zero. On failure, returns zero. This function fails if no color planes are specified for processing. Remarks This function is useful when the current pixel type is set to 24-bit RGB. When the current pixel type is set to 24-bit RGB, the red, green, and blue color components can be independently selected for image processing operations. See Also iGetRGBPlaneUsage Example I want to set the red and green planes only for image processing. vspython.iSetRGBPlaneUsage(1,1,0) i SetROI Set the region-of-interest (ROI) used for image processing. int iSetROI(

int xpos, // The left edge of the ROI int ypos, // The top edge of the ROI int width, // The width of the ROI int height // The Height of the ROI

) Parameters xpos, ypos

111

Page 112: Video Savant Python function library - [email protected]

Coordinates of upper-left corner of ROI width The width of the ROI height The height of the ROI

Return Value The return value is non-zero if the ROI has been successfully set. It is zero if an error occurred.

Remarks The region-of-interest (ROI) is a rectangular area in an image buffer. Imaging library operations using the ROI allow only pixels inside the ROI and on the four ROI sides to be read or written. Pixels outside the ROI are ignored.

The imaging library manages one ROI per imaging device. All applications accessing a particular device must share the device's ROI. iIgnoreROI is the only other imaging library function which modifies the current ROI. See Also iIgnoreROI, iGetROI, iShowROIOutline Example I want to set the region of interest to start at position (25,45) with a width of 100 pixels and a height of 150 pixels. vspython.iSetROI(25,45,100,150) iSetTIFFWriteSettings Change the way that TIFF images are exported to an image file int iSetTIFFWriteSettings(

int pixelType, // export TIFF images to this pixel type int compressed, // compress original image? int append // append image to file?

)

112

Page 113: Video Savant Python function library - [email protected]

Parameters pixelType

Force all calls to iExportFile to export TIFF images as this pixel type. pixelType can be one of the following values:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale

values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

compressed

If compressed is set to 0, the original image(s) will be exported to the image file when iExportFile is called. Otherwise, the image(s) will be compressed in size when exported.

append

If append is set to 0, if the file specified in iExportFile already exists, then it will be overwritten with the new images to be exported. Otherwise, the new images to be exported will be appended to the end of the file.

Return Value The return value is non-zero if successful. Otherwise zero is returned, indicating an error occurred.

113

Page 114: Video Savant Python function library - [email protected]

See Also iSetRAWExportSettings, iExportFile, iSetAVIWriteSettings, iSetBMPWriteSettings, iSetJPEGWriteSettings Example

I want to export buffers 5,6,and 7 from Video Savant into the file "C:\test\sample.tif" and store those images as uncompressed and 16 bit monochrome. If any images already existed in sample.tif I want to overwrite them. vspython.iSetTIFFWriteSettings(iPIXTYPE16, 0, 0) vspython.iExportFile("C:\\test\\sample.tif","TIFF",5,7) iShiftBits Bit-shift image pixels left or right to form a second image. int iShiftBits(

int sourceStartBuf, // source start buffer of sequence int sourceEndBuf, // source end buffer of sequence int destStartBuf, // destination start buffer of sequence int destEndBuf, // destination end buffer of sequence int shiftPos, // number of positions to shift int shiftLeft // shift towards the left?

)

Parameters sourceStartBuf, sourceEndBuf

sourceStartBuf..sourceEndBuf is the sequence containing image buffers to perform the bit-shift operation on.

destStartBuf, destEndBuft destStartBuf..destEndBuf is the sequence containing image buffers into which to place the results.

shiftPos The number of bit positions to shift the pixels. Bits are not rotated as they are shifted out of a pixel. Bits shifted into a pixel are zero valued.

shiftLeft If set to non-zero, the bits are shifted in the direction of the most significant bit (identical to multiplication by power of 2), otherwise bits are shifted in the direction of least significant bit (identical to division by power of 2).

Return Value

114

Page 115: Video Savant Python function library - [email protected]

The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks This operation provides improved performance over iMulDiv when a power of 2 is used for multiplication or division. The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Pixel planes cannot be shifted into one another.

See also iMulDiv Example I want to shift the bits from buffers 3 and 4 two bits to the left, and store the resulting images in buffers 9 and 10. vspython.iShiftBits(3,4,9,10,2,1) iShowCursorLine Show, hide or move a "line" cursor on the currently displayed image buffer. void iShowCursorLine(

int show, // show or hide cursor int x1, // starting x coordinate int y1, // starting y coordinate int x2, // ending x coordinate int y2 // ending y coordinate

)

Parameters show

If this parameter is non-zero, the cursor is shown. If it is zero, the cursor is hidden, and x1, y1, x2, y2 are ignored.

x1, y1 The start point of the line.

x2, y2 The end point of the line.

115

Page 116: Video Savant Python function library - [email protected]

Return Value This function has no return value.

Remarks If a cursor is displayed, it should be hidden before reading image data in the current display buffer. Any portion of the line which would extend beyond the edges of the current image buffer is clipped.

See Also iActivateCursorMode, iShowCursorPoint, iShowCursorRect Example I want to show a line with a start point of (200,100) and an end point of (300,150). vspython.iShowCursorLine(1,200,100,300,150) iShowCursorPoint Show, hide or move a "point" cursor on the currently displayed image buffer. void iShowCursorPoint(

int show, // show or hide cursor int xpos, // x coordinate of cursor position int ypos // y coordinate of cursor position

)

Parameters show

If this parameter is non-zero, the cursor is shown. If it is zero, the cursor is hidden, and the xpos and ypos parameters are unused.

xpos, ypos The coordinates to show the cursor at, if nShow is non-zero.

Return Value This function has no return value.

Remarks

116

Page 117: Video Savant Python function library - [email protected]

The "point" cursor is usually a cross hair. The cursor coordinates specify the center of the cross hair. If a cursor is displayed, it should be hidden before reading image data in the current display buffer except in the case where iReadPixel is called to read image data located at the current cursor coordinates.

See Also iActivateCursorMode, iShowCursorRect, iShowCursorLine Example I want to show a cursor at position (25,45) vspython.iShowCursorPoint(1,25,45) iShowCursorRect Show, hide or move a "rectangle" cursor on the currently displayed image buffer. void iShowCursorRect(

int show, // show or hide cursor int x1, // left x-coordinate of rectangle int y1, // top y-coordinate of rectangle int x2, // right x-coordinate of rectangle int y2 // bottom y-coordinate of rectangle

)

Parameters show

If this parameter is non-zero, the cursor is shown. If it is zero, the cursor is hidden, and x1, y1, x2, y2 are ignored.

x1, y1 The upper-left corner of the rectangle.

x2, y2 The lower-right corner of the rectangle.

Return Value This function has no return value.

Remarks

117

Page 118: Video Savant Python function library - [email protected]

If a cursor is displayed, it should be hidden before reading image data in the current display buffer. Any portion of the rectangle which would extend beyond the edges of the current image buffer is clipped.

See Also iActivateCursorMode, iShowCursorPoint, iShowCursorLine Example I want to show a rectangle with an upper left corner of (25,45) and a bottom right corner of (150,125). vspython.iShowCursorRect(1,25,45,150,125) iShowROIOutline Show or hide a rectangular outline of the ROI on the image display monitor. void iShowROIOutline(

int show // show or hide outline )

Parameters

show

If this parameter is non-zero, the outline will be shown; if it is zero, the outline will be hidden.

Return Value This function has no return value.

Remarks The function iIsROIVisible can be used to determine if the outline drawn by iShowROIOutline is currently visible. The ROI rectangle display has the special property that it is always removed prior to operations that may read underlying data, and restored afterwards.

See Also iIsROIVisible, iSetROI

118

Page 119: Video Savant Python function library - [email protected]

Example I want to show the region of interest outline. vspython.iShowROIOutline(1) iSubtract Subtract one image from another to form a third image. int iSubtract(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source2StartBuf and source2EndBuf buffers is subtracted from the sequence between source1StartBuf and source1EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. If a pixel in source2StartBuf..source2EndBuf is greater than the corresponding pixel in source1StartBuf..source1EndBuf (which would result in a negative result) the destination pixel is set to 0. See Also

119

Page 120: Video Savant Python function library - [email protected]

iAbsDif Example I want to subtract all the pixels in buffers 6 and 7 from buffer 3 and store the resulting buffers in buffers 9 and 10. vspython.iSubtract(3,3,6,7,9,10) iSubtractConstant Subtract a constant value from an image to form a second image. int iSubtractConstant(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constantPixelValue, // constant to subtract from pixels optional int greenPixelValue, // green constant to subtract from

// pixels optional int bluePixelValue // blue constant to subtract from

// pixels );

Parameters sourceStartBuf, sourceEndBuf

The constant value will be subtracted from the sequence between sourceStartBuf and sourceEndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

constantPixelValue

The constant value to subtract the pixels by. The pixels are subtracted by the pixel values in the sequence between sourceStartBuf and sourceEndBuf. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be subtracted by all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be subtracted by to the corresponding color pixels in the source buffers.

)

120

Page 121: Video Savant Python function library - [email protected]

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. If subtracting the constant value from a pixel would produce a result less than 0, the result is set to 0.

See Also iAddConstant Examples Example 1

Subtracting the constant(50) by the images in the sequence 2,3 and storing the result in buffers 7,8. vspython.iSubtractConstant(2,3,7,8,50) Example 2 Subtracting the constant(128) by the red pixel values, constant(255) by the green pixel values, and constant(0) by the blue pixel values of the image in buffer 2. The result will be stored in buffer 7. vspython.iSubtractConstant(2,2,7,7,128,255,0) iTableTransform Transform an image using a look up table. int iTableTransform(

int sourceStartBuf, // source start buffer of sequence int sourceEndBuf, // source end buffer of sequence int destStartBuf, // destination start buffer of sequence int destEndBuf, // destination end buffer of sequence int ptrLUT // location for look up table , optional int numIndexBits, // number of index bits optional int numBitsToShift, // Number of bit positions the Index.

// Bits are left-shifted from the least // significant bit.

optional int valueClassBits // value of the class bits );

121

Page 122: Video Savant Python function library - [email protected]

Parameters

sourceStartBuf, sourceEndBuf sourceStartBuf..sourceEndBuf is the sequence containing image buffers to operate on.

destStartBuf, destEndBuf destStartBuf..destEndBuf is the sequence containing image buffers to place the results.

ptrLUT

ptrLUT

represents the location of the look up table. The look up table will be filled with the transformation values. If none of the optional parameters are specified, the look up table must contain 2pixel size entries. (pixel size is 8 for 8 bit grayscale or 24 bit color devices and pixel size is 16 for 16 bit grayscale devices) Otherwise, the look up table must contain 2numIndexBits entries. ptrLUT must first be passed to iAlloc with the number of entries of the look up table as the size and iPIXTYPEDEF as the pixel type.

numIndexBits, numBitsToShift, valueClassBits

The bits in an image pixel (or pixel color plane) value are divided into Index Bits and Class Bits. If the Class Bits in a pixel (or pixel color plane) value equals valueClassBits, the ptrLUT array element indexed by the value stored in numIndexBits will be indexed.

Either all of numIndexBits, numBitsToShift, and valueClassBits are specified or none of them are. If none of these parameters are set, it is assumed that you are specifying a look up table with an entry for every possible pixel value. numIndexBits The number of Index bits. numBitsToShift

Number of bit positions the Index bits are left-shifted from the least significant bit.

valueClassBits Value of the class bits.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The contents of ptrLUT can be filled by a call to the Python function StoreList

122

Page 123: Video Savant Python function library - [email protected]

(part of the ListManip module). Shorter sequences rewind after the last buffer. The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. Examples Example 1 I am using 8 bit monochrome. I want to transform each of the pixel values in buffer 3 on a logarithmic scale. The resulting image will be stored in buffer 8. import ListManip import math Slope = (math.e - 1) / 255 LUTStorage = vspython.iAlloc(256, iPIXTYPE8) LUTList = [] for count in xrange(256): LUTList.append((255 - 1) * math.log(Slope*count + 1)) ListManip.StoreList(LUTStorage, LUTList, iPIXTYPE8) vspython.iTableTransform(3,3,8,8,LUTStorage) vspython.iFree(LUTStorage) del LUTList Example 2 Assume we are using 8 bit monochrome. I want to map each group of 16 pixel values (0 to 15, 16 to 31, etc.) to the same pixel value. (the lowest pixel value in the group) I will use 4 index bits so I need 24 values in my look up table. However, I want to look at the 4 most significant bits so I shift 4 bits. I want to perform this transformation on buffer 3 and store the result in buffer 9. import ListManip LUTStorage = vspython.iAlloc(16, iPIXTYPE8) LUTList = [] for count in xrange(16): LUTList[count] = count*16 ListManip.StoreList(LUTStorage, LUTList, iPIXTYPE8) vspython.iTableTransform(3,3,9,9,LUTStorage,4,4,0) vspython.iFree(LUTStorage)

iTranspose

123

Page 124: Video Savant Python function library - [email protected]

Swap image rows and columns and copy to another location. int iTranspose(

int sourceStartBuf, // source start buffer of the image(s) to process int sourceEndBuf, // source end buffer of the image(s) to process int destStartBuf, // starting storage buffer of the location(s) for

// results int destEndBuf, // Ending storage buffer of the location(s) for

// results int xLoc, // x-coordinate of top-left corner of

// image window when stored in // destination

int yLoc, // y-coordinate of top-left corner of // image window when stored in

// destination int operation, // transpose operation to perform

optional int constPixelValue, // constant pixel value to use in

// erasing background optional int greenPixelValue, // green constant pixel value to use in

// erasing background optional int bluePixelValue // blue constant pixel value to use in

// erasing background )

Parameters sourceStartBuf, sourceEndBuf

The sequence sourceStartBuf..sourceEndBuf contains the image buffers to process.

destStartBuf, destEndBuf

The sequence destStartBuf..destEndBuf contains the image buffers to store the processed image(s).

xLoc, yLoc

The location for storing the processed image window in the destination image buffer. xLoc and yLoc are the coordinates of the top-left corner of the destination location. Note that the source image window location is defined by the ROI setting (see iSetROI).

operation

The transpose operation. This is set to one of the following constants: Value Meaning iGEO_TRANSTL transpose starting at top-

left and proceeding to lower-right iGEO_TRANSTR transpose starting at top-

124

Page 125: Video Savant Python function library - [email protected]

right and proceeding to lower-left constPixelValue

If this parameter is set, the color of the source pixels will be set to this pixelValue after processing.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are set, then the color of the red source pixels will be set to constPixelValue and the green and blue source pixels will be set to greenPixelValue and bluePixelValue respectively.

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The source and destination can overlap. Pixels in the source ROI can be overwritten with a constant pixel value. If the copied image ROI exceeds buffer boundaries in the destination, it is clipped. The image buffers do not have to be unique. iSetRGBPlaneUsage sets the color planes affected by this operation.

See Also iCopyTo, iReflect, iRotate Examples Example 1 I want to tranpose the images in buffers 3 and 4 starting at the top left and proceeding to the lower right and store the resulting images in buffers 9 and 10 respectively starting at position (25,45). vspython.iTranspose(3,4,9,10,25,45, iGEO_TRANSTL) Example 2 I want to tranpose the image in buffer 2 starting at the top right and proceeding to the lower left and store the resulting image in buffer 9 starting at the top left corner of the resulting image. I want to set all the pixels in buffer 2 to the pixel value 128. vspython.iTranspose(2,2,9,9,0,0, iGEO_TRANSTR,128)

125

Page 126: Video Savant Python function library - [email protected]

Example 3 Same as the previous example except that I will set the source buffer pixels as follows: Red pixels set to 125, green pixels set to 150, and blue pixels set to 255. vspython.iTranspose(2,2,9,9,0,0, iGEO_TRANSTR,125,150,255) iWaitFor

Wait a designated period of time before performing the next operation. int iWaitFor(

int time // time in milliseconds to wait );

Parameters time

The time to wait in milliseconds before proceeding to the next operation. Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred.

Example

Wait 10 seconds, print a number to the screen vspython.iWaitFor(10000) print 6 iWaitUntil

Wait until a particular time before proceeding with the next operation int iWaitUntil(

int Year, // Year to wait until int Month, // Month to wait until int Day, // Day to wait until int Hour, // Hour to wait until int Minute, // Minute to wait until int Second // Second to wait until

);

126

Page 127: Video Savant Python function library - [email protected]

Parameters NOTE: For the following parameters, the date and time set must be greater than or equal to the current date and time. Year

The year to wait until before proceeding with the next operation. Set this value to 0 to use the current year.

Month

The month to wait until before proceeding with the next operation. Set this value to 0 to use the current month.

Day

The day to wait until before proceeding with the next operation. Set this value to 0 to use the current day.

Hour

The hour to wait until before proceeding with the next operation. Set this value to –1 to use the current hour.

Minute

The minute to wait until before proceeding with the next operation. Set this value to –1 to use the current minute.

Second

The second to wait until before proceeding with the next operation. Set this value to –1 to use the current second.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. Example

Wait until July 26, 2001 at 11:00 am, print a number to the screen vspython.iWaitUntil(2001,7,26,11,0,0) print 6 iWaitUntilTime

127

Page 128: Video Savant Python function library - [email protected]

Wait for the next occurrence of a particular hour, minute, or second. int iWaitUntilTime(

int nTimeType, // Type of time to wait for (hour, minute, second) int nTimeValue, // The particular hour, minute, or second to wait for

);

Parameters nTimeType

The type of time to wait for. The possible types are:

Value Meaning HOUR The function will wait for the next occurrence of

particular hour in a day. This hour is specified as a value between 0 and 23 using the nTimeValue field.

MINUTE The function will wait for the next occurrence of

a particular minute in an hour. The minute is specified as a value between 0 and 59 using the nTimeValue field.

SECOND The function will wait for the next occurrence of

a particular second in a minute. The second is specified as a value between 0 and 59 using the nTimeValue field.

nTimeValue

The particular hour, minute, or second that the function should wait for. See the description of nTimeType for a description of possible values to use.

Return Value A non-zero value is returned if the operation was successful. Zero is returned if an error occurred. Example

Every hour, at exactly 15 minutes past the hour, print a number to the screen. Please note that to terminate this example script, you need to press the F1 key.

128

Page 129: Video Savant Python function library - [email protected]

while(1): vspython.iWaitUntilTime(MINUTE, 15) print 6

iWriteBlock

Write a block of pixels to an image buffer window. int iWriteBlock(

int destBuf, // destination buffer int pixelType, // type of pixel int ptrBuffer, // buffer containing data to write int xpos, // left x-coordinate of dest. region int ypos, // top y-coordinate of dest. int width, // width of destination region int height // height of destination region

) Parameter

destBuf

Image data is written to this buffer

pixelType The type of pixel data stored in the buffer referenced by ptrBuffer. See iReadBlock for a discussion of how to set pixelType.

ptrBuffer ptrBuffer represents the location of the buffer data which is to be written to destBuf. ptrBuffer must first be passed to iAlloc with width*height as the size and pixelType as the pixel type.

xpos, ypos

The upper-left hand corner of the rectangle to write the data to.

width The width of the destination region in pixels. height The height of the destination region in pixels. Return Value The return value is non-zero if the data has been successfully written. It is zero if an error occurred.

129

Page 130: Video Savant Python function library - [email protected]

Remarks To store a list of integers inside pixelBuffer, call the Python function StoreList (part of the ListManip module) with pixelType as the pixel type.

For imaging devices which store true color images, this function will write the data stored in the host memory to each of the color planes as specified by iSetRGBPlaneUsage.

See Also iReadBlock, iWriteRGBBlock, iSetRGBPlaneUsage Example

I am using a 24 bit color camera. I want to read in the block of data from buffer 3 starting at position (0,0) with a width of 300 pixels and a height of 400 pixels. Next, I will write this block of data to buffer 9, starting at position (40,65) except that I have increased all pixel values by 7. import ListManip Size = 300*400 result = vspython.iAlloc(Size, iPIXTYPERGB) vspython.iReadBlock(3,iPIXTYPERGB,0,0,300,400,result) pixelList = ListManip.CreateList(result, Size, iPIXTYPERGB) for count in xrange(len(pixelList)): pixelList[count] = pixelList[count] + 7 if pixelList[count] > 255: pixelList[count] = 255 ListManip.StoreList(result, pixelList, iPIXTYPERGB) vspython.iWriteBlock(9,iPIXTYPERGB, result, 40, 65, 300, 400) vspython.iFree(result) del pixelList iWriteElement Write a value to a particular index of a storage block of data. int iWriteElement(

int ptrStorage, // integer representing storage location of stored // data

int index, // index of ptrStorage to access int pixelType, // pixel type int pixelValue // pixel value

)

130

Page 131: Video Savant Python function library - [email protected]

Parameters ptrStorage

ptrStorage represents the location of the storage block of data. ptrStorage must first have been passed to iAlloc with the appropriate size (see iAlloc for more information) and pixelType as the pixel type.

index

The index of ptrStorage to access. The first index is always at position 0 and index must be a valid index.

pixelType

The type of data located in the storage location referred to by ptrStorage. The pixelType should match the pixel type passed in to iAlloc. The possible types are:

Value Meaning iPIXTYPE8 Data is stored as pixels of 8 bit gray scale

values. For color devices, active color planes are averaged. For 16 bit devices, only the high-order bytes are used.

iPIXTYPE16 Data is stored as pixels of 16 bit gray scale

values. For 8 bit devices, the 8 bit value is placed in the high-order byte. For color devices, active color planes are averaged.

iPIXTYPERGB Data is stored as pixels of three 8 bit values in

the order: red, green, blue. For 16 bit devices, only the high-order pixel bytes are used.

iPIXTYPEDEF Data is stored as pixels of 8 bit gray scale

values on 8 bit devices (including 24 bit color devices). Data is stored as pixels of 16 bit gray scale values on 16 bit devices.

iPIXTYPEPOINT Data is stored as (x,y) coordinate pairs.

iPIXTYPECONTOURS Data is stored as contour values.

pixelValue The value to be assigned to the pixel represented at location index of ptrStorage. Color values are passed in one color plane at a time.

131

Page 132: Video Savant Python function library - [email protected]

Return Value The return value is non zero if the operation was successful, and 0 if an error occurred. See Also iReadBlock, iWriteBlock, iWriteRGBBlock Example I want to write to the 4th index in the storage block of data the pixel value 25. import ListManip Size = 100*20 result = vspython.iAlloc(Size,iPIXTYPE8) value = vspython.iWriteElement(result, 4, iPIXTYPE8, 25) vspython.iFree(result) iWritePixel

Write a pixel value to a point in an image buffer. int iWritePixel(

int destStartBuf, // starting buffer in destination sequence int destEndBuf, // ending buffer in destination sequence int xpos, // x-coordinate of point int ypos, // y-coordinate of point int pixelValue, // pixel value to write optional int greenPixelValue, // green pixel value to write optional int bluePixelValue // blue pixel value to write

)

Parameters

destStartBuf, destEndBuf

The pixel will be written to each image buffer in the sequence destStartBuf..destEndBuf.

xpos, ypos The coordinates of the pixel to write.

pixelValue

132

Page 133: Video Savant Python function library - [email protected]

The value to set the pixel to.

greenPixelValue, bluePixelValue If greenPixelValue and bluePixelValue are set, then the colored pixel value containing pixelValue as the red pixel value and greenPixelValue and bluePixelValue as the blue and green pixel values will be used.

Return Value A non-zero return value indicates success. A zero return value indicates failure.

Examples Example 1 I want to write the pixel value 5 to the buffers 9,10,11,and 12 at location (35,90). vspython.iWritePixel(9,12,35,90,5) Example 2 I want to write the colored pixel value (40,60,80) (Red, Green, Blue) to buffer 8 at location (0,0). vspython.iWritePixel(8,8,0,0,40,60,80)

iWriteRGBBlock

Write a block of data to the red, green, or blue pixel planes in an image buffer window. int iWriteRGBBlock(

int destBuf, // image for writing out block of pixels int ptrRedStorage, // integer representing storage location to store

// red values int ptrGreenStorage, // integer representing storage location to store

// green values int ptrBlueStorage, // integer representing storage location to store

// blue values int xpos, // top-left x-coordinate of image window // to write to int ypos, // top-left y-coordinate of image window int width, // width of image window to write to

// to write to

int height // height of image window to write to )

133

Page 134: Video Savant Python function library - [email protected]

Parameters destBuf

Write the pixel value data referenced by ptrRedStorage, ptrGreenStorage, and ptrBlueStorage to this image buffer.

ptrRedStorage, ptrGreenStorage, ptrBlueStorage

ptrRedStorage represents the location of the pixel data for the iWriteRGBBlock red pixel value information. To fill in this location with the actual pixel data, you must call the Python function StoreList (part of the ListManip module) with iPIXTYPE8 as the pixel type. ptrRedStorage must first be passed to iAlloc with width*height as the size and iPIXTYPE8 as the pixel type to create the storage space needed to store the red pixel value result from iReadRGBBlock. ptrGreenStorage and ptrBlueStorage are indentically defined as ptrRedStorage except for the green and blue pixels.

xpos, ypos

The upper-left hand corner of the image window to write to. width, height

The width and height of the image window to write to. Return Value The return value is non-zero if the data has been successfully written. It is zero if an error occurred. Remarks To store a list of integers inside ptrRedStorage, ptrGreenStorage, or ptrBlueStorage, call the Python function StoreList (part of the ListManip module) with iPIXTYPE8 as the pixel type. An application normally uses this function when writing true color image data to a true color imaging device. However, an application can call this function if a gray scale device is used. For a gray scale device, the pixel value is calculated as an average of the (non-NULL) red, green and blue host memory buffers. For 16 bit gray scale devices, the 8 bit color plane average is stored in the high-order pixel bytes, and 0 is stored in the low order pixel bytes. iWriteBlock can be used to set a group of color planes as specified by iSetRGBPlaneUsage from a single host memory buffer. See the remarks following iWriteBlock.

See Also iReadRGBBlock, iWriteBlock, iSetRGBPlaneUsage

134

Page 135: Video Savant Python function library - [email protected]

Example I am reading from a color image. I want to read in the pixel block starting at position (0,0) with a width of 310 pixels and a height of 278 pixels from buffer 3. Next, I extract each of the red, green, and blue values read from the buffer and store them each in a list. Each pixel value in the red list is increased by 3, each pixel value in the green list is decreased by 5, and each pixel value in the blue list is increased by 1. These altered lists are put back in the storage buffer locations. Finally, I write out the values in the storage locations to buffer 9 starting at position (35,45) with a width of 310 pixels and a height of 278 pixels. import ListManip Size = 310*278 RedStorage = vspython.iAlloc(Size, iPIXTYPE8) GreenStorage = vspython.iAlloc(Size, iPIXTYPE8) BlueStorage = vspython.iAlloc(Size, iPIXTYPE8) vspython.iReadRGBBlock(3,0,0,310,278,RedStorage,GreenStorage,BlueStorage) RedList = ListManip.CreateList(RedStorage, Size, iPIXTYPE8) GreenList = ListManip.CreateList(GreenStorage, Size, iPIXTYPE8) BlueList = ListManip.CreateList(BlueStorage, Size, iPIXTYPE8) for count in xrange(len(RedList)): RedList[count] = RedList[count] + 3 GreenList[count] = GreenList[count] - 5 BlueList[count] = BlueList[count] + 1 if RedList[count] > 255: RedList[count] = 255 if GreenList[count] < 0: GreenList[count] = 0 if BlueList[count] > 255: BlueList[count] = 255 ListManip.StoreList(RedStorage, RedList, iPIXTYPE8) ListManip.StoreList(GreenStorage, GreenList, iPIXTYPE8) ListManip.StoreList(BlueStorage, BlueList, iPIXTYPE8) vspython.iWriteRGBBlock(9,RedStorage,GreenStorage,BlueStorage,35,45,310,278) vspython.iFree(RedStorage) vspython.iFree(GreenStorage) vspython.iFree(BlueStorage) del RedList del GreenList del BlueList iXOR

135

Page 136: Video Savant Python function library - [email protected]

Perform a bitwise XOR (Exclusive-Or) between two images to form a third image. int iXOR(

int source1StartBuf, // first source start buffer int source1EndBuf, // first source end buffer int source2StartBuf, // second source start buffer int source2EndBuf, // second source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf // destination end buffer to store results

); Parameters

source1StartBuf, source1EndBuf, source2StartBuf, source2EndBuf

The sequence between source1StartBuf and source1EndBuf buffers is XORed together with the sequence between source2StartBuf and source2EndBuf buffers.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results

Return Value The return value is non-zero if the operation succeeded. It is zero if an error occurred.

Remarks The image buffers do not have to be unique. This operation is only performed on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise XOR examines the pixel values in the sources bit-by-bit, and sets the bits in the destination value according to this table:

Bitwise XOR

Source 1 Source 2 Destination 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0 Example I want to XOR the pixels in buffers 3 and 4 with the pixels in buffer 7, and store the resulting images in buffers 9 and 10.

136

Page 137: Video Savant Python function library - [email protected]

vspython.iXOR(3,4,7,7,9,10) iXORConstant Perform a bitwise XOR (Exclusive-Or) between an image and a constant value to form a second image. int iXORConstant(

int sourceStartBuf, // source start buffer int sourceEndBuf, // source end buffer int destStartBuf, // destination start buffer to store results int destEndBuf, // destination end buffer to store results int constantPixelValue, // constant to XOR with pixels optional int greenPixelValue, // green constant to XOR with pixels optional int bluePixelValue // blue constant to XOR with pixels

);

Parameters sourceStartBuf, sourceEndBuf

The sequence between sourceStartBuf and sourceEndBuf buffers will be XORed with the constant value.

destStartBuf, destEndBuf

The sequence between destStartBuf and destEndBuf will contain the image buffers to place the results.

constantPixelValue

The constant value to XOR with the pixels in the images in the sequence between sourceStartBuf and sourceEndBuf. If the image is a color image and greenPixelValue and bluePixelValue are not set, the constantPixelValue will be XORed with all three color planes.

greenPixelValue, bluePixelValue

If greenPixelValue and bluePixelValue are specified, then constantPixelValue will be treated as the red pixel value and each of the red, green, and blue pixel values will be XORed with the corresponding color in the source buffers.

Return Value The return value is non-zero if successful, and zero if an error occurred.

Remarks The image buffers do not have to be unique. This operation is only performed

137

Page 138: Video Savant Python function library - [email protected]

on pixels in the current ROI. iSetRGBPlaneUsage sets the color planes affected by this operation. A bitwise XOR examines the pixel values in the source and the constant value bit-by-bit, and sets destination pixel bits according to this table:

Bitwise XOR Source 1 Source 2 Destination 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0 Examples Example 1

XORing the constant(50) to the images in the sequence 2,3 and storing the result in buffers 7,8. vspython.iXORConstant(2,3,7,8,50) Example 2 XORing the constant(128) to the red pixel values, constant(255) to the green pixel values, and constant(0) to the blue pixel values of the image in buffer 2. The result will be stored in buffer 7. vspython.iXORConstant(2,2,7,7,128,255,0) LIST MANIP MODULE FUNCTIONS CreateList Create a list from a storage buffer list CreateList(

int ptrStorage, // location of the storage block of data int size, // number of entries in the list int pixelType // type of data in the list

)

Parameters ptrStorage

The location of the storage block of data. The storage block of data must

138

Page 139: Video Savant Python function library - [email protected]

already have been filled. A call to iAlloc must be made prior to calling this function. The return value of iAlloc is ptrStorage.

size

The number of entries in the list. pixelType

The type of data in the list. The possible values are the same as pixelType for iAlloc. pixelType in CreateList must match the pixelType passed in to an earlier call to iAlloc.

Return Value A list of pixelType data is created of length size. The list contains the values stored in ptrStorage. See Also iReadBlock, iReadRGBBlock, iReadLine, iEnumExtractContours, iGetLinePoints Example See examples for all the functions in the See Also section. StoreList Store the contents of a list into a storage buffer void StoreList(

int ptrStorage, // location of the storage block of data list listToStore, // the list to store int pixelType // type of data in the list

)

Parameters ptrStorage

The location of the storage block of data. A call to iAlloc must be made prior to calling this function. The return value of iAlloc is ptrStorage.

listToStore

The list to store into the storage buffer ptrStorage. The list can not have more entries in it than storage space has been allocated for ptrStorage.

pixelType

139

Page 140: Video Savant Python function library - [email protected]

The type of data in the list. The possible values are the same as pixelType for iAlloc. pixelType in StoreList must match the pixelType passed in to an earlier call to iAlloc.

Return Value None. See Also iWriteBlock, iWriteRGBBlock, iTableTransform, iEnumExtractContours Example See examples for all the functions in the See Also section. StringToList Converts a string of numbers separated by commas into a list of integers list StringToList(

string numList // list of numbers separated by commas )

Parameters numList

The list of numbers separated by commas. This string does not contain any spaces in it.

Return Value The list of numbers in the string is returned as an actual list with the same values. See Also iExtractHistogram, iExtractProjectionRows, iExtractProjectionCols

140

Page 141: Video Savant Python function library - [email protected]

141

Example See examples for all the functions in the See Also section.