Skip to content

Commit

Permalink
Add output parser for dssim algo. (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Leonard <johanatan@gmail.com>
  • Loading branch information
jleonard-r7 and johanatan committed Nov 14, 2020
1 parent 9e73a86 commit b2251fe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/clj/kamera/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
(update :actual #(.getAbsolutePath %))))
normalisation-chain))

(def ^:private default-compare-parser #(last (re-find #"all: .* \((.*)\)" %1)))
(def ^:private compare-parsers
{"mae" default-compare-parser
"dssim" #(last (re-find #"all: (.*)" %1))})

(defn compare-images [^File expected
^File actual
{:keys [metric screenshot-directory normalisations]}
Expand Down Expand Up @@ -147,7 +152,7 @@
(.getAbsolutePath actual)
(.getAbsolutePath difference)]
opts)
mean-absolute-error (when-let [e (last (re-find #"all: .* \((.*)\)" stderr))]
metric (when-let [e ((get compare-parsers metric default-compare-parser) stderr)]
(read-string e))]

(merge-with concat
Expand All @@ -160,8 +165,8 @@
{:errors [(format "Error comparing images - ImageMagick exited with code %s \n stdout: %s \n stderr: %s"
exit-code stdout stderr)]})

(if mean-absolute-error
{:metric mean-absolute-error}
(if metric
{:metric metric}
{:errors [(format "Could not parse ImageMagick output\n stdout: %s \n stderr: %s"
stdout stderr)]}))))))

Expand Down

0 comments on commit b2251fe

Please sign in to comment.