stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: enable a webcam as image input

Open DNArtbill opened this issue 3 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

grab an image from a webcam and use it for processing then grabbing a new image when done.

Proposed workflow

  1. Go to .... the img2img tab
  2. Press .... an not yet excisting "use camera" button
  3. Press .... an not yet excisting "loop" toggle ui element if desired
  4. Press ... Generate

Additional information

https://www.youtube.com/watch?v=g75ipNzWnbo the video here gives an impression of the process im sure lots of us would enjoy

DNArtbill avatar Oct 24 '22 16:10 DNArtbill

Yes this would be a great experience

doantientai avatar Mar 01 '23 18:03 doantientai

This feature world be usefull for me.

roots-3d avatar Mar 21 '23 18:03 roots-3d

+1

jonwong666 avatar Apr 19 '23 10:04 jonwong666

You can easily make the UI take a webcam as input by modifying this one line

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ab7f213bec2f816f9c5644becb32eb72c8ffb89/modules/ui.py#L707

change your local stable-diffusion-webui/modules/ui.py to say webcam i.e.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", show_label=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA").style(height=480) 

then restart ./webui.sh. Tested and works on MacOS.

mngyuan avatar May 05 '23 16:05 mngyuan

You can easily make the UI take a webcam as input by modifying this one line

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ab7f213bec2f816f9c5644becb32eb72c8ffb89/modules/ui.py#L707

change your local stable-diffusion-webui/modules/ui.py to say webcam i.e.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", show_label=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA").style(height=480) 

then restart ./webui.sh. Tested and works on MacOS.

thanks, I can see the webcam but when I hit 'generate' I get an error "AttributeError: 'NoneType' object has no attribute 'split' "

jonwong666 avatar May 05 '23 22:05 jonwong666

+1

Grocel avatar Jun 02 '23 22:06 Grocel

You can easily make the UI take a webcam as input by modifying this one line

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ab7f213bec2f816f9c5644becb32eb72c8ffb89/modules/ui.py#L707

change your local stable-diffusion-webui/modules/ui.py to say webcam i.e.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", show_label=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA").style(height=480) 

then restart ./webui.sh. Tested and works on MacOS.

sounds like OP means they'd like a live webcam input that loops like a video, rather than taking a simple image and generating based off of that

Tommo1818 avatar Aug 24 '23 03:08 Tommo1818

You get "AttributeError: 'NoneType' object has no attribute 'split' " because it doesn't return an image unless you press the camera icon.

Worked for me with the following change. Which combined with "generate forever" option gives a constantly updating render.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", streaming=True, show_label=False, mirror_webcam=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA", height=opts.img2img_editor_height)

patrickgalbraith avatar Nov 17 '23 02:11 patrickgalbraith

You get "AttributeError: 'NoneType' object has no attribute 'split' " because it doesn't return an image unless you press the camera icon.

Worked for me with the following change. Which combined with "generate forever" option gives a constantly updating render.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", streaming=True, show_label=False, mirror_webcam=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA", height=opts.img2img_editor_height)

thanks that worked, how are you toggling between normal image upload and webcam? it'll be great if there was a new tab for the input type to be webcam

jonwong666 avatar Nov 18 '23 02:11 jonwong666

You get "AttributeError: 'NoneType' object has no attribute 'split' " because it doesn't return an image unless you press the camera icon. Worked for me with the following change. Which combined with "generate forever" option gives a constantly updating render.

init_img = gr.Image(label="Image for img2img", elem_id="img2img_image", streaming=True, show_label=False, mirror_webcam=False, source="webcam", interactive=True, type="pil", tool="editor", image_mode="RGBA", height=opts.img2img_editor_height)

thanks that worked, how are you toggling between normal image upload and webcam? it'll be great if there was a new tab for the input type to be webcam

I'm not. Yeah to do that would require a new tab. Which shouldn't be too hard to implement.

patrickgalbraith avatar Nov 18 '23 02:11 patrickgalbraith

thanks, I tried mucking around with it, the easiest way is just to replace the input in the sketch tab since I dont use the sketch function anyway, works great

jonwong666 avatar Nov 18 '23 02:11 jonwong666

Many helps! But here is a new question, if I want to change the source to virtual camera such as OBS, how can I set it?

nekomimimode-hex avatar Dec 09 '23 21:12 nekomimimode-hex