Skip to main content

Overview

The Capture-id module is the legacy document capture solution that uses AI-powered detection to automatically capture ID documents with OCR data extraction. While still supported, consider using Capture-id&R or Capture-id&A for enhanced features and vendor-specific integrations.
This is a legacy module. For new implementations, consider using Capture-id&R (Regula) or Capture-id&A (Acuant) for enhanced features.

Key Features

  • AI-Powered Detection: Automatic ID detection and capture
  • Real-time Feedback: Visual guidance for document positioning
  • OCR Extraction: Extract text data from ID documents
  • Quality Checks: Built-in validation for blur and document quality
  • Multi-side Capture: Support for front and back capture
  • Customizable UI: Full customization of detection feedback and styling
  • No External Dependencies: Self-contained solution without third-party vendors

Hardware Requirements

  • Modern web browser with camera access
  • Device camera (mobile or desktop)
  • Stable internet connection
  • HTTPS protocol (required for camera access)
  • WebRTC support

Installation

npm install @fad-producto/fad-sdk

Implementation

1

Import SDK and Configure

Import the FAD SDK and set up your configuration:
import FadSDK from '@fad-producto/fad-sdk';

const TOKEN = 'YOUR_FAD_TOKEN';

const CONFIGURATION = {
  views: {
    instructions: false,
    preview: false,
  },
};
2

Customize Detection Legends

Set up real-time detection feedback messages:
const CONFIGURATION = {
  // ... previous config
  customization: {
    moduleCustomization: {
      legends: {
        title: 'ID Capture',
        detection: {
          noDocument: 'Place document in frame',
          goodDocument: 'Hold steady',
          bigDocument: 'Move away',
          smallDocument: 'Move closer',
          invalidBack: 'Show front side',
          invalidFront: 'Show back side',
          blurryDocument: 'Document unclear, hold steady',
        },
        subtitle: {
          front: 'Front',
          back: 'Back',
        },
        instruction: {
          front: 'ID Capture',
          back: 'ID Capture',
        },
      },
    },
  },
};
3

Customize Visual Styling

Configure the detection UI appearance:
const CONFIGURATION = {
  // ... previous config
  customization: {
    moduleCustomization: {
      style: {
        outerBackgroundColor: '#2b2b2b66',
        idDetectedOuterBackgroundColor: '#0a0a0ab3',
        detectionBorder: {
          initial: {
            color: '#FFFFFF',
            style: 'solid',
            width: '4px',
          },
          warning: {
            color: '#FFDC45',
            style: 'solid',
            width: '4px',
          },
          detected: {
            color: '#009895',
            style: 'solid',
            width: '4px',
          },
        },
        instruction: {
          initial: {
            backgroundColor: '#000000b5',
            color: '#FFFFFF',
          },
          warning: {
            backgroundColor: '#FFDC45B5',
            color: '#FFFFFF',
          },
          detected: {
            backgroundColor: '#009895',
            color: '#FFFFFF',
          },
        },
      },
    },
  },
};
4

Initialize SDK and Start Capture

Create the SDK instance and start the capture process:
async function initProcess() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA,
  };

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const captureIdResponse = await FAD_SDK.startCaptureId(CONFIGURATION);

    console.log('Process completed', captureIdResponse);

    // Access captured data
    const frontImage = captureIdResponse.data.image.front.data;
    const backImage = captureIdResponse.data.image.back?.data;
    const ocrData = captureIdResponse.data.ocr;

    // Display results
    displayResults(frontImage, backImage, ocrData);

  } catch (ex) {
    console.error('Process error:', ex);
    handleError(ex);
  } finally {
    FAD_SDK.end();
  }
}

Response Structure

{
  event: string,  // 'PROCESS_COMPLETED'
  data: {
    image: {
      front: {
        data: string,  // Base64 image of front side
      },
      back?: {
        data: string,  // Base64 image of back side (if applicable)
      }
    },
    ocr: {
      firstName: string,
      lastName: string,
      documentNumber: string,
      dateOfBirth: string,
      address: string,
      // ... additional fields based on document type
    }
  }
}

Error Handling

Handle errors using the SDK error constants:
if (ex.code === FadSDK.Errors.CaptureId.NOT_READABLE_CAMERA) {
  alert('Camera is being used by another application.');
}

