This commit is contained in:
19
docs/snippets/r/ocr/cloud_ocr_backend.md
Normal file
19
docs/snippets/r/ocr/cloud_ocr_backend.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
custom_ocr_backend <- function(image_path, language) {
|
||||
cat(sprintf("Processing image: %s\n", image_path))
|
||||
return(sprintf("Extracted text from %s", image_path))
|
||||
}
|
||||
|
||||
register_ocr_backend("custom_cloud", custom_ocr_backend)
|
||||
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "custom_cloud", language = "en")
|
||||
)
|
||||
|
||||
json <- extract_file_sync("document.pdf", "application/pdf", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
cat(sprintf("Custom backend result: %d chars\n", nchar(result$content)))
|
||||
```
|
||||
16
docs/snippets/r/ocr/image_extraction.md
Normal file
16
docs/snippets/r/ocr/image_extraction.md
Normal file
@@ -0,0 +1,16 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "tesseract", language = "eng")
|
||||
)
|
||||
|
||||
json <- extract_file_sync("scan.png", "image/png", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat("Image extraction via OCR:\n")
|
||||
cat(sprintf("Content length: %d characters\n", nchar(result$content)))
|
||||
cat(sprintf("Mime type: %s\n", result$mime_type))
|
||||
cat(sprintf("Detected language: %s\n", result$detected_language))
|
||||
```
|
||||
16
docs/snippets/r/ocr/image_preprocessing.md
Normal file
16
docs/snippets/r/ocr/image_preprocessing.md
Normal file
@@ -0,0 +1,16 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "tesseract", language = "eng"),
|
||||
enable_quality_processing = TRUE
|
||||
)
|
||||
|
||||
json <- extract_file_sync("scan.png", "image/png", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Quality: %.2f, Length: %d\n",
|
||||
result$quality_score %||% 0,
|
||||
nchar(result$content)))
|
||||
```
|
||||
16
docs/snippets/r/ocr/ocr_easyocr.md
Normal file
16
docs/snippets/r/ocr/ocr_easyocr.md
Normal file
@@ -0,0 +1,16 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
# Note: EasyOCR backend requires Python to be installed
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "easyocr", language = "en")
|
||||
)
|
||||
|
||||
json <- extract_file_sync("document.pdf", "application/pdf", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat("EasyOCR extraction:\n")
|
||||
cat(sprintf("Content length: %d characters\n", nchar(result$content)))
|
||||
cat(sprintf("Detected language: %s\n", result$detected_language))
|
||||
```
|
||||
23
docs/snippets/r/ocr/ocr_elements.md
Normal file
23
docs/snippets/r/ocr/ocr_elements.md
Normal file
@@ -0,0 +1,23 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
# Enable structured OCR elements alongside text extraction
|
||||
config <- list(
|
||||
ocr = list(
|
||||
backend = "paddleocr",
|
||||
language = "en",
|
||||
element_config = list(include_elements = TRUE)
|
||||
)
|
||||
)
|
||||
|
||||
json <- extract_file_sync("scanned.pdf", "application/pdf", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
if (!is.null(result$ocr_elements)) {
|
||||
for (element in result$ocr_elements) {
|
||||
cat(sprintf("Text: %s\n", element$text))
|
||||
cat(sprintf("Confidence: %.2f\n", element$confidence$recognition))
|
||||
cat("\n")
|
||||
}
|
||||
}
|
||||
```
|
||||
17
docs/snippets/r/ocr/ocr_extraction.md
Normal file
17
docs/snippets/r/ocr/ocr_extraction.md
Normal file
@@ -0,0 +1,17 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
# Configure Tesseract OCR
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "tesseract", language = "eng")
|
||||
)
|
||||
|
||||
# Extract text from a scanned image
|
||||
json <- extract_file_sync("scan.png", "image/png", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Extracted %d characters\n", nchar(result$content)))
|
||||
cat("Content preview:\n")
|
||||
cat(substr(result$content, 1, 200))
|
||||
```
|
||||
12
docs/snippets/r/ocr/ocr_force_all_pages.md
Normal file
12
docs/snippets/r/ocr/ocr_force_all_pages.md
Normal file
@@ -0,0 +1,12 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
config <- list(force_ocr = TRUE)
|
||||
|
||||
json <- extract_file_sync("multipage_document.pdf", "application/pdf", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Total pages: %d\n", length(result$pages)))
|
||||
cat(sprintf("Content extracted via OCR: %d characters\n", nchar(result$content)))
|
||||
cat(sprintf("Detected language: %s\n", result$detected_language))
|
||||
```
|
||||
18
docs/snippets/r/ocr/ocr_multi_language.md
Normal file
18
docs/snippets/r/ocr/ocr_multi_language.md
Normal file
@@ -0,0 +1,18 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
# Configure multi-language OCR (English, French, German)
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "tesseract", language = "eng+fra+deu")
|
||||
)
|
||||
|
||||
# Extract from a multilingual document
|
||||
json <- extract_file_sync("multilingual.png", "image/png", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Detected language: %s\n", result$detected_language))
|
||||
cat(sprintf("Extracted %d characters\n", nchar(result$content)))
|
||||
cat("Content preview:\n")
|
||||
cat(substr(result$content, 1, 200))
|
||||
```
|
||||
18
docs/snippets/r/ocr/ocr_paddleocr.md
Normal file
18
docs/snippets/r/ocr/ocr_paddleocr.md
Normal file
@@ -0,0 +1,18 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
# Configure PaddleOCR backend (defaults to mobile tier)
|
||||
config <- list(
|
||||
force_ocr = TRUE,
|
||||
ocr = list(backend = "paddle-ocr", language = "en")
|
||||
)
|
||||
|
||||
# Extract text from an image using PaddleOCR
|
||||
json <- extract_file_sync("document.jpg", "image/jpeg", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Extracted %d characters\n", nchar(result$content)))
|
||||
cat(sprintf("MIME type: %s\n", result$mime_type))
|
||||
cat("Content preview:\n")
|
||||
cat(substr(result$content, 1, 200))
|
||||
```
|
||||
Reference in New Issue
Block a user