# Motion and object tracking

- FASTCV\_API void fcvUpdateMotionHistoryu8s32(const uint8\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, int32\_t \*\_\_restrict dst, uint32\_t dstStride, int32\_t timeStamp, int32\_t maxHistory)

    - This function calculates the motion history image.

This function updates the motion history image based on the input motion image. src is a motion image where pixelvalue!=0 indicates a moving pixel. The function go through all the pixels in the src image. If the value is non zero, it sets the corresponding value of the dst image as the timestamp value. If the value is zero, it compares the corresponding value at the dst image with the timestamp value, if the difference is larger than the

- Parameters:

    - - **src** – The input image/patch. Must be 8 bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:should** be 128-bit aligned.
- **srcWidth** – Image width, the number of pixels in a row **NOTE:** should be a multiple of 8.
- **srcHeight** – Image height.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth. **NOTE:** should be a multiple of 8.
- **dst** – The input image/patch. Must be 8 bit grayscale image. Size of buffer is dstStride\*srcHeight bytes. **NOTE:should** be 128-bit aligned.
- **dstStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth. **NOTE:** should be a multiple of 8.
- **timeStamp** – The timestamp value of the current frame that’s being updated.
- **maxHistory** – The maximum window size that the motion history image will keep.

- Returns:

    - No return value.

- FASTCV\_API uint32\_t fcvMeanShiftu8(const uint8\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria)

    - Applies the meanshift procedure and obtains the final converged position.

This function applies the meanshift procedure to an original image (usually a probability image) and obtains the final converged position. The converged position search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be 8 bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the MeanShift which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations

- Returns:

    - The actually number of iterations

- FASTCV\_API uint32\_t fcvMeanShifts32(const int32\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria)

    - Applies the meanshift procedure and obtains the final converged position.

This function applies the meanshift procedure to an original image (usually a probability image) and obtains the final converged position. The converged position search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be int 32bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*4. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the MeanShift which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations

- Returns:

    - Number of iterations

