minas2025 commited on
Commit
02ea090
·
verified ·
1 Parent(s): 958b3d0

fix: one full-frame face pass + IoU box matching (SCRFD dies on tight crops)

Browse files
Files changed (1) hide show
  1. circle_bibi.py +11 -4
circle_bibi.py CHANGED
@@ -132,16 +132,23 @@ def main():
132
  if total % max(1, args.stride) != 0:
133
  if writer: writer.write(frame)
134
  continue
 
135
  r = det.predict(frame, verbose=False, imgsz=640, conf=0.25,
136
  device=0 if args.gpu else "cpu")[0]
137
  target = None
138
  for b in r.boxes:
139
  x1, y1, x2, y2 = b.xyxy[0].tolist()
140
  conf = float(b.conf[0])
141
- faces = [f for f in face_app.get(frame[int(max(0,y1)):int(y2),
142
- int(max(0,x1)):int(x2)])
143
- if f.embedding is not None] if x2-x1 > 16 and y2-y1 > 16 else []
144
- best = max((cos(f.embedding, ref) for f in faces), default=0.0)
 
 
 
 
 
 
145
  if best >= REF_THRESHOLD:
146
  target = ((x1+x2)/2, (y1+y2)/2, (x2-x1+y2-y1)/4, conf, best)
147
  break
 
132
  if total % max(1, args.stride) != 0:
133
  if writer: writer.write(frame)
134
  continue
135
+ det_faces = face_app.get(frame)
136
  r = det.predict(frame, verbose=False, imgsz=640, conf=0.25,
137
  device=0 if args.gpu else "cpu")[0]
138
  target = None
139
  for b in r.boxes:
140
  x1, y1, x2, y2 = b.xyxy[0].tolist()
141
  conf = float(b.conf[0])
142
+ # match full-frame faces to this box by IoU (SCRFD is unreliable
143
+ # on tight crops; one face-pass per frame is also faster)
144
+ best = 0.0
145
+ for f in det_faces:
146
+ fb = f.bbox
147
+ box = (max(x1, fb[0]), max(y1, fb[1]), min(x2, fb[2]), min(y2, fb[3]))
148
+ if box[2] > box[0] and box[3] > box[1]:
149
+ ua = (x2-x1)*(y2-y1) + (fb[2]-fb[0])*(fb[3]-fb[1]) - (box[2]-box[0])*(box[3]-box[1])
150
+ if ua > 0 and ((box[2]-box[0])*(box[3]-box[1])) / ua >= IOU_GATE:
151
+ best = max(best, cos(f.embedding, ref))
152
  if best >= REF_THRESHOLD:
153
  target = ((x1+x2)/2, (y1+y2)/2, (x2-x1+y2-y1)/4, conf, best)
154
  break