# Two Strong RC1 browser/POS integration

Release: `two-strong-rc1`. The SDK ZIP is published at
https://card-scanner-alpha.pages.dev/sdk/card-scanner-two-strong-rc1.zip.
Check its SHA-256 against `/sdk/release.json` and retain that file with your build.
The illustrated strategy guide is https://card-scanner-alpha.pages.dev/algorithms.html.

Unpack the ZIP into your own application's static `/scanner/` directory. Keep all
modules, `pkg/`, and licenses together. Serve JavaScript with a JavaScript content
type and `.wasm` as `application/wasm`. HTTPS is required for camera capture.
Importing the hosted SDK directly across origins does not work with the SDK's
same-origin Worker; self-host the bundle. Allow your worker/module/WASM resources
in your application's CSP and include the catalog origin in `connect-src`.

```js
import {BrowserScanner, TWO_STRONG_RC} from '/scanner/scanner.js';
const scanner = new BrowserScanner();
const config = await (await fetch('/scanner/config.json')).json();
await scanner.configure(config);

async function scanFrame(imageData) {
  const result = await scanner.process(imageData, TWO_STRONG_RC);
  if (result.match_state?.new_lock) {
    // Present result.matches (up to five distinct products) for POS review.
    // Retain result.cropRGBA (500 x 700 RGBA) with the saved scan if desired.
  }
  return result;
}
```

Use `getUserMedia({video:{facingMode:'environment'},audio:false})` and draw the
video to a canvas to obtain ImageData. Await each `scanFrame` call before the next;
the SDK rejects overlapping requests. Stop all MediaStream tracks on exit,
call `scanner.resetTracking()` after changing sources, and `scanner.close()` when
done. The SDK does not manage camera permission, history, duplicate suppression,
corrections, or POS inventory mutations. The included alpha demonstrates those
UI features. Handle errors and catalog-loading progress through `onprogress`.

Two Strong is now the SDK's default confirmation mode when callers enable
`holdMatches`. The exported `TWO_STRONG_RC` object also enables live stabilization,
held matches, the five-observation fallback, browser catalog guidance and motion
tracking with the evaluated 1500 ms discovery budget. For photos, override
`{...TWO_STRONG_RC,holdMatches:false,stabilize:false}`. For an ordinary five-frame
control use `{...TWO_STRONG_RC,confirmation:'off'}`. Additional explicit research
modes are `strict-one`, `strict-three`, `span-quality`, and `sequential`.

The bundled `config.json` points to the same verified catalog as the alpha; its
public catalog responses allow cross-origin reads. You can mirror the complete
catalog directory for an offline POS or serve your own compatible manifest.
Relative manifest parts resolve against the manifest URL. Hashes remain
`phash256-rgb-white-v1` with the same four rotations and UUID identities.

For on-demand server lookup:

```js
await scanner.configure({mode:'endpoint', endpoint:'https://your-pos.example/api/card-hashes'});
```

The SDK sends JSON `{hash_bits:256,top_k:5,query_hashes:[{rotation_ccw,phash16},...]}`.
Return JSON `{matches:[{product_id,title,distance,similarity,image_url,...},...]}`
ranked by integer Hamming distance (0–256); product IDs are canonical UUIDs.
Similarity is `100 * (1 - distance / 256)`. Supply a different-product runner-up
for early confirmation: the best distance must be <=32 and its gap >=16 bits.
Missing or insufficient rival evidence uses ordinary consensus. CORS must allow
POST, OPTIONS and Content-Type if the endpoint has a different origin. The
server receives hashes, not pixels. Early confirmation may make more endpoint
requests during acquisition than the five-frame-only control.

A `new_lock` event announces one accepted track. Keep your own set of accepted
product IDs to skip repeated cards, and retain all returned alternatives so a
cashier can correct a close match. Match distance is not a calibrated probability
and family recognition does not guarantee the printing. Pricing is outside this
release. No sample uploads or scan-history writes occur in the SDK itself.

The P18 native APK uses this same JavaScript confirmation tracker. Its Camera2,
RGBA/native extraction, full offline catalog, and private WebView scan history
remain separate from the browser capture/worker engine. Its build metadata records
both the RC application commit and the reused native engine's provenance.
