vz::Imagination  v1.0.0-2969
C++ helper class for image manipulation using OpenCV
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
vz Namespace Reference

vz namespace for C Code Run's "Vision" tools and libraries. More...

Classes

class  Imagination
 Imagination objects are used to perform simple and common image manipulations, as well as act as an image cache to store variations on an image. More...
 

Typedefs

typedef std::vector< cv::Mat > VMats
 Vector of OpenCV cv::Mat. More...
 
typedef std::vector< std::string > VStr
 Vector of text strings. More...
 
typedef std::vector< cv::Point > Contour
 A single contour is a vector of many points. More...
 
typedef std::vector< ContourVContours
 Many contours are then combined to create a vector of contours. More...
 
typedef std::vector< cv::RotatedRect > VRotatedRects
 Vector of rotated rectangles. More...
 
typedef std::vector< cv::Vec4i > VV4i
 Vector of Vec4i. More...
 
typedef std::vector< int > VInt
 Vector of int. More...
 
typedef std::set< double > SDouble
 Set of doubles. More...
 
typedef std::vector< double > VDouble
 Vector of doubles. More...
 
typedef std::vector< VDoubleVVDouble
 Vector of vz::VDouble. More...
 
typedef std::vector< size_t > VSizet
 Vector of size_t. More...
 
typedef std::map< std::string, std::string > MStr
 Map of strings where both the key and the value are strings. More...
 

Functions

VVDouble intervals (VDouble &data, const double threshold_multiplier=2.0)
 Automatically determine some intervals in a vector of double values. More...
 
VDouble popular_values_from_intervals (const VVDouble &vv, const double threshold=0.5)
 Find one or more possible values based on the given intervals. More...
 
double best_value_from_intervals (const VVDouble &vv)
 Returns the average of the largest grouping within the intervals. More...
 
std::string to_string (const VVDouble &vv)
 Convert the given interval to a text string. More...
 
size_t k_means (const VDouble &data, size_t k, VSizet &assignments, VDouble &centroids)
 Perform k-means clustering on a vector of doubles. More...
 
size_t k_means_vector (const VDouble &data, size_t k, vz::VVDouble &results, VDouble &centroids)
 Similar to vz::k_means(), but the results that would have been returned in assignments are de-referenced and formatted as a vector of clusters. More...
 
bool compare_exact (const cv::Mat &lhs, const cv::Mat &rhs)
 Compare two images. This will only return true if the images are exactly the same. More...
 
cv::Mat to_greyscale (const cv::Mat &src)
 Convert the source cv::Mat image to single-channel grey. More...
 
cv::Mat apply_gaussian_blur (const cv::Mat &src, const int kernel_size=3)
 Apply a Gaussian blur to the image. More...
 
cv::Mat apply_blur_and_convert_to_greyscale (const cv::Mat &src, const int kernel_size=3)
 Apply a Gaussian blur to the image and then convert the result to single-channel greyscale. More...
 
cv::Mat apply_simple_colour_balance (const cv::Mat &src)
 Apply a simple colour balance to the image. More...
 
cv::Mat erode (const cv::Mat &src, const int iterations=1)
 Erode the image. More...
 
cv::Mat dilate (const cv::Mat &src, const int iterations=1)
 Dilate the image. More...
 
cv::Mat invert (const cv::Mat &src)
 Invert the image. More...
 
cv::Mat apply_canny_edge_detection (const cv::Mat &src, const double canny_threshold)
 Apply canny edge detection. More...
 
VContours find_contours (const cv::Mat &src)
 Find the contours in the given source image. More...
 
cv::Mat add_contours_to_image (const cv::Mat &src, const VContours &contours, const cv::Scalar &colour=cv::Scalar(0, 255, 255))
 Add the given contours (if any) to the image. More...
 
cv::Mat add_contours_and_limits_to_image (const cv::Mat &src, const VContours &contours)
 Very similar to add_contours_to_image(), but colours the contours based on groupings/limits of the contour areas. More...
 
cv::Mat plot_histogram (const cv::Mat &src, const int width=640, const int height=480, const cv::Scalar background_colour=cv::Scalar(0, 0, 0))
 Plot the image's histogram. More...
 
cv::Mat find_hough_lines (const cv::Mat &src, VV4i &lines)
 Apply the Hough Lines transform. More...
 
cv::Mat rotate (const cv::Mat &src, double degrees)
 Rotate an image an arbitrary number of degrees around the exact center of the image. More...
 
