Skip to content

Fix UnboundLocalError when no faces are detected#286

Open
Mr-Neutr0n wants to merge 1 commit intoOpenTalker:mainfrom
Mr-Neutr0n:fix-mask-sharp-undefined
Open

Fix UnboundLocalError when no faces are detected#286
Mr-Neutr0n wants to merge 1 commit intoOpenTalker:mainfrom
Mr-Neutr0n:fix-mask-sharp-undefined

Conversation

@Mr-Neutr0n
Copy link
Copy Markdown

Summary

  • Initialize mask_sharp before the face detection loop to prevent UnboundLocalError when no faces are detected

Problem

When processing an image/frame with no detected faces, the code crashes with:

UnboundLocalError: local variable 'mask_sharp' referenced before assignment

This happens because mask_sharp is only assigned inside the for loop (line 93), but is used after the loop (line 113). If the loop never executes (no faces detected), the variable is undefined.

Solution

Initialize mask_sharp with zeros before the loop, matching the dimensions of full_mask.

Test plan

  • Process an image with no faces and verify no crash occurs
  • Process an image with faces and verify output is unchanged

Fixes #273

Initialize mask_sharp before the face detection loop to prevent
UnboundLocalError when facebs is empty (no faces detected).

Previously, mask_sharp was only assigned inside the for loop,
so if no faces were detected, line 113 would fail with:
"UnboundLocalError: local variable 'mask_sharp' referenced before assignment"

Fixes OpenTalker#273
@Mr-Neutr0n
Copy link
Copy Markdown
Author

following up on this. fixes an UnboundLocalError crash when no faces are detected in a frame — the variable was used before assignment. small fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnboundLocalError: local variable 'mask_sharp' referenced before assignment

1 participant