View Source Evision Example - Stitching Multiple Photos into A Panorama Photo
# set `EVISION_PREFER_PRECOMPILED` to `false`
# if you prefer `:evision` to be compiled from source
# note that to compile from source, you may need at least 1GB RAM
# System.put_env("EVISION_PREFER_PRECOMPILED", "false")
Mix.install([
{:evision, "~> 0.1.20"},
{:kino, "~> 0.7"},
{:req, "~> 0.3"}
])
:ok
define-some-helper-functions
Define Some Helper Functions
defmodule Helper do
def download!(url, save_as, overwrite? \\ false) do
unless File.exists?(save_as) do
Req.get!(url, http_errors: :raise, output: save_as, cache: not overwrite?)
end
:ok
end
end
{:module, Helper, <<70, 79, 82, 49, 0, 0, 10, ...>>, {:download!, 3}}
download-test-images
Download Test Images
# change to the file's directory
# or somewhere you have write permission
File.cd!(__DIR__)
# https://github.com/opencv/opencv_extra/tree/4.x/testdata/stitching
Helper.download!(
"https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/stitching/a1.png",
"a1.png"
)
Helper.download!(
"https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/stitching/a2.png",
"a2.png"
)
Helper.download!(
"https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/stitching/a3.png",
"a3.png"
)
:ok
stitching
Stitching
alias Evision, as: Cv
a1 = Cv.imread("./a1.png")
a2 = Cv.imread("./a2.png")
a3 = Cv.imread("./a3.png")
sticher = Cv.Stitcher.create()
{status_code, result} = Cv.Stitcher.stitch(sticher, [a1, a2, a3])
0 = status_code
# status_code should be 0 (OK),
# for other status_code, please refer to https://github.com/opencv/opencv/blob/4.5.4/modules/stitching/include/opencv2/stitching.hpp#L152
Cv.imencode(".png", result)
|> Kino.Image.new(:png)