- FASTCV\_API uint32\_t fcvMeanShiftf32(const [float32\_t](https://docs.qualcomm.com/doc/80-79511-2/topic/typedef_a00021_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria)

    - Applies the meanshift procedure and obtains the final converged position.

This function applies the meanshift procedure to an original image (usually a probability image) and obtains the final converged position. The converged position search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be float 32bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*4. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the MeanShift which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations

- Returns:

    - Number of iterations

- FASTCV\_API uint32\_t fcvConAdaTracku8(const uint8\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria, [fcvBox2D](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00002.html#_CPPv48fcvBox2D) \*circuBox)

    - Applies the ConAdaTrack procedure and find the object center, size and orientation.

This function applies the ConAdaTrack procedure to an original image (usually a probability image) and obtains the final converged object. The optimal object search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be 8bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the object search which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations
- **circuBox** – The circumscribed box around the object

- Returns:

    - Number of iterations

- FASTCV\_API uint32\_t fcvConAdaTracks32(const int32\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria, [fcvBox2D](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00002.html#_CPPv48fcvBox2D) \*circuBox)

    - Applies the ConAdaTrack procedure and find the object center, size and orientation.

This function applies the ConAdaTrack procedure to an original image (usually a probability image) and obtains the final converged object. The optimal object search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be int 32bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*4. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the object search which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations
- **circuBox** – The circumscribed box around the object

- Returns:

    - Number of iterations

- FASTCV\_API uint32\_t fcvConAdaTrackf32(const [float32\_t](https://docs.qualcomm.com/doc/80-79511-2/topic/typedef_a00021_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, [fcvRectangleInt](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00019.html#_CPPv415fcvRectangleInt) \*window, [fcvTermCriteria](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00020.html#_CPPv415fcvTermCriteria) criteria, [fcvBox2D](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00002.html#_CPPv48fcvBox2D) \*circuBox)

    - Applies the ConAdaTrack procedure and find the object center, size and orientation.

This function applies the ConAdaTrack procedure to an original image (usually a probability image) and obtains the final converged object. The optimal object search will stop either it has reached the required accuracy or the maximum number of iterations.

- Parameters:

    - - **src** – Pointer to the original image which is usually a probability image computed based on object histogram. Must be float 32bit grayscale image. Size of buffer is srcStride\*srcHeight bytes. **NOTE:** should be 128-bit aligned.
- **srcWidth** – The width of the input source image. **NOTE:** should be a multiple of 8.
- **srcHeight** – The height of the input source image.
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*4. **NOTE:** should be a multiple of 8.
- **window** – Pointer to the initial search window position which also returns the final converged window position.
- **criteria** – The criteria used to finish the object search which consists of two termination criteria: 1) epsilon: required accuracy; 2) max\_iter: maximum number of iterations
- **circuBox** – The circumscribed box around the object

- Returns:

    - Number of iterations

- FASTCV\_API [fcvBGCodeWord](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00001.html#_CPPv413fcvBGCodeWord) \*\*fcvCreateBGCodeBookModel(uint32\_t srcWidth, uint32\_t srcHeight, void \*\*\_\_restrict cbmodel)

    - Creates codebook model according to the image size.

This function creates codebook model and returns codebook map.
    These 2 parameters will be used in fcvBGCodeBookUpdateu8(), fcvBGCodeBookDiffu8()
    and fcvBGCodeBookClearStaleu8(). Codebook functions are useful in background subtraction
    in many use cases, such as video surveillance.
    Copy to clipboard

- Parameters:

    - - **srcWidth** – Width of the input image. **NOTE:** should be multiple of 8. The number of pixels in a row.
- **srcHeight** – Height of the input image.
- **cbmodel** – Double pointer to codebook model. Codebook model contains parameters for generating and maintaining codebook model.

- Returns:

    - Double pointer to codebook map. Codebook map is a pointer map consisting of code word for each pixel of input image.

- FASTCV\_API void fcvReleaseBGCodeBookModel(void \*\*cbmodel)

    - Releases codebook model and codebook map.

This function release codebook model and codebook map. Codebook map is
    referred in codebook model.
    Copy to clipboard

- Parameters:

    - **cbmodel** – Double pointer to codebook model

- FASTCV\_API void fcvConfigBGCodeBookModel(void \*cbmodel, uint8\_t cbBound, uint8\_t minMod, uint8\_t maxMod)

    - configure codebook model

This function configure codebook model. It takes three parameters. They
    are codebook boundary, minimum and maximum mode for each channel (generally 3).
    These three parameters are firstly configured in fcvCreateBGCodeBookModel,
    and the values are (10,10,10), (3,1,1) and (10,1,1) respectively.
    Copy to clipboard

- Parameters:

    - - **cbmodel** – Pointer to codebook model
- **cbBound** – Pointer to uint8\_t array that should be of 3 elements. This parameter is for updating codebook model in fcvBGCodeBookUpdateu8 that specifies the boundary of each channel.
- **minMod** – Pointer to uint8\_t array that should be of 3 elements. This parameter is for generating the mask in fcvBGCodeBookDiffu8 that specifies the minimum mode of each channel of the code word.
- **maxMod** – Pointer to uint8\_t array that should be of 3 elements. This parameter is for generating the mask in fcvBGCodeBookDiffu8 that specifies the maximum mode of each channel of the code word.

- FASTCV\_API void fcvBGCodeBookUpdateu8(void \*\_\_restrict cbmodel, const uint8\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, const uint8\_t \*\_\_restrict fgMask, uint32\_t fgMaskStride, [fcvBGCodeWord](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00001.html#_CPPv413fcvBGCodeWord) \*\*\_\_restrict cbMap, int32\_t \*\_\_restrict updateTime)

    - Updates codebook map according to input image. fgMask can be a reference.

This function updates codebook map according to input image. fgMask is generated by
    fcvBGCodeBookDiffu8() and can be a reference in this function. Therefore, fgMask is
    NULL at the first time.
    Codebook functions are useful in background subtraction in many use cases, such as
    video surveillance.
    Copy to clipboard

- Parameters:

    - - **cbmodel** – Pointer to codebook model Codebook model contains parameters for generating and maintaining codebook model
- **src** – Pointer to the input image **WARNING:** should be 128-bit aligned. must be a 3-channel image.
- **srcWidth** – Width of the image in pixel. The number of pixels in a row. **NOTE:** should be multiple of 8.
- **srcHeight** – Height of the image in pixel
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*3. **NOTE:** should be multiple of 8.
- **fgMask** – Pointer to the returned foreground mask image. Use NULL as default **WARNING:** should be 128-bit aligned. must be a 1-channel image, same width & height as src.
- **fgMaskStride** – Stride of the foreground mask image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 fgMaskStride is default to srcWidth. **NOTE:** should be multiple of 8.
- **cbMap** –

    Pointer to codebook map

    Codebook map is a pointer map consisting of code word for each pixel of input image.
- **updateTime** –

    Update time.

    updateTime is a return value.

- FASTCV\_API void fcvBGCodeBookDiffu8(void \*\_\_restrict cbmodel, const uint8\_t \*\_\_restrict src, uint32\_t srcWidth, uint32\_t srcHeight, uint32\_t srcStride, uint8\_t \*\_\_restrict fgMask, uint32\_t fgMaskStride, [fcvBGCodeWord](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00001.html#_CPPv413fcvBGCodeWord) \*\*\_\_restrict cbMap, int32\_t \*\_\_restrict numFgMask)

    - Generates differential mask of input frame according to background codebook map.

This function generates differential mask  of input frame according to background codebook map.
    Codebook functions are useful in background subtraction in many use cases, such as
    video surveillance.
    Copy to clipboard

- Parameters:

    - - **cbmodel** – Pointer to codebook model Codebook model contains parameters for generating and maintaining codebook model
- **src** – Pointer to the input image **WARNING:** should be 128-bit aligned. must be a 3-channel image.
- **srcWidth** – Width of the image in pixel. The number of pixels in a row. **NOTE:** should be multiple of 8.
- **srcHeight** – Height of the image in pixel
- **srcStride** – Stride of image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 srcStride is default to srcWidth\*3. **NOTE:** should be multiple of 8.
- **fgMask** – Pointer to the returned foreground mask image. **WARNING:** should be 128-bit aligned. must be a 1-channel image, same width & height as src.
- **fgMaskStride** – Stride of the foreground mask image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 fgMaskStride is default to srcWidth. **NOTE:** should be multiple of 8.
- **cbMap** –

    Pointer to code book map.

    Codebook map is a pointer map consisting of code word for each pixel of input image.
- **numFgMask** –

    Number of foreground pixels in the mask

    numFgMask is a return value.

- FASTCV\_API void fcvBGCodeBookClearStaleu8(void \*\_\_restrict cbmodel, int32\_t staleThresh, const uint8\_t \*\_\_restrict fgMask, uint32\_t fgMaskWidth, uint32\_t fgMaskHeight, uint32\_t fgMaskStride, [fcvBGCodeWord](https://docs.qualcomm.com/doc/80-79511-2/topic/struct_a00001.html#_CPPv413fcvBGCodeWord) \*\*\_\_restrict cbMap)

    - Removes stale element in codebook according to foreground mask.

This function removes stale element in codebook according to foreground mask.
    Threshold is defined in staleThresh.
    Codebook functions are useful in background subtraction in many use cases, such as
    video surveillance.
    Copy to clipboard

- Parameters:

    - - **cbmodel** – Pointer to codebook model Codebook model contains parameters for generating and maintaining codebook model
- **staleThresh** – Threshold of stale element
- **fgMask** – Pointer to the foreground mask image in ROI. Use NULL as default **NOTE:** should be 128-bit aligned. must be a 1-channel image.
- **fgMaskWidth** – Width of the mask in pixel, which is the same as input image **NOTE:** should be multiple of 8.
- **fgMaskHeight** – Height of the mask in pixel, which is the same as input image
- **fgMaskStride** – Stride of the foreground mask image is the number of bytes between column 0 of row 1 and column 0 of row 2 in data memory. If left at 0 fgMaskStride is default to fgMaskWidth. **NOTE:** should be multiple of 8.
- **cbMap** –

    Pointer to code book map

    Codebook map is a pointer map consisting of code word for each pixel of input image.

Last Published: Aug 30, 2024

[Previous Topic
Miscellaneous](https://docs.qualcomm.com/bundle/publicresource/80-79511-2/topics/miscellaneous.md) [Next Topic
Object detection](https://docs.qualcomm.com/bundle/publicresource/80-79511-2/topics/object_detection.md)