correct for rotation and axes for greyscale
This commit is contained in:
parent
2ba4528c1d
commit
e43f8b0efb
|
@ -67,7 +67,8 @@ fn main() -> anyhow::Result<()> {
|
||||||
let mut out = v4l::Device::with_path(output)?;
|
let mut out = v4l::Device::with_path(output)?;
|
||||||
// To find the fourcc code, use v4l2-ctl --list-formats-out /dev/video0
|
// To find the fourcc code, use v4l2-ctl --list-formats-out /dev/video0
|
||||||
// (or read the source :)
|
// (or read the source :)
|
||||||
let format = v4l::Format::new(WIDTH as u32, HEIGHT as u32, fourcc);
|
// flip axes
|
||||||
|
let format = v4l::Format::new(HEIGHT as u32, WIDTH as u32, fourcc);
|
||||||
Output::set_format(&out, &format)?;
|
Output::set_format(&out, &format)?;
|
||||||
|
|
||||||
// Setup Capture
|
// Setup Capture
|
||||||
|
@ -105,13 +106,16 @@ fn main() -> anyhow::Result<()> {
|
||||||
// swap the bytes, we are using LE, not BE, 16 bit grayscale
|
// swap the bytes, we are using LE, not BE, 16 bit grayscale
|
||||||
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
||||||
for i in 0..FRAME_LEN / 2 {
|
for i in 0..FRAME_LEN / 2 {
|
||||||
|
let x = i % WIDTH;
|
||||||
|
let y = (i / WIDTH) % HEIGHT;
|
||||||
let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]);
|
let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]);
|
||||||
if greyscale {
|
if greyscale {
|
||||||
if args.temperature {
|
if args.temperature {
|
||||||
pixel = pixel_to_celcius(pixel);
|
pixel = pixel_to_celcius(pixel);
|
||||||
}
|
}
|
||||||
let pixel_swapped = pixel.to_le_bytes();
|
let pixel_swapped = pixel.to_le_bytes();
|
||||||
swapped[i * 2..i * 2 + 2].copy_from_slice(&pixel_swapped);
|
let out_i = ((HEIGHT - 1 - y) + (WIDTH - 1 - x) * HEIGHT) * 2;
|
||||||
|
swapped[out_i..out_i + 2].copy_from_slice(&pixel_swapped);
|
||||||
} else {
|
} else {
|
||||||
pixel = pixel_to_celcius(pixel);
|
pixel = pixel_to_celcius(pixel);
|
||||||
let cutoff = args.red_cutoff.unwrap();
|
let cutoff = args.red_cutoff.unwrap();
|
||||||
|
@ -122,7 +126,8 @@ fn main() -> anyhow::Result<()> {
|
||||||
};
|
};
|
||||||
let g = frame[i * 2];
|
let g = frame[i * 2];
|
||||||
let b = frame[i * 2 + 1];
|
let b = frame[i * 2 + 1];
|
||||||
swapped[i * 4..i * 4 + 4].copy_from_slice(&[0, r, g, b]);
|
let out_i = (y + x * HEIGHT) * 2;
|
||||||
|
swapped[out_i..out_i + 4].copy_from_slice(&[0, r, g, b]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.write_all(&swapped[..])?;
|
out.write_all(&swapped[..])?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user