This commit is contained in:
35
docs/snippets/rust/ocr/ocr_elements.md
Normal file
35
docs/snippets/rust/ocr/ocr_elements.md
Normal file
@@ -0,0 +1,35 @@
|
||||
```rust title="Rust"
|
||||
use kreuzberg::{extract_file, ExtractionConfig, OcrConfig};
|
||||
use kreuzberg::types::OcrElementConfig;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> kreuzberg::Result<()> {
|
||||
let config = ExtractionConfig {
|
||||
ocr: Some(OcrConfig {
|
||||
backend: "paddleocr".to_string(),
|
||||
language: "en".to_string(),
|
||||
element_config: Some(OcrElementConfig {
|
||||
include_elements: true,
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = extract_file("scanned.pdf", None, &config).await?;
|
||||
|
||||
if let Some(elements) = &result.ocr_elements {
|
||||
for element in elements {
|
||||
println!("Text: {}", element.text);
|
||||
println!("Confidence: {:.2}", element.confidence.recognition);
|
||||
println!("Geometry: {:?}", element.geometry);
|
||||
if let Some(rotation) = &element.rotation {
|
||||
println!("Rotation: {}°", rotation.angle_degrees);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user