cv::Mat resize (const cv::Mat &src, int width, int height=0)
 Resize the given image, while maintaining the original aspect ratio. More...
 
cv::Mat resize (const cv::Mat &src, const double scale)
 Resize the given image, keeping the same aspect ratio. More...
 
cv::Mat letterbox (const cv::Mat &src, int width, int height, const cv::Scalar &colour=cv::Scalar(0, 0, 0))
 Resize the image to fit within the given dimensions and apply a border to pad the size until the desired size is achieved. More...
 
cv::Mat apply_DoG (const cv::Mat &src, const double k=1.6, const double sigma=0.5, const double gamma=1.0)
 Perform 2 Gaussian blurs of different size, and subtract the 2nd from the 1st. More...
 
cv::Mat apply_DoG_threshold (const cv::Mat &src, const double k=200.0, const double sigma=0.5, const double gamma=1.0)
 Obtain the DoG (Difference of Gaussian) by calling apply_DoG(), then find a threshold image from the result. More...
 
VRotatedRects convert_contours_to_rotated_rects (const VContours &contours)
 Convert all of the contours to rotated rectangles. More...
 

Detailed Description

vz namespace for C Code Run's "Vision" tools and libraries.

Typedef Documentation

◆ VMats

typedef std::vector<cv::Mat> vz::VMats

Vector of OpenCV cv::Mat.

◆ VStr

typedef std::vector<std::string> vz::VStr

Vector of text strings.

◆ Contour

typedef std::vector<cv::Point> vz::Contour

A single contour is a vector of many points.

See also
vz::find_contours()

◆ VContours

typedef std::vector<Contour> vz::VContours

Many contours are then combined to create a vector of contours.

See also
vz::find_contours()

◆ VRotatedRects

typedef std::vector<cv::RotatedRect> vz::VRotatedRects

Vector of rotated rectangles.

See also
vz::convert_contours_to_rotated_rects()

◆ VV4i

typedef std::vector<cv::Vec4i> vz::VV4i

Vector of Vec4i.

See also
vz::find_hough_lines()

◆ VInt

typedef std::vector<int> vz::VInt

Vector of int.

◆ SDouble

typedef std::set<double> vz::SDouble

Set of doubles.

◆ VDouble

typedef std::vector<double> vz::VDouble

Vector of doubles.

See also
vz::k_means()

◆ VVDouble

typedef std::vector<VDouble> vz::VVDouble

Vector of vz::VDouble.

See also
vz::k_means_vector()

◆ VSizet

typedef std::vector<size_t> vz::VSizet

Vector of size_t.

See also
vz::k_means()

◆ MStr

typedef std::map<std::string, std::string> vz::MStr

Map of strings where both the key and the value are strings.

Function Documentation

◆ intervals()

vz::VVDouble vz::intervals ( VDouble data,
const double  threshold_multiplier = 2.0 
)

Automatically determine some intervals in a vector of double values.

Based on some example code discovered at https://stackoverflow.com/questions/17479944/partitioning-an-float-array-into-similar-segments-clustering while looking into segmentation and natural break optimizations.

Note
This should produce better results than attempting to use vz::k_means() on 1-D data.
Parameters
[in,out]dataThe input data vector is sorted by intervals().
[in]threshold_multiplierUsed to calculate the threshold when determining where to start a new interval. The larger the threshold, the smaller the number of intervals. A threshold multiplier near 0.0 will cause every value to be in a new interval.

For example, given this data:

vz::VDouble data = { 1.1, 1.2, 1.3, 5.7, 5.8, 5.9, 12.0 };

Calling vz::intervals() might return something similar to this:

results == { {1.1, 1.2, 1.3}, {5.7, 5.8, 5.9}, {12.0} );
See also
vz::k_means()
Jenks Natural Breaks Optimization
Kernel Density Estimation (KDE)
Exceptions
std::invalid_argumentif threshold_multiplier is <= 0

Referenced by add_contours_and_limits_to_image(), and vz::Imagination::create_hough_lines_and_angles().

Here is the caller graph for this function:

◆ popular_values_from_intervals()

vz::VDouble vz::popular_values_from_intervals ( const VVDouble vv,
const double  threshold = 0.5 
)

Find one or more possible values based on the given intervals.

If multiple values are returned, they will be sorted from most-likely to least-likely as determined by the size of the interval groupings.

Parameters
[in]vvThe intervals returned by vz::intervals().
[in]thresholdHelps determine how many groupings to consider. If set to 1.0, then only the largest grouping will be considered, while a value of 0.5 will take into consideration any grouping that is at least 1/2 the size of the largest interval.

