Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
ShiftDetector< A > Struct Template Reference

ShiftDetector structure provides shift detection of given region at the image. More...

#include <SimdShift.hpp>

Public Types

enum  TextureType {
  TextureGray ,
  TextureGrad
}
 
enum  DifferenceType {
  AbsDifference ,
  SquaredDifference
}
 
typedef A< uint8_t > Allocator
 
typedef Simd::View< A > View
 
typedef Simd::Point< ptrdiff_t > Point
 
typedef Simd::Point< double > FPoint
 
typedef Rectangle< ptrdiff_t > Rect
 

Public Member Functions

void InitBuffers (const Point &frameSize, size_t levelCount, TextureType textureType=TextureGray, DifferenceType differenceType=AbsDifference)
 
void SetBackground (const View &background, bool makeCopy=true)
 
bool Estimate (const View &current, const Rect &region, const Point &maxShift, double hiddenAreaPenalty=0, ptrdiff_t regionAreaMin=REGION_CORRELATION_AREA_MIN)
 
bool Estimate (const View &current, const Rect &region, int maxShift, double hiddenAreaPenalty=0, ptrdiff_t regionAreaMin=REGION_CORRELATION_AREA_MIN)
 
Point Shift () const
 
FPoint ProximateShift () const
 
double Stability () const
 
double Correlation () const
 

Detailed Description

template<template< class > class A>
struct Simd::ShiftDetector< A >

ShiftDetector structure provides shift detection of given region at the image.

Using example:

#include "Simd/SimdShift.hpp"
#include <iostream>

int main()
{
    typedef Simd::ShiftDetector<Simd::Allocator> ShiftDetector;

    ShiftDetector::View background;
    background.Load("../../data/image/face/lena.pgm");

    ShiftDetector detector;

    detector.InitBuffers(background.Size(), 4);

    detector.SetBackground(background);

    ShiftDetector::Rect region(64, 64, 192, 192);

    ShiftDetector::View current = background.Region(region.Shifted(10, 10));

    if (detector.Estimate(current, region, 32))
        std::cout << "Shift = (" << detector.Shift().x << ", " << detector.Shift().y << "). " << std::endl;
    else
        std::cout << "Can't find shift for current image!" << std::endl;

    return 0;
}

Member Typedef Documentation

◆ Allocator

typedef A<uint8_t> Allocator

Allocator type definition.

◆ View

typedef Simd::View<A> View

An image type definition.

◆ Point

typedef Simd::Point<ptrdiff_t> Point

A point with integer coordinates.

◆ FPoint

typedef Simd::Point<double> FPoint

A point with float point coordinates.

◆ Rect

typedef Rectangle<ptrdiff_t> Rect

A rectangle type definition.

Member Enumeration Documentation

◆ TextureType

Describes types of texture which used to find correlation between background and current image.

Enumerator
TextureGray 

Original grayscale image.

TextureGrad 

Saturated sum of absolute gradients along X and Y axes.

◆ DifferenceType

Describes types of function which used to find correlation between background and current image.

Enumerator
AbsDifference 

Sum of absolute differences of points of two images.

SquaredDifference 

Sum of squared differences of points of two images.

Member Function Documentation

◆ InitBuffers()

void InitBuffers ( const Point frameSize,
size_t  levelCount,
TextureType  textureType = TextureGray,
DifferenceType  differenceType = AbsDifference 
)

Initializes internal buffers of ShiftDetector structure. It allows it to work with image of given size.

Parameters
[in]frameSize- a size of background image.
[in]levelCount- number of levels in the internal image pyramids used to find shift.
[in]textureType- type of textures used to detect shift.
[in]differenceType- type of correlation functions used to detect shift.

◆ SetBackground()

void SetBackground ( const View background,
bool  makeCopy = true 
)

Sets a background image. Size of background image must be equal to frameSize (see function ShiftDetector::InitBuffers).

Parameters
[in]background- background image.
[in]makeCopy- if true, copy of the background will be created.

◆ Estimate() [1/2]

bool Estimate ( const View current,
const Rect region,
const Point maxShift,
double  hiddenAreaPenalty = 0,
ptrdiff_t  regionAreaMin = REGION_CORRELATION_AREA_MIN 
)

Estimates shift of current image relative to background image.

Parameters
[in]current- current image.
[in]region- a region at the background where the algorithm start to search current image. Estimated shift is taken relative of the region.
[in]maxShift- a 2D-point which characterizes maximal possible shift of the region (along X and Y axes).
[in]hiddenAreaPenalty- a parameter used to restrict searching of the shift at the border of background image.
[in]regionAreaMin- a parameter used to set minimal area of region use for shift estimation. By default is equal to 25.
Returns
a result of shift estimation.

◆ Estimate() [2/2]

bool Estimate ( const View current,
const Rect region,
int  maxShift,
double  hiddenAreaPenalty = 0,
ptrdiff_t  regionAreaMin = REGION_CORRELATION_AREA_MIN 
)

Estimates shift of current image relative to background image.

Parameters
[in]current- current image.
[in]region- a region at the background where the algorithm start to search current image. Estimated shift is taken relative of the region.
[in]maxShift- a maximal distance which characterizes maximal possible shift of the region.
[in]hiddenAreaPenalty- a parameter used to restrict searching of the shift at the border of background image.
[in]regionAreaMin- a parameter used to set minimal area of region use for shift estimation. By default is equal to 25.
Returns
a result of shift estimation.

◆ Shift()

Point Shift ( ) const

Gets estimated integer shift of current image relative to background image.

Returns
estimated integer shift.

◆ ProximateShift()

FPoint ProximateShift ( ) const

Gets proximate (with sub-pixel accuracy) shift of current image relative to background image.

Returns
proximate shift with sub-pixel accuracy.

◆ Stability()

double Stability ( ) const

Gets a value which characterizes stability (reliability) of found shift.

Returns
stability (reliability) of found shift.

◆ Correlation()

double Correlation ( ) const

Gets the best correlation of background and current image.

Returns
the best correlation of background and current image.