Detection States

The module provides real-time feedback based on document detection state:
StateDescriptionBorder ColorAction
noDocumentNo document detectedWhitePlace document in frame
smallDocumentDocument too farWarningMove closer
bigDocumentDocument too closeWarningMove away
blurryDocumentDocument unclearWarningHold steady
goodDocumentReady to captureSuccessHold steady (auto-capture)
invalidFrontWrong side shownWarningShow correct side
invalidBackWrong side shownWarningShow correct side

Configuration Options

Control which screens are displayed:
views: {
  instructions: false,  // Hide instruction screen
  preview: false        // Hide preview screen
}
Disabling views creates a streamlined experience but removes user guidance.
Customize the frame border appearance:
detectionBorder: {
  initial: {
    color: '#FFFFFF',    // Default state
    style: 'solid',
    width: '4px',
  },
  warning: {
    color: '#FFDC45',    // Warning states (too close, too far, blur)
    style: 'solid',
    width: '4px',
  },
  detected: {
    color: '#009895',    // Good document detected
    style: 'solid',
    width: '4px',
  },
}
Customize the feedback message appearance:
instruction: {
  initial: {
    backgroundColor: '#000000b5',  // Semi-transparent black
    color: '#FFFFFF',
  },
  warning: {
    backgroundColor: '#FFDC45B5',  // Semi-transparent yellow
    color: '#FFFFFF',
  },
  detected: {
    backgroundColor: '#009895',    // Teal green
    color: '#FFFFFF',
  },
}
Override default asset paths:
pathDependencies: {
  imageDirectory: 'https://your-cdn.com/images',
  jsDirectory: 'https://your-cdn.com/js',
  images: {
    nativeCaptureInstruction: 'https://your-cdn.com/custom-instruction.png'
  }
}

Usage Examples

import FadSDK from '@fad-producto/fad-sdk';

async function captureId() {
  const FAD_SDK = new FadSDK(TOKEN, {
    environment: FadSDK.getFadEnvironments().UATHA,
  });

  try {
    const response = await FAD_SDK.startCaptureId({
      views: { instructions: false, preview: false }
    });

    return {
      frontImage: response.data.image.front.data,
      backImage: response.data.image.back?.data,
      ocrData: response.data.ocr,
    };
  } finally {
    FAD_SDK.end();
  }
}

Best Practices

Good Lighting

Instruct users to ensure adequate lighting for better detection and OCR accuracy.

Steady Hands

Encourage users to keep device and document steady during capture.

Clean Camera

Remind users to clean camera lens for clearer captures.

Flat Document

Ensure document is flat and fully visible within the frame.

Migration Guide

Planning to migrate from Capture-id? Review the migration guide for your chosen replacement module.

Migrating to Capture-id&R (Regula)

// Before (Capture-id)
const response = await FAD_SDK.startCaptureId(CONFIGURATION);

// After (Capture-id&R)
const response = await FAD_SDK.startRegula(
  REGULA_CREDENTIALS,
  FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
  true,  // idData
  true,  // idPhoto
  CONFIGURATION
);
Benefits:
  • Enhanced document authentication
  • More accurate OCR
  • Better fraud detection
  • Support for more document types

Migrating to Capture-id&A (Acuant)

// Before (Capture-id)
const response = await FAD_SDK.startCaptureId(CONFIGURATION);

// After (Capture-id&A)
const response = await FAD_SDK.startAcuant(
  ACUANT_CREDENTIALS,
  true,   // idData
  true,   // idPhoto
  true,   // manualCapture
  CONFIGURATION
);
Benefits:
  • Professional-grade verification
  • Better quality metrics
  • Enhanced security features
  • Comprehensive validation

Troubleshooting

  • Verify camera permissions are granted
  • Check if camera is used by another app
  • Ensure HTTPS is used
  • Test on different browsers
  • Improve lighting conditions
  • Ensure document is flat
  • Move document within optimal distance
  • Clean camera lens
  • Check network connectivity for model loading
  • Improve lighting
  • Ensure document is in focus
  • Hold device steady
  • Clean document surface
  • Check internet connection
  • Verify browser supports WebGL
  • Check browser console for errors
  • Ensure browser is up to date

Build docs developers (and LLMs) love