归档分析脚本到 analysis/reverse_tools(compare_live/verify_nuc/verify_full/parse_ddt/parse_pcap),更新 session_state 引用路径

This commit is contained in:
ZXCLI
2026-08-19 15:55:21 +08:00
parent 0d83c625d1
commit dd52469377
6 changed files with 395 additions and 4 deletions
+53
View File
@@ -0,0 +1,53 @@
import struct, sys
# compare demo3 live capture vs official capture on the same static scene
b = open(r"C:\Project\MAG160C\build-artifacts\demo3_frame_capture.bin", "rb").read()
off = 0
live = struct.unpack_from("<19200H", b, off); off += 38400
ref = struct.unpack_from("<19200H", b, off); off += 38400
nuc = struct.unpack_from("<19200H", b, off); off += 38400
gray = b[off:off+19200]; off += 19200
lut = b[off:off+1024]; off += 1024
meta = struct.unpack_from("<8i", b, off)
print("demo3: win=[%d,%d] stats=(%d..%d m%d s%d) shutter=%d sel=%d" % meta)
print("demo3: live_mean=%.0f ref_mean=%.0f nuc_mean=%.0f" % (sum(live)/19200, sum(ref)/19200, sum(nuc)/19200))
d = r"C:\Project\MAG160C\analysis\pairs_final_20260813"
def load(path, fmt, n):
b = open(path, "rb").read()
return struct.unpack_from("<%d%s" % (n, fmt), b, 0)
win = open(d + r"\pair_000.win", "rb").read()
hi, lo, fmax, fmin, mean, std, axmax, axmin = struct.unpack_from("<8I", win, 0)
gray_o = load(d + r"\pair_000.gray", "B", 320*240)
raw_o = load(d + r"\pair_000.raw", "H", 19200)
lut_o = open(d + r"\pair_000.lut", "rb").read()
print("official: win=[%d,%d] stats=(%d..%d m%d s%d)" % (lo, hi, fmin, fmax, mean, std))
print("official: raw_mean=%.0f" % (sum(raw_o)/19200))
# gray comparison: demo3 gray160 vs official gray320 downsampled (2x parity)
g_o160 = [gray_o[y*320 + x] for y in range(0, 240, 2) for x in range(0, 320, 2)]
import collections
hd = collections.Counter(gray)
ho = collections.Counter(g_o160)
# histogram correlation
allk = set(hd) | set(ho)
n = sum(hd.values())
# compare histograms as distributions
import math
def corr(a, b):
ka = set(a); kb = set(b)
ks = ka | kb
ma = sum(a[k] for k in ks)/n
mb = sum(b[k] for k in ks)/n
num = sum((a.get(k,0)-ma)*(b.get(k,0)-mb) for k in ks)
da = math.sqrt(sum((a.get(k,0)-ma)**2 for k in ks))
db = math.sqrt(sum((b.get(k,0)-mb)**2 for k in ks))
return num/(da*db) if da and db else 0
print("gray histogram correlation: %.4f" % corr(hd, ho))
print("demo3 gray range: %d..%d, official: %d..%d" % (min(gray), max(gray), min(g_o160), max(g_o160)))
# LUT comparison
dl = sum(1 for i in range(1024) if lut[i] != lut_o[i])
print("demo3 lut vs official lut diff: %d/1024" % dl)
print("demo3 lut[0:8]:", list(lut[:8]), " official:", list(lut_o[:8]))
print("demo3 lut[1000:]:", list(lut[1000:]), " official:", list(lut_o[1000:]))