For example, given this data:

?

Calling vz::popular_values_from_intervals() might return something similar to this:

?

◆ best_value_from_intervals()

double vz::best_value_from_intervals ( const VVDouble vv)

Returns the average of the largest grouping within the intervals.

For example, given this data:

?

Calling vz::best_value_from_intervals() might return something similar to this:

?

Referenced by vz::Imagination::create_hough_lines_and_angles().

Here is the caller graph for this function:

◆ to_string()

std::string vz::to_string ( const VVDouble vv)

Convert the given interval to a text string.

The resulting string is meant for debug purposes, not serialization.

For example:

-> interval #1/6: 6 values, average=1.35, midrange=1.35, median=1.4, values: 1.1 1.2 1.3 1.4 1.5 1.6
-> interval #2/6: 3 values, average=5.8, midrange=5.8, median=5.8, values: 5.7 5.8 5.9
-> interval #3/6: 4 values, average=9.5, midrange=9.5, median=9.6, values: 9.2 9.4 9.6 9.8
-> interval #4/6: 27 values, average=15.05, midrange=15.05, median=15.05, values: 15.01 15.01 15.01 15.02 15.02 15.02 15.03 15.03 15.03 15.04 15.04 15.04 15.05 15.05 15.05 15.06 15.06 15.06 15.07 15.07 15.07 15.08 15.08 15.08 15.09 15.09 15.09
-> interval #5/6: 5 values, average=32, midrange=32, median=32, values: 30 31 32 33 34
-> interval #6/6: 1 values, average=99, midrange=99, median=99, values: 99
  • average is the arithmetic mean (sum of every value divided by the number of values)
  • midrange is the sum of the largest and smallest values divided by 2
  • median is the central point of the data set

◆ k_means()

size_t vz::k_means ( const VDouble data,
size_t  k,
VSizet assignments,
VDouble centroids 
)

Perform k-means clustering on a vector of doubles.

Unfortunately, k-means requires the caller to know the exact number of clusters.

Warning
Running k-means on single dimension data (such as a vector of doubles) is not the recommended way to use k-means cluster detection. Especially with a data set that contains wide gaps between the data, or data with a large number of entries at one end of the range, the results are unlikely to be very useful. Instead, you probably want to use vz::intervals().
Note
This implementation is based on two tutorials about k-means:
Parameters
[in]dataVector of doubles.
[in]kThe number of clusters. The result may have fewer than this if there isn't enough input data.
[out]assignmentsA vector of indexes indicating the cluster into which a data point was assigned. Indexes will range from zero to k - 1.
[out]centroidsThe final centroids as determined by k-means – the location of each cluster.
Returns
Returns the number of iterations required.

For example, given this data:

vz::VDouble data = { 1.1, 1.2, 1.3, 5.7, 5.8, 5.9 };

Calling vz::k_means() with k=2 might return something similar to the following after 2 iterations:

assignments == { 0, 0, 0, 1, 1, 1 };
centroids == { 1.2, 5.8 };
See also
vz::k_means_vector()
Exceptions
std::invalid_argumentif k (number of clusters) is invalid

Referenced by k_means_vector().

Here is the caller graph for this function:

◆ k_means_vector()

size_t vz::k_means_vector ( const VDouble data,
size_t  k,
vz::VVDouble results,
VDouble centroids 
)

Similar to vz::k_means(), but the results that would have been returned in assignments are de-referenced and formatted as a vector of clusters.

For example, given this data:

vz::VDouble data = { 1.1, 1.2, 1.3, 5.7, 5.8, 5.9 };

Calling k_means_split() with k=2 might return something similar to the following after 2 iterations:

results == { {1.1, 1.2, 1.3}, {5.7, 5.8, 5.9} };
centroids == { 1.2, 5.8 };
See also
vz::k_means()

References k_means().

Here is the call graph for this function:

◆ compare_exact()

bool vz::compare_exact ( const cv::Mat &  lhs,
const cv::Mat &  rhs 
)

Compare two images. This will only return true if the images are exactly the same.

Referenced by vz::Imagination::operator==().

Here is the caller graph for this function:

◆ to_greyscale()

cv::Mat vz::to_greyscale ( const cv::Mat &  src)

Convert the source cv::Mat image to single-channel grey.

If the source is already greyscale, then returns a clone of the source image.

Examples:

