benchmarks comparing the rust image processing ecosystem
opencv affine
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | affine.svg | 2 | ||||
| -rw-r--r-- | benches/affine.rs | 64 |
3 files changed, 65 insertions, 2 deletions
@@ -13,6 +13,7 @@ fimg = { version = "0.4.23", features = ["text", "blur", "scale"] } iai = { git = "https://github.com/bend-n/iai", version = "0.1.1" } image = { version = "0.24.7", default-features = false, features = ["png"] } imageproc = { version = "0.23.0", default-features = false } +opencv = "0.86.1" resize = { version = "0.8.2", default-features = false, features = ["std"] } rgb = "0.8.37" umath = "0.0.7" @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="600" height="480"><path fill="#0d1117" d="M0 0h600v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 444h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 444h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 389.57h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 389.57h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 393.47)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 335.15h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 335.15h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 339.05)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 280.72h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 280.72h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 284.62)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 226.29h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 226.29h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 230.19)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 171.86h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 171.86h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 175.76)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 117.44h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 117.44h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 121.34)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 63.01h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 63.01h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 66.91)"><tspan> 1.4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M184.21 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(184.21 465.9)"><tspan>270 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M262.33 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(262.33 465.9)"><tspan>180 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M340.46 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(340.46 465.9)"><tspan>90 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M418.58 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(418.58 465.9)"><tspan>flip h</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M496.7 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(496.7 465.9)"><tspan>flip v</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M106.09 63.01V444h468.73V63.01H106.09Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(498.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M508.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M508.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M158.17 444h26.05V215.73h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M158.17 444V215.74h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M236.29 444h26.05V266.61h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M236.29 444V266.62h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M314.41 444h26.06V171.61h-26.06z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M314.41 444V171.62h26.05V444h-26.05Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M392.54 444h26.05V298.25h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M392.54 444V298.26h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M470.66 444h26.05V298.25h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M470.66 444V298.26h26.04V444h-26.04Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(498.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M508.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M508.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M184.21 444h26.05V99.05h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M184.21 444V99.06h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M262.33 444h26.05V138.09h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M262.33 444V138.1h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M340.46 444h26.05V131.05h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M340.46 444V131.06h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M418.58 444h26.05V138.1h-26.05z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M418.58 444V138.11h26.04V444h-26.04Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M496.7 444h26.05V162.09H496.7z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M496.7 444V162.1h26.04V444H496.7Z"/></g><path fill="none" stroke="#E6EDF3" d="M106.09 63.01V444h468.73V63.01H106.09Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(340.45 32.86)"><tspan>affine</tspan></text></svg>
\ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" width="600" height="480"><path fill="#0d1117" d="M0 0h600v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 444h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 444h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 389.57h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 389.57h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 393.47)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 335.15h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 335.15h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 339.05)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 280.72h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 280.72h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 284.62)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 226.29h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 226.29h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 230.19)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">8</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 171.86h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 171.86h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 175.76)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 117.44h333.86m126.48 0h8.39" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 117.44h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 121.34)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M106.09 63.01h468.73" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M106.09 63.01h9m459.73 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(97.7 66.91)"><tspan> 1.4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M184.21 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(184.21 465.9)"><tspan>270 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M262.33 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(262.33 465.9)"><tspan>180 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M340.46 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(340.46 465.9)"><tspan>90 degrees</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M418.58 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(418.58 465.9)"><tspan>flip h</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M496.7 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(496.7 465.9)"><tspan>flip v</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M106.09 63.01V444h468.73V63.01H106.09Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(498.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M508.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M508.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M154.92 444h19.54V219.5h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M154.92 444V219.51h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M233.04 444h19.54V274.36h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M233.04 444V274.37h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M311.16 444h19.54V171.61h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M311.16 444V171.62h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M389.28 444h19.54V298.25h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M389.28 444V298.26h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M467.4 444h19.54V298.25H467.4z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M467.4 444V298.26h19.53V444H467.4Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(498.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M508.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M508.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M174.45 444h19.54V98.81h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M174.45 444V98.82h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M252.57 444h19.54V137.86h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M252.57 444V137.87h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M330.69 444h19.54V130.82h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M330.69 444V130.83h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M408.81 444h19.54V137.86h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M408.81 444V137.87h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M486.93 444h19.54V161.87h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M486.93 444V161.88h19.53V444h-19.53Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(498.69 129.06)"><tspan>opencv</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M508.48 129.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M508.48 129.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M193.98 444h19.54V321.17h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M193.98 444V321.18h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M272.1 444h19.54V227.46H272.1z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M272.1 444V227.47h19.53V444H272.1Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M350.22 444h19.54V162.55h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M350.22 444V162.56h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M428.34 444h19.54V227.46h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M428.34 444V227.47h19.53V444h-19.53Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M506.46 444H526V288.01h-19.54z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M506.46 444V288.02h19.53V444h-19.53Z"/></g><path fill="none" stroke="#E6EDF3" d="M106.09 63.01V444h468.73V63.01H106.09Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(340.45 32.86)"><tspan>affine</tspan></text></svg>
\ No newline at end of file diff --git a/benches/affine.rs b/benches/affine.rs index 9daa7d3..99e0f13 100644 --- a/benches/affine.rs +++ b/benches/affine.rs @@ -1,6 +1,8 @@ -//! note that imageproc doesnt support in-place transformations. +#![feature(array_chunks)] +//! note that image doesnt support in-place transformations. use fimg::Image; use image::{imageops, RgbImage}; +use opencv::{core::CV_8UC3, prelude::*}; const SIZE: u32 = 5424; // dont have to alloc, but it would be less fair. @@ -8,6 +10,31 @@ pub fn fimg() -> Image<Vec<u8>, 3> { Image::build(SIZE, SIZE).buf(iai::black_box(include_bytes!("../data.imgbuf").to_vec())) } +pub fn opencv() -> Mat { + opencv::core::set_num_threads(1).unwrap(); + let mut data = iai::black_box(include_bytes!("../data.imgbuf").to_vec()) + .array_chunks::<3>() + .flat_map(|&[r, g, b]| [b, g, r]) + .collect::<Vec<_>>(); + let mat = unsafe { + Mat::new_size_with_data_def( + opencv::core::Size_ { + width: 5424, + height: 5424, + }, + CV_8UC3, + data.as_mut_ptr() as *mut core::ffi::c_void, + ) + .unwrap() + }; + std::mem::forget(data); + mat +} + +pub fn o_opencv() -> Mat { + unsafe { Mat::new_rows_cols(SIZE as i32, SIZE as i32, CV_8UC3).unwrap() } +} + pub fn ipimg() -> RgbImage { RgbImage::from_raw( SIZE, @@ -25,6 +52,12 @@ pub fn rot_90_imgproc() { iai::black_box(imageops::rotate90(&ipimg())); } +pub fn rot_90_opencv() { + let mut o = o_opencv(); + opencv::core::rotate(&opencv(), &mut o, 0).unwrap(); + iai::black_box(o); +} + pub fn rot_180_fimg() { iai::black_box(fimg().cloner().rot_180()); } @@ -33,6 +66,12 @@ pub fn rot_180_imgproc() { iai::black_box(imageops::rotate180(&ipimg())); } +pub fn rot_180_opencv() { + let mut o = o_opencv(); + opencv::core::rotate(&opencv(), &mut o, 1).unwrap(); + iai::black_box(o); +} + pub fn rot_270_fimg() { iai::black_box(unsafe { fimg().cloner().rot_270() }); } @@ -41,6 +80,12 @@ pub fn rot_270_imgproc() { iai::black_box(imageops::rotate270(&ipimg())); } +pub fn rot_270_opencv() { + let mut o = o_opencv(); + opencv::core::rotate(&opencv(), &mut o, -1).unwrap(); + iai::black_box(o); +} + pub fn flip_h_fimg() { iai::black_box(fimg().cloner().flip_h()); } @@ -49,6 +94,12 @@ pub fn flip_h_imgproc() { iai::black_box(imageops::flip_horizontal(&ipimg())); } +pub fn flip_h_opencv() { + let mut o = o_opencv(); + opencv::core::flip(&opencv(), &mut o, 1).unwrap(); + iai::black_box(o); +} + pub fn flip_v_fimg() { iai::black_box(fimg().cloner().flip_h()); } @@ -57,15 +108,26 @@ pub fn flip_v_imgproc() { iai::black_box(imageops::flip_vertical(&ipimg())); } +pub fn flip_v_opencv() { + let mut o = o_opencv(); + opencv::core::flip(&opencv(), &mut o, 0).unwrap(); + iai::black_box(o); +} + iai::main!( rot_90_fimg, rot_90_imgproc, + rot_90_opencv, rot_180_fimg, rot_180_imgproc, + rot_180_opencv, rot_270_fimg, rot_270_imgproc, + rot_270_opencv, flip_h_fimg, flip_h_imgproc, + flip_h_opencv, flip_v_fimg, flip_v_imgproc, + flip_v_opencv, ); |