The setProcessor method configures how K21 processes captured images or video frames. It supports both OCR (Optical Character Recognition) and Vision-based processing, with customizable settings for each.

Usage

const k21 = new K21();

// Use default OCR settings
k21.setProcessor();

// Custom OCR configuration
k21.setProcessor({
  processingType: "OCR",
  ocrConfig: {
    ocrModel: "tesseract",
    boundingBoxes: true
  }
});

ProcessorConfig Interface

The main configuration object accepts the following parameters:

ParameterTypeDefaultDescription
processingTypestring'OCR'Type of processing to apply (“OCR” or “Vision”)
ocrConfigOcrConfigSee belowConfiguration for OCR-based processing
visionConfigVisionConfigSee belowConfiguration for vision-based processing

OcrConfig Interface

Configuration options for OCR processing:

ParameterTypeDefaultDescription
ocrModelstring'default'OCR model to use (e.g., “tesseract”, “native”, “default”)
boundingBoxesbooleantrueWhether to include text bounding box coordinates in results
dpinumber-Dots per inch for image processing. Higher values for smaller text
psmnumber-Page Segmentation Mode - controls how the page is analyzed
oemnumber-OCR Engine Mode - controls which engine(s) are used

VisionConfig Interface

Configuration options for vision-based processing:

ParameterTypeDefaultDescription
urlstring-Base URL for the vision API endpoint
apiKeystring-Authentication key for the vision API
modelstring-Model identifier to use for vision processing
promptstring-Optional prompt to guide the vision model’s analysis

Default Values

If you call setProcessor() without any configuration, these default values will be used:

{
  processingType: 'OCR',
  ocrConfig: {
    ocrModel: 'default',
    boundingBoxes: true
  }
}

Examples

Basic OCR Processing

k21.setProcessor({
  processingType: "OCR"
});

Advanced OCR Configuration

k21.setProcessor({
  processingType: "OCR",
  ocrConfig: {
    ocrModel: "tesseract",
    boundingBoxes: true,
    dpi: 300,
    psm: 3,
    oem: 1
  }
});

Vision API Processing

k21.setProcessor({
  processingType: "Vision",
  visionConfig: {
    url: "https://api.vision-service.com/v1",
    apiKey: "your-api-key",
    model: "gpt-4-vision",
    prompt: "Describe the main activities visible in this screen capture"
  }
});

Mixed Processing (TBD)

// Coming soon: Support for combining OCR and Vision processing
// This feature is currently under development

Important Notes

  1. The processingType determines which configuration will be used (ocrConfig or visionConfig)
  2. When using vision-based processing, make sure you have valid API credentials
  3. OCR settings like psm and oem are specific to certain OCR engines (like Tesseract)
  4. Higher DPI values can improve accuracy for small text but may increase processing time
  5. Vision API processing may incur additional costs depending on your provider