Hama myScan Linux driver tools: scan mode, frame decoding, stitching

UVC extension-unit control (mouse/scan mode, LEDs, exposure), JPEG header
fix and embedded laser record decoding, session recorder, and a stitcher
that combines laser dead reckoning with phase correlation and ECC refinement.
FINDINGS.md holds the reverse-engineered protocol and laser calibration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
erik
2026-10-02 10:41:22 +00:00
co-authored by Claude Opus 5.5
commit e1c1012c1c
13 changed files with 1751 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""Stitch a directory recorded by tools/record.py into a page image."""
import argparse
import csv
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import cv2 # noqa: E402
import numpy as np # noqa: E402
from myscan.stitch import ROT_GAIN, Stitcher, laser_deltas # noqa: E402
def main():
ap = argparse.ArgumentParser()
ap.add_argument("dir")
ap.add_argument("-o", "--out", help="output image (default <dir>/page.png)")
ap.add_argument("--no-refine", action="store_true", help="lasers only, no image registration")
ap.add_argument("--rot-gain", type=float, default=ROT_GAIN)
ap.add_argument("--start", type=int, default=0)
ap.add_argument("--end", type=int)
a = ap.parse_args()
rows = list(csv.DictReader(open(os.path.join(a.dir, "records.csv"))))
v = np.array([[int(r[f"v{k}"]) for k in range(6)] for r in rows])
deltas = laser_deltas(v)
frames = [int(r["frame"]) for r in rows]
rng = range(a.start, a.end if a.end is not None else len(rows))
st = None
for i in rng:
im = cv2.imread(os.path.join(a.dir, f"f{frames[i]:05d}.png"), cv2.IMREAD_GRAYSCALE)
if st is None:
st = Stitcher(im.shape, refine=not a.no_refine, rot_gain=a.rot_gain)
st.add(im, deltas[i])
out = a.out or os.path.join(a.dir, "page.png")
cv2.imwrite(out, st.image())
print(f"{st.n} frames -> {out} {st.stats}")
if __name__ == "__main__":
main()