original image result image
capture.jpg
capture_grey.jpg
coins.jpg
coins_grey.jpg
See also
vz::Imagination::EMatType::kO2Greyscale
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif the image has an unsupported number of channels

Referenced by apply_blur_and_convert_to_greyscale(), apply_DoG(), vz::Imagination::create_threshold(), and vz::Imagination::get().

Here is the caller graph for this function:

◆ apply_gaussian_blur()

cv::Mat vz::apply_gaussian_blur ( const cv::Mat &  src,
const int  kernel_size = 3 
)

Apply a Gaussian blur to the image.

Parameters
[in]srcThe input image. This can be a colour, greyscale, or binary image.
[in]kernel_sizeThe kernel size must be positive, and an odd number. The larger the kernel size, the larger the blur area. A kernel of size 1 does not blur.

Examples:

original image kernel_size=3 kernel_size=9 kernel_size=15
gaussian_blur_original.jpg
gaussian_blur_3x3.jpg
gaussian_blur_9x9.jpg
gaussian_blur_15x15.jpg
See also
vz::Imagination::EMatType::kO2GaussianBlur
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif the kernel size is < 1 or an even number

Referenced by apply_blur_and_convert_to_greyscale(), vz::Imagination::create_threshold(), and vz::Imagination::get().

Here is the caller graph for this function:

◆ apply_blur_and_convert_to_greyscale()

cv::Mat vz::apply_blur_and_convert_to_greyscale ( const cv::Mat &  src,
const int  kernel_size = 3 
)

Apply a Gaussian blur to the image and then convert the result to single-channel greyscale.

This is equivalent to calling both apply_gaussian_blur() and to_greyscale().

Parameters
[in]srcThe input image. This can be a colour, greyscale, or binary image.
[in]kernel_sizeThe kernel size must be positive, and an odd number. The larger the kernel size, the larger the blur area. A kernel of size 1 does not blur.
Returns
The output image will be single-channel greyscale, regardless of the input image.

Examples:

original image kernel_size=3 kernel_size=9 kernel_size=15
gaussian_blur_original.jpg
gaussian_blur_3x3_grey.jpg
gaussian_blur_9x9_grey.jpg
gaussian_blur_15x15_grey.jpg
See also
vz::Imagination::EMatType::kO2BlurGreyscale

References apply_gaussian_blur(), and to_greyscale().

Here is the call graph for this function:

◆ apply_simple_colour_balance()

cv::Mat vz::apply_simple_colour_balance ( const cv::Mat &  src)

Apply a simple colour balance to the image.

This is the color balancing technique used in Adobe Photoshop's "auto levels" command. The idea is that in a well balanced photo, the brightest color should be white and the darkest black. Thus, we can remove the color cast from an image by scaling the histograms of each of the R, G, and B channels so that they span the complete 0-255 scale.

Note
Source: http://www.morethantechnical.com/2015/01/14/simplest-color-balance-with-opencv-wcode/
Source: http://web.stanford.edu/~sujason/ColorBalancing/simplestcb.html

Examples:

original image result image
capture.jpg
simple_colour_balance.jpg
See also
vz::Imagination::EMatType::kO2SimpleColourBalance
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ erode()

cv::Mat vz::erode ( const cv::Mat &  src,
const int  iterations = 1 
)

Erode the image.

Dark area in the image are "grown" to erode lighter area. Reverses the changes done by vz::dilate().

Parameters
[in]srcThe input image.
[in]iterationsThe number of erosion iterations to run. Must be a positive number.

Examples:

original image iterations=1 iterations=2 iterations=3
coins_grey.jpg
coins_erode_1.jpg
coins_erode_2.jpg
coins_erode_3.jpg

The results are typically better when the source is a binary image:

original image iterations=1 iterations=2 iterations=3
coins_threshold_with_blur_3.jpg
coins_threshold_erode_1.jpg
coins_threshold_erode_2.jpg
coins_threshold_erode_3.jpg
See also
vz::Imagination::EMatType::kErode
vz::Imagination::EMatType::kThreshold
vz::dilate()
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ dilate()

cv::Mat vz::dilate ( const cv::Mat &  src,
const int  iterations = 1 
)

Dilate the image.

This works best on black-and-white threshold images. Does the opposite as vz::erode(), meaning that white areas of the image are "grown".

Parameters
[in]srcThe input image.
[in]iterationsThe number of dilation iterations to run. Must be a positive number.

Examples:

