# libcvautomation: Libcv Search Methods

libcvautomation 1.5

- Main Page
- Related Pages
- Classes
- Files

Libcv Search Methods

This page describes the methods libcv uses to search for a sub image in a root image.

## Tolerance Values

Tolerance values are used to control how strict each of the following search methods are. Acceptable values are from `INT_MIN` to `INT_MAX`.

Additionally, each of the reference programs - `cva-input` and `cva-match` - have a "sane tolerance" built in. This is accessed by the "-o" switch, and allows you to specify a tolerance on scale of 1-100, where 1 is incredibly strict, and 100 is incredibly loose.

Note:
  The formula for calculating the sane tolerance is: \( T(x) = (10^{\frac{\log{INT\_MAX}}{\lambda}})^x \) where \( \lambda \) is the highest tolerance value (in our case, 100). Finally, we have to round down a little bit to ensure that we don't accidentally generate a value higher than `INT_MAX`. The formula used does mean that we will never be able to generate values lower than 0.

Warning:
  The "sane-tolerance" option doesn't know which search method you are using - Thus while 1 is an incredibly strict search for Squared Difference and Squared Difference (Normalized), it is fairly loose search for Cross Correlation, Cross Correlation (Normalized), Correlation Coefficient, and Correlation Coefficient (Normalized)

## Squared Difference

     #define CV_TM_SQDIFF   0

Squared Difference is the default search method used by `libcvautomation`, as well as `cva-match` and `cva-input`.

For this method, setting a low tolerance value results in a more strict match.

Formula: \(R(x,y) = \sum_{x',y'} (T(x',y') - I(x + x', y+y'))^2 \)

## Squared Difference (Normalized)

     #define CV_TM_SQDIFF_NORMED    1

This is a normalized version of the Squared Difference search method.

For this method, setting a low tolerance value results in a more strict match.

Formula: \( R(x,y) = \frac{\sum_{x',y'}(T(x',y') - I(x + x', y + y'))^2}{ \sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'}I(x + x', y + y')^2}} \)

## Cross Correlation

     #define CV_TM_CCORR    2

This is the Cross Correlation search method.

For this method, setting a high tolerance value results in a more strict match.

Formula: \( R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y')) \)

## Cross Correlation (Normalized)

     #define CV_TM_CCORR_NORMED 3

This is the normalized version of the Cross Correlation search method.

For this method, setting a high tolerance value results in a more strict match.

Formula: \( R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I'(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}} \)

## Correlation Coefficient

     #define CV_TM_CCOEFF   4

This is the Correlation Coefficient search method.

For this method, setting a high tolerance value results in a more strict match.

Formula: \( R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I(x+x',y+y')) \) where: \( \begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array} \)

## Correlation Coefficient (Normalized)

     #define CV_TM_CCOEFF_NORMED    5

This is the normalized version of the Correlation Coefficient search method.

For this method, setting a high tolerance value results in a more strict match.

Formula: \( R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} } \)

All Classes Files Functions Defines