use thiserror::Error;
pub type Result<T> = std::result::Result<T, OpenCvError>;
#[derive(Debug, Error)]
pub enum VideoCaptureError {
#[error("failed to open video source: {path}")]
OpenFailed {
path: String,
},
#[error("video stream is not open")]
NotOpen,
#[error("failed to read frame")]
ReadFailed,
#[error("end of stream")]
EndOfStream,
#[error("unsupported backend")]
UnsupportedBackend,
#[error("seek failed")]
SeekFailed,
#[error("invalid fps property")]
InvalidFps,
#[error("backend error: {0}")]
Backend(String),
}
#[derive(Debug, Error)]
pub enum ImageEncodingError {
#[error("encoding failed for kind {kind}")]
EncodeFailed {
kind: &'static str,
},
#[error("unsupported pixel format: {0:?}")]
UnsupportedPixelFormat(crate::PixelFormat),
#[error("backend error: {0}")]
Backend(String),
}
#[derive(Debug, Error)]
pub enum ImageOpsError {
#[error("dimension mismatch: lhs {lhs:?}, rhs {rhs:?}")]
DimensionMismatch {
lhs: (u32, u32, u32),
rhs: (u32, u32, u32),
},
#[error("unsupported pixel format: {0:?}")]
UnsupportedPixelFormat(crate::PixelFormat),
#[error("unsupported conversion: {src:?} -> {dst:?}")]
UnsupportedConversion {
src: crate::PixelFormat,
dst: crate::PixelFormat,
},
#[error("invalid parameter: {0}")]
InvalidParameter(&'static str),
#[error("empty input")]
EmptyInput,
#[error("backend error: {0}")]
Backend(String),
}
#[derive(Debug, Error)]
pub enum OpenCvError {
#[error(transparent)]
VideoCapture(#[from] VideoCaptureError),
#[error(transparent)]
ImageEncoding(#[from] ImageEncodingError),
#[error(transparent)]
ImageOps(#[from] ImageOpsError),
}