diff --git a/images/exampleB.jpg b/images/exampleB.jpg new file mode 100644 index 0000000..47ca21c Binary files /dev/null and b/images/exampleB.jpg differ diff --git a/images/exampleH.jpg b/images/exampleH.jpg new file mode 100644 index 0000000..450c005 Binary files /dev/null and b/images/exampleH.jpg differ diff --git a/images/exampleV.jpg b/images/exampleV.jpg new file mode 100644 index 0000000..ad6f2ae Binary files /dev/null and b/images/exampleV.jpg differ diff --git a/scripts/face_swap.py b/scripts/face_swap.py index 99d9ce5..cd0b096 100644 --- a/scripts/face_swap.py +++ b/scripts/face_swap.py @@ -245,10 +245,63 @@ class Script(scripts.Script): return is_img2img def ui(self, is_img2img): + def switchExample(howSplit: str, divider: int, showTips: bool): + if "Both" in howSplit: + image = Image.open("./extensions/batch-face-swap/images/exampleB.jpg") + width, height = image.size + image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) + image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB) + if divider > 1: + for i in range(divider-1): + start_point = (0, int((height/divider)*(i+1))) + end_point = (int(width), int((height/divider)*(i+1))) + color = (255, 0, 0) + thickness = 4 + image = cv2.line(image, start_point, end_point, color, thickness) + + for i in range(divider-1): + start_point = (int((width/divider)*(i+1)), 0) + end_point = (int((width/divider)*(i+1)), int(height)) + color = (255, 0, 0) + thickness = 4 + image = cv2.line(image, start_point, end_point, color, thickness) + + elif "Vertical" in howSplit: + image = Image.open("./extensions/batch-face-swap/images/exampleV.jpg") + width, height = image.size + image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) + image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB) + if divider > 1: + for i in range(divider-1): + start_point = (int((width/divider)*(i+1)), 0) + end_point = (int((width/divider)*(i+1)), int(height)) + color = (255, 0, 0) + thickness = 4 + image = cv2.line(image, start_point, end_point, color, thickness) + + else: + image = Image.open("./extensions/batch-face-swap/images/exampleH.jpg") + width, height = image.size + image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) + image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB) + if divider > 1: + for i in range(divider-1): + start_point = (0, int((height/divider)*(i+1))) + end_point = (int(width), int((height/divider)*(i+1))) + color = (255, 0, 0) + thickness = 4 + image = cv2.line(image, start_point, end_point, color, thickness) + + image = Image.fromarray(image) + update = gr.Image.update(value=image) + return update + def switchTextbox(saveMask: bool): return gr.Textbox.update(visible=bool(saveMask)) def switchHTML(showTips: bool): return gr.HTML.update(visible=bool(showTips)) + def switchImage(showTips: bool): + return gr.Image.update(visible=bool(showTips)) gr.HTML("
Make sure you're in the \"Inpaint upload\" tab!
") @@ -263,8 +316,9 @@ class Script(scripts.Script): with gr.Column(): gr.HTML("Step 2: Image splitter:
") htmlTip2 = gr.HTML("This divides image to smaller images and tries to find a face in the individual smaller images.
Useful when faces are small in relation to the size of the whole picture and not being detected.
(may result in mask that only covers a part of a face or no detection if the division goes right through the face)
",visible=False) - divider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="How many times to divide image") + divider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="How many images to divide into") howSplit = gr.Radio(["Horizontal only ▤", "Vertical only ▥", "Both ▦"], value = "Both ▦", label = "How to divide") + exampleImage = gr.Image(value=Image.open("./extensions/batch-face-swap/images/exampleB.jpg"), label="Split visualizer", type="pil", visible=False).style(height=500) with gr.Column(): gr.HTML("Other:
") htmlTip3 = gr.HTML("Press 'Generate masks' button to see how many faces do your current settings detect without generating SD image.
You can also save generated masks to disk. (if you leave path empty, it will save the masks to your default webui outputs directory)
Activate 'View all results' checkbox to see results in the WebUI at the end (not recommended when processing a large number of images)
",visible=False) @@ -282,6 +336,10 @@ class Script(scripts.Script): showTips.change(switchHTML, showTips, htmlTip1) showTips.change(switchHTML, showTips, htmlTip2) showTips.change(switchHTML, showTips, htmlTip3) + showTips.change(switchImage, showTips, exampleImage) + + howSplit.change(switchExample, [howSplit, divider, showTips], exampleImage) + divider.change(switchExample, [howSplit, divider, showTips], exampleImage)