Video search

This commit is contained in:
2024-05-30 15:58:31 +01:00
parent 74d91d52e5
commit 3257521068
5 changed files with 321 additions and 132 deletions
+13 -11
View File
@@ -12,18 +12,20 @@ pub struct InferenceServerConfig {
pub embedding_size: usize,
}
pub fn resize_for_embed_sync<T: Borrow<DynamicImage> + Send + 'static>(config: InferenceServerConfig, image: T) -> Result<Vec<u8>> {
let new = image.borrow().resize(
config.image_size.0,
config.image_size.1,
FilterType::Lanczos3
);
let mut buf = Vec::new();
let mut csr = Cursor::new(&mut buf);
new.write_to(&mut csr, ImageFormat::Png)?;
Ok::<Vec<u8>, anyhow::Error>(buf)
}
pub async fn resize_for_embed<T: Borrow<DynamicImage> + Send + 'static>(config: InferenceServerConfig, image: T) -> Result<Vec<u8>> {
let resized = tokio::task::spawn_blocking(move || {
let new = image.borrow().resize(
config.image_size.0,
config.image_size.1,
FilterType::Lanczos3
);
let mut buf = Vec::new();
let mut csr = Cursor::new(&mut buf);
new.write_to(&mut csr, ImageFormat::Png)?;
Ok::<Vec<u8>, anyhow::Error>(buf)
}).await??;
let resized = tokio::task::spawn_blocking(move || resize_for_embed_sync(config, image)).await??;
Ok(resized)
}