This class is used to compare images and find/highlight differences. More...
#include <VzImgCmp.hpp>
Public Types | |
enum | Flags { kNone = 0x0000, kDiffOriginalSize = 0x0001, kDiffResized = 0x0002, kDiffColour = 0x0004, kDiffGreyscale = 0x0008, kThresholdTriangle = 0x0010, kThresholdOtsu = 0x0020, kAnnotateOverGrey = 0x0040, kAnnotateOverColour = 0x0080, kAnnotateAddRedBorder = 0x0100, kAnnotateAddGreenBorder = 0x0200, kDrawContour = 0x0400, kDrawRectangle = 0x0800 } |
Optional features flags. More... | |
Public Member Functions | |
ImgCmp () | |
Empty constructor. You must call set_master_image() before it can be used. More... | |
ImgCmp (cv::Mat mat) | |
Constructor. Automatically calls set_master_image() with the given cv::Mat image. More... | |
virtual | ~ImgCmp () |
Destructor. More... | |
virtual ImgCmp & | reset () |
Reset the object to a known state. More... | |
virtual std::string | version () const |
Get the version string. Similar to "1.0.0-1234" . More... | |
virtual ImgCmp & | set_flag (const Flags f, const bool verify=false) |
Set a feature flag. Optionally can be told to call verify_flags(). More... | |
virtual ImgCmp & | clear_flag (const Flags f, const bool verify=false) |
Set a feature flag. Optionally can be told to call verify_flags(). More... | |
virtual ImgCmp & | verify_flags () |
This knows about the groupings of the various flags and will ensure that incompatible flags are not set, and that at least 1 of each feature flag groups has been set. More... | |
virtual VStr | debug_save () |
Save all the images as .png files using semi-descriptive names for debug purposes. More... | |
virtual ImgCmp & | set_master_image (cv::Mat img) |
Set the master image against which all other images will be compared. More... | |
virtual size_t | compare (cv::Mat img) |
Compare the given image against the previously set master image. More... | |
virtual cv::Mat | annotate () |
Annotate the most recently compared image. More... | |
Public Attributes | |
vz::Imagination | master_original |
Original master image as set by set_master_image. More... | |
vz::Imagination | master_resized |
Master image reduced to 25% of the original size. More... | |
vz::Imagination | candy_original |
The target image which is compared against the original is called candy . More... | |
vz::Imagination | candy_resized |
The target image which is compared against the original, but resized to match master_resized. More... | |
double | resized_image_scale |
Scale to apply when resizing images. More... | |
cv::Mat | differences |
The differences between the master image and the most recent image after calling compare(). More... | |
cv::Mat | differences_threshold |
The differences converted to a binary mask using one of the thresholds. More... | |
vz::VContours | differences_contours |
The contours (each of which is a vector of points) from differences_threshold. More... | |
double | min_contour_area |
The minimum area a difference must occupy to be retained. Differences smaller than this will be ignored. Units if measurement is "square pixels". More... | |
int | dilate_and_erode |
The amount of dilation and erosion applied to differences_threshold. More... | |
cv::Mat | annotated_candy |
The target image which is compared against the original is called candy . More... | |
cv::Scalar | annotation_colour |
The colour that will be used to annotate the images and highlight the differences. More... | |
int | annotation_thickness |
The thickness of the lines used to annotate the images and highlight the differences. The default is 2 . More... | |
Flags | flags |
Optional flags. More... | |
Protected Member Functions | |
virtual ImgCmp & | diff_images () |
This is called by compare() to compute differences. More... | |
virtual ImgCmp & | get_contours () |
This is called by compare() to get the differences_contours. More... | |
This class is used to compare images and find/highlight differences.
There is a single master image against which other images are compared. The output is a combination of a threshold mask, a sequence of contours (the differences) and/or an annotated image.
Usual sequence of events:
enum vz::ImgCmp::Flags |
Optional features flags.
vz::ImgCmp::ImgCmp | ( | ) |
Empty constructor. You must call set_master_image() before it can be used.
vz::ImgCmp::ImgCmp | ( | cv::Mat | mat | ) |
Constructor. Automatically calls set_master_image() with the given cv::Mat
image.
|
virtual |
Destructor.
|
virtual |
Reset the object to a known state.
This is automatically called by the constructors, but is not called by set_master_image().
|
virtual |
Get the version string. Similar to "1.0.0-1234"
.
|
virtual |
Set a feature flag. Optionally can be told to call verify_flags().
|
virtual |
Set a feature flag. Optionally can be told to call verify_flags().
|
virtual |
This knows about the groupings of the various flags and will ensure that incompatible flags are not set, and that at least 1 of each feature flag groups has been set.
This is automatically called by some key API calls, such as compare().
|
virtual |
Save all the images as .png files using semi-descriptive names for debug purposes.
|
virtual |
Set the master image against which all other images will be compared.
The image is cloned prior to set_master_image()
returning, so the original cv::Mat
can be modified, reused, or destroyed without it causing any problems.
Once you've called set_master_image
() (either directly or via the class constructor that takes a cv::Mat
) then you may call compare().
std::invalid_argument | if the new master image seems to be invalid |
|
virtual |
Compare the given image against the previously set master image.
std::logic_error | if the master image has not yet been defined |
std::invalid_argument | if the new image seems to be invalid |
|
virtual |
Annotate the most recently compared image.
You must call compare() prior to this method. The annotated image will also be stored in annotated_candy.
|
protectedvirtual |
|
protectedvirtual |
This is called by compare() to get the differences_contours.
vz::Imagination vz::ImgCmp::master_original |
Original master image as set by set_master_image.
vz::Imagination vz::ImgCmp::master_resized |
Master image reduced to 25% of the original size.
vz::Imagination vz::ImgCmp::candy_original |
The target image which is compared against the original is called candy
.
vz::Imagination vz::ImgCmp::candy_resized |
The target image which is compared against the original, but resized to match master_resized.
double vz::ImgCmp::resized_image_scale |
Scale to apply when resizing images.
Default is 0.25, meaning resized image will be 1/4 the size of the original. If you change this value, you must call set_master_image() again to ensure that master_resized has been set correctly.
cv::Mat vz::ImgCmp::differences |
The differences between the master image and the most recent image after calling compare().
This image may be colour or greyscale (single channel) depending on whether kDiffColour or kDiffGreyscale has been set.
Starting with the example image,
cv::Mat vz::ImgCmp::differences_threshold |
The differences converted to a binary mask using one of the thresholds.
There are two threshold methods available, triangle (the default) and Otsu. There may be situations or configurations where Otsu gives better results than the traditional triangle method, though in my testing of the sample images I have on hand the traditional triangle method seems to work better.
Starting with the example image,
vz::VContours vz::ImgCmp::differences_contours |
The contours (each of which is a vector of points) from differences_threshold.
Each contour represents an important difference found when the image was compared against the master in compare().
double vz::ImgCmp::min_contour_area |
The minimum area a difference must occupy to be retained. Differences smaller than this will be ignored. Units if measurement is "square pixels".
int vz::ImgCmp::dilate_and_erode |
The amount of dilation and erosion applied to differences_threshold.
Default is 3. Set to zero to disable. Dilation and erosion determine how differences which are near to each other may be combined into a single difference. Without any dilation and erosion, differences are very sharp and stand out easily; each difference is interpreted independently. But differences that are very tiny may be ignored because they fall beneath the threshold of min_contour_area.
There needs to be a balance between having too much, and not enough.
Starting with the example image,
dilate_and_erode=0
dilate_and_erode=5
dilate_and_erode=10
cv::Mat vz::ImgCmp::annotated_candy |
The target image which is compared against the original is called candy
.
This is the annotated version, highlighting all of the differences. This image is only generated when annotate() is called.
Starting with the example image,
cv::Scalar vz::ImgCmp::annotation_colour |
The colour that will be used to annotate the images and highlight the differences.
The default colour is pure red.
"{0, 0, 255}"
while blue is "{255, 0, 0}"
. int vz::ImgCmp::annotation_thickness |
The thickness of the lines used to annotate the images and highlight the differences. The default is 2
.
Flags vz::ImgCmp::flags |
Optional flags.
Instead of accessing this member directly, please use set_flag() and clear_flag() which has additional logic to ensure conflicting features aren't set.