original image erode iterations=3 erode + dilate iterations=3
coins.jpg
coins_threshold_erode_3.jpg
coins_erode_and_dilate_3.jpg
See also
vz::Imagination::EMatType::kErodeAndDilate
vz::to_greyscale()
vz::erode()
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ invert()

cv::Mat vz::invert ( const cv::Mat &  src)

Invert the image.

Examples:

original image result image
capture.jpg
capture_invert.jpg
coins.jpg
coins_invert.jpg
See also
vz::Imagination::EMatType::kO2Invert
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::create_threshold(), and vz::Imagination::get().

Here is the caller graph for this function:

◆ apply_canny_edge_detection()

cv::Mat vz::apply_canny_edge_detection ( const cv::Mat &  src,
const double  canny_threshold 
)

Apply canny edge detection.

The result of canny edge detection is a black-and-white image, and the output can differ significantly depending on the input source.

Parameters
[in]srcThe input image.
[in]canny_thresholdA threshold to apply when converting the input image to black-and-white. This must be a positive number.

Examples:

input image description input image output image
original colour image
coins.jpg
coins_canny_edge_detect.jpg
gaussian blur image (3x3 kernel size)
See also
vz::apply_gaussian_blur()
vz::Imagination::EMatType::kO2GaussianBlur
coins_blur_3.jpg
coins_blur_3_canny_edge_detect.jpg
gaussian blur image (15x15 kernel size)
See also
vz::apply_gaussian_blur()
vz::Imagination::EMatType::kO2GaussianBlur
coins_blur_15.jpg
coins_blur_15_canny_edge_detect.jpg
threshold image
See also
vz::Imagination::EMatType::kThreshold
coins_threshold.jpg
coins_threshold_canny_edge_detect.jpg
See also
vz::Imagination::EMatType::kCannyEdgeDetection
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ find_contours()

vz::VContours vz::find_contours ( const cv::Mat &  src)

Find the contours in the given source image.

Unlike most other functions in the vz namespace, the output of this function is not a visual image. Instead, the output is a vector of contours, each of which is a vector of points.

To get a visual representation of the contours, call vz::add_contours_to_image().

Parameters
[in]srcThe input image should be a black-and-white image, such as those produced by apply_canny_edge_detection().
Note
For a visual representation of what find_contours() detects, see the output of add_contours_to_image().
See also
vz::Imagination::EMatType::kFindContours
vz::add_contours_to_image().
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::find_contours().

Here is the caller graph for this function:

◆ add_contours_to_image()

cv::Mat vz::add_contours_to_image ( const cv::Mat &  src,
const VContours contours,
const cv::Scalar &  colour = cv::Scalar(0, 255, 255) 
)

Add the given contours (if any) to the image.

Parameters
[in]srcInput image which is cloned prior to drawing the contours.
[in]contoursThe vector of contours to draw. This is obtained via vz::find_contours().
[in]colourThe RGB colour to use when drawing the contours. The default colour is yellow.

Example:

input image output image
coins.jpg
coins_contours.jpg
See also
vz::Imagination::EMatType::kFindContours
vz::find_contours().
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ add_contours_and_limits_to_image()

cv::Mat vz::add_contours_and_limits_to_image ( const cv::Mat &  src,
const VContours contours 
)

Very similar to add_contours_to_image(), but colours the contours based on groupings/limits of the contour areas.

Exceptions
std::invalid_argumentif the image is empty

References intervals().

Referenced by vz::Imagination::get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plot_histogram()

cv::Mat vz::plot_histogram ( const cv::Mat &  src,
const int  width = 640,
const int  height = 480,
const cv::Scalar  background_colour = cv::Scalar(0, 0, 0) 
)

Plot the image's histogram.

Parameters
[in]srcInput must be either 3-channel (BGR) or 1-channel (greyscale) image.
[in]widthWidth of output histogram plot.
[in]heightHeight of output histogram plot.
[in]background_colourDefaults to black, but also common would be cv::Scalar(255,255,255) to get a white background.

Examples of histograms on colour images:

original image histogram
capture.jpg
histogram_capture_colour.png
coins.jpg
histogram_coins_colour.png
sudoku.jpg
histogram_sudoku_colour.png

Examples of histograms on greyscale images:

original image histogram
capture_grey.jpg
histogram_capture_grey.png
coins_grey.jpg
histogram_coins_grey.png
sudoku_grey.jpg
histogram_sudoku_grey.png
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif the image is neither greyscale nor 3-channel RGB
std::invalid_argumentif the output dimensions are out of range

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ find_hough_lines()

cv::Mat vz::find_hough_lines ( const cv::Mat &  src,
vz::VV4i lines 
)

Apply the Hough Lines transform.

Parameters
[in]srcInput image must be canny edge detection.
[out]linesVector of 4 integer endpoints, where:
  • lines[i][0] is x1
  • lines[i][1] is y1
  • lines[i][2] is x2
  • lines[i][3] is y2.
 

Example:

original image input image (canny edge) output image
sudoku.jpg
threshold_sudoku_result.png
hough_lines.jpg
See also
vz::Imagination::EMatType::kHoughLines

Referenced by vz::Imagination::create_hough_lines_and_angles().

Here is the caller graph for this function:

◆ rotate()

cv::Mat vz::rotate ( const cv::Mat &  src,
double  degrees 
)

Rotate an image an arbitrary number of degrees around the exact center of the image.

The image may be extended to ensure it isn't truncated during the rotation. New areas will be filled in as black.

Mathematical degrees are used, meaning the rotation is performed counter-clockwise. Specifying negative degrees will result in a clockwise rotation. Angles greater than 360.0 and lesser than -360.0 are valid, and are automatically normalized to 0-360.

Note
This function has optimizations to deal with rotations for exact multiples of 90.0 degrees (..., -180, -90, 0, 90, 180, ...).

Example:

cv::Mat dst = vz::rotate(src, 45.0);
// which is equivalent to:
dst = vz::rotate(src, -315.0);

 

input image output image
capture.jpg
capture_rotate_45_degrees.jpg
Exceptions
std::invalid_argumentif the image is empty

Referenced by vz::Imagination::get().

Here is the caller graph for this function:

◆ resize() [1/2]

cv::Mat vz::resize ( const cv::Mat &  src,
int  width,
int  height = 0 
)

Resize the given image, while maintaining the original aspect ratio.

Either the width or the height must be specified as non-zero to indicate the desired image size. The other measurement will be calculated to keep the correct aspect ratio. If both the width and height have been specified, then it is up to the caller to maintain the correct aspect ratio.

See also
letterbox()
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif either the width or the height is negative
std::invalid_argumentif both width and hight are invalid

Referenced by vz::Imagination::create_mosaic(), letterbox(), vz::Imagination::resize(), and resize().

Here is the caller graph for this function:

◆ resize() [2/2]

cv::Mat vz::resize ( const cv::Mat &  src,
const double  scale 
)

Resize the given image, keeping the same aspect ratio.

A scale of 1.0 will return an image of the same size, while 0.5 will be 1/2 the size, and 2.0 will be twice as large as the original.

See also
letterbox()
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif the scale is less than zero

References resize().

Here is the call graph for this function:

◆ letterbox()

cv::Mat vz::letterbox ( const cv::Mat &  src,
int  width,
int  height,
const cv::Scalar &  colour = cv::Scalar(0, 0, 0) 
)

Resize the image to fit within the given dimensions and apply a border to pad the size until the desired size is achieved.

The aspect ratio will be maintained. If the image does not fit perfectly within the given dimensions, apply letterboxing (black bars on top and bottom or left and right sides) to achieve the desired final dimensions. Default colour for the letterboxing is black.

Example:

cv::Mat dst = vz::letterbox(src, 320, 200);

 

input image output image
capture.jpg
letterbox_320x200.jpg
See also
resize()
Exceptions
std::invalid_argumentif the image is empty
std::invalid_argumentif either the width or the height is less than 1

References letterbox(), and resize().

Referenced by letterbox().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_DoG()

cv::Mat vz::apply_DoG ( const cv::Mat &  src,
const double  k = 1.6,
const double  sigma = 0.5,
const double  gamma = 1.0 
)

Perform 2 Gaussian blurs of different size, and subtract the 2nd from the 1st.

See also
apply_DoG_threshold()
Exceptions
std::invalid_argumentif the image is empty

References to_greyscale().

Referenced by apply_DoG_threshold(), and vz::Imagination::get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_DoG_threshold()

cv::Mat vz::apply_DoG_threshold ( const cv::Mat &  src,
const double  k = 200.0,
const double  sigma = 0.5,
const double  gamma = 1.0 
)

Obtain the DoG (Difference of Gaussian) by calling apply_DoG(), then find a threshold image from the result.

References apply_DoG().

Referenced by vz::Imagination::create_threshold().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_contours_to_rotated_rects()

vz::VRotatedRects vz::convert_contours_to_rotated_rects ( const VContours contours)

Convert all of the contours to rotated rectangles.