This commit is contained in:
parent
13dfafebbc
commit
5576015929
14
.drone.yml
Normal file
14
.drone.yml
Normal file
@ -0,0 +1,14 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: rust
|
||||
commands:
|
||||
- cargo build --verbose --all
|
||||
|
||||
- name: fmt-check
|
||||
image: rust
|
||||
commands:
|
||||
- rustup component add rustfmt
|
||||
- cargo fmt --all -- --check
|
12
bin/run.rs
12
bin/run.rs
@ -1,22 +1,20 @@
|
||||
use dispmap::compute;
|
||||
|
||||
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let mut args = std::env::args();
|
||||
let _ = args.next();
|
||||
|
||||
|
||||
let left_path = args.next().unwrap();
|
||||
let right_path = args.next().unwrap();
|
||||
|
||||
println!("disparity for {} {}", left_path, right_path);
|
||||
|
||||
let left = image::open(left_path)?.to_rgb8();
|
||||
let left = image::open(left_path)?.to_rgb8();
|
||||
let right = image::open(right_path)?.to_rgb8();
|
||||
|
||||
let disp = compute(&left, &right);
|
||||
|
||||
disp.save("disp.png")?;
|
||||
|
||||
Ok(())
|
||||
disp.save("disp.png")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
47
src/lib.rs
47
src/lib.rs
@ -1,4 +1,4 @@
|
||||
use image::{buffer::PixelsMut, GrayImage, Luma, RgbImage, GenericImageView, Rgb};
|
||||
use image::{buffer::PixelsMut, GenericImageView, GrayImage, Luma, Rgb, RgbImage};
|
||||
|
||||
fn diff(left: Rgb<u8>, right: Rgb<u8>) -> i32 {
|
||||
let r = (left[0] as i32 - right[0] as i32).abs();
|
||||
@ -22,7 +22,7 @@ fn match_box(left: [Rgb<u8>; 16], right: [Rgb<u8>; 16]) -> i32 {
|
||||
|
||||
fn px(img: &RgbImage, x: u32, y: u32) -> Rgb<u8> {
|
||||
if x >= img.width() || y >= img.height() {
|
||||
return Rgb([0,0,0]);
|
||||
return Rgb([0, 0, 0]);
|
||||
}
|
||||
|
||||
img.get_pixel(x, y).clone()
|
||||
@ -34,18 +34,41 @@ fn match_pixels(left: &RgbImage, right: &RgbImage, x: u32, y: u32, j: u32) -> i3
|
||||
|
||||
match_box(
|
||||
[
|
||||
px(left, lx, y ), px(left, lx + 1, y ), px(left, lx + 2, y ), px(left, lx + 3, y ),
|
||||
px(left, lx, y + 1), px(left, lx + 1, y + 1), px(left, lx + 2, y + 1), px(left, lx + 3, y + 1),
|
||||
px(left, lx, y + 2), px(left, lx + 1, y + 2), px(left, lx + 2, y + 2), px(left, lx + 3, y + 2),
|
||||
px(left, lx, y + 3), px(left, lx + 1, y + 3), px(left, lx + 2, y + 3), px(left, lx + 3, y + 3),
|
||||
px(left, lx, y),
|
||||
px(left, lx + 1, y),
|
||||
px(left, lx + 2, y),
|
||||
px(left, lx + 3, y),
|
||||
px(left, lx, y + 1),
|
||||
px(left, lx + 1, y + 1),
|
||||
px(left, lx + 2, y + 1),
|
||||
px(left, lx + 3, y + 1),
|
||||
px(left, lx, y + 2),
|
||||
px(left, lx + 1, y + 2),
|
||||
px(left, lx + 2, y + 2),
|
||||
px(left, lx + 3, y + 2),
|
||||
px(left, lx, y + 3),
|
||||
px(left, lx + 1, y + 3),
|
||||
px(left, lx + 2, y + 3),
|
||||
px(left, lx + 3, y + 3),
|
||||
],
|
||||
[
|
||||
px(right, rx, y ), px(right, rx + 1, y ), px(right, rx + 2, y ), px(right, rx + 3, y ),
|
||||
px(right, rx, y + 1), px(right, rx + 1, y + 1), px(right, rx + 2, y + 1), px(right, rx + 3, y + 1),
|
||||
px(right, rx, y + 2), px(right, rx + 1, y + 2), px(right, rx + 2, y + 2), px(right, rx + 3, y + 2),
|
||||
px(right, rx, y + 3), px(right, rx + 1, y + 3), px(right, rx + 2, y + 3), px(right, rx + 3, y + 3),
|
||||
]
|
||||
|
||||
px(right, rx, y),
|
||||
px(right, rx + 1, y),
|
||||
px(right, rx + 2, y),
|
||||
px(right, rx + 3, y),
|
||||
px(right, rx, y + 1),
|
||||
px(right, rx + 1, y + 1),
|
||||
px(right, rx + 2, y + 1),
|
||||
px(right, rx + 3, y + 1),
|
||||
px(right, rx, y + 2),
|
||||
px(right, rx + 1, y + 2),
|
||||
px(right, rx + 2, y + 2),
|
||||
px(right, rx + 3, y + 2),
|
||||
px(right, rx, y + 3),
|
||||
px(right, rx + 1, y + 3),
|
||||
px(right, rx + 2, y + 3),
|
||||
px(right, rx + 3, y + 3),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user