Skip to main content

cv - Compare images (:cv_compare_image)

Declaration​

shapes, visualized = img:cv_compare_image(other_img[, options])

Parameters​

  • other_img
    Image object. The image to compare with

  • options
    Table

    Option fields
    {
    should_visualize = false | true, -- optional, whether to output visualization, default false
    approx_epsilon = integer_value, -- optional, contour approximation percentage of perimeter, simplifies complex contours, default 2
    }

Returns​

  • shapes
    Table. The list of difference shapes between the two images

    Shapes structure
    {
    { -- shape 1
    { -- vertex 1
    ["y"] = number_value,
    ["x"] = number_value,
    },
    { -- vertex 2
    ["y"] = number_value,
    ["x"] = number_value,
    },
    ...
    },
    { -- shape 2
    { -- vertex 1
    ["y"] = number_value,
    ["x"] = number_value,
    },
    { -- vertex 2
    ["y"] = number_value,
    ["x"] = number_value,
    },
    ...
    },
    ...
    }
  • visualized
    Image object. When options.should_visualize is true, this is the visualization image

Description​

Compare two images to find differences and return vertex lists of difference regions
The two images must have the same size

Example​

local cv = require("image.cv")
local img1 = image.load_file(XXT_SCRIPTS_PATH..'/1.png')
local img2 = image.load_file(XXT_SCRIPTS_PATH..'/2.png')
-- returns a list of shapes; may contain multiple shapes
local shapes, visimg = img1:cv_compare_image(img2)
nLog(shapes) -- print shapes
dialog():add_image(visimg):show() -- visualize difference image