Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 3:11 pm

I would like to be able to watch some equipment I control through an RPi3 unit so I can verify correct operation.
I am myself across the ocean from the RPi3 and the prototype so it would be a way to monitor what happens...
It is possible to direct tech people on location to set it up if it is not too complex, either on a second RPi or the one I use for control.
Any suggestions?
Bo Berglund
Sweden

W. H. Heydt
Posts: 13644
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 4:51 pm

Bosse_B wrote:
Tue Aug 18, 2020 3:11 pm
I would like to be able to watch some equipment I control through an RPi3 unit so I can verify correct operation.
I am myself across the ocean from the RPi3 and the prototype so it would be a way to monitor what happens...
It is possible to direct tech people on location to set it up if it is not too complex, either on a second RPi or the one I use for control.
Any suggestions?
One of the UK suppliers (PiHut? Pimoroni? One of those two) was advertising a webcam for Pis.

There's a lot of interest in this area at the moment because of remote instruction by schools. The RPF is looking at cameras to see what works well and what is inexpensive (probably in hopes of finding ones that are both), but I haven't see any results of that...yet. I will note that--for my grandson--I have a Pi set up using a PiCamera v2 in that role and it is certainly adequate to his needs (in fact, he's "in class" right now, with it).

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 5:23 pm

I googled and found an "instructable" that installed a package called motion.
I tried it on my old available RPi3 running Jessie, but it would not start the service.
I guess I have to create anew SDCard for the RPi3 and use Pi-OS instead...
Bo Berglund
Sweden

Dragontail281
Posts: 43
Joined: Thu Mar 07, 2019 8:56 pm

Re: Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 6:16 pm

If you aren't doing anything else with the Pi you could just create a new SD card with MotionEyeOS on it, or have the "techs" at the equipment location do it.
Fairly easy program to work with and you can access online after opening up a port.
I use it as a second cam at my house, in addition to a Nest cam that I have had for a few years now.
I can watch it at work or even on my phone.
RPI3b+ - Raspberry Pi OS -general "playing"
RPI0W - MotionEyeOS - yard surveillance
RPI0W - Driveway gate monitor - coming soon
RPI0W - ?????

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 7:30 pm

I have now tested with motion on the RPi3 with a fully updated Pi-OS.
It works but the configuration file is just too much...
And my Logitech hd 720p webcam is not possible to adjust focus on, so the closeups are all fuzzy.

I want to have the cam take still images at a slow rate or on command so it won't bog down the RPi3.
I only need a new image when I have commanded an action and want to see the result.

I believe the prototype RPi3 on location could be able to handle this task too, especially if the pictures are taken on demand.
In such a case the tech guy just has to connect the webcam to an unused USB and position it such that I can see the active area of the equipment, and its display.
All software update and config could be done remotely by me.

The equipment is in Texas and due to Covid-19 the premises are evacuated, everyone except a few in manufacturing work remotely from home.
Bo Berglund
Sweden

User avatar
DAI-X
Posts: 57
Joined: Fri Nov 27, 2015 11:19 pm
Location: sutton coldfield, uk

Re: Advice on using an USB webcam on an RPi3?

Tue Aug 18, 2020 8:43 pm

I have built something similar to what I think you are after

Put simply I used "web.py" This is a simple python-based http server which runs a python script when you connect to an IP address on a Pi equipped with a USB webcam (ebay special!). I can do this anywhere via my phone browser.

The web.py script when requested takes a photo, and then generates and returns a simple html page with the image embedded in it.

The beauty if this is it has no performance overhead unless the webpage is actually requested. It works well if you only want static images infrequently / on request. It does take a few seconds to take the photo and update the webpage but I suspect this won't be a problem to you either. It runs on a Pi 1 so maybe a 3 would be quicker.

if you want some more info I can post some code to help you

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: Advice on using an USB webcam on an RPi3?

Wed Aug 19, 2020 8:59 am

DAI-X wrote:
Tue Aug 18, 2020 8:43 pm
I have built something similar to what I think you are after

Put simply I used "web.py" This is a simple python-based http server which runs a python script when you connect to an IP address on a Pi equipped with a USB webcam (ebay special!). I can do this anywhere via my phone browser.

The web.py script when requested takes a photo, and then generates and returns a simple html page with the image embedded in it.

The beauty if this is it has no performance overhead unless the webpage is actually requested. It works well if you only want static images infrequently / on request. It does take a few seconds to take the photo and update the webpage but I suspect this won't be a problem to you either. It runs on a Pi 1 so maybe a 3 would be quicker.

if you want some more info I can post some code to help you
This sounds exactly like what I need!
Just issue the equipment command then refresh the webpage showing the image!
Very neat and just what is needed here.

Techs on location can just connect the webcam and then adjust it so its picture covers the interesting area, whereas I can install the software remotely in advance. And the Techs can check the image by connecting their phone to the RPi3 IP address, which is known.

Yet another Covid-remote solution!

Please post or PM more info about the Python script and how to install it. :)
Bo Berglund
Sweden

User avatar
DAI-X
Posts: 57
Joined: Fri Nov 27, 2015 11:19 pm
Location: sutton coldfield, uk

Re: Advice on using an USB webcam on an RPi3?

Wed Aug 19, 2020 1:56 pm

Ok here goes. First you need to install the web.py application from https://webpy.org/

(I still use python 2 and the code below is in python 2 so I think for python 2 it is......

pip install web.py

you also then need to ensure you have fswebcam installed which will run your USB camera

sudo apt install fswebcam


copy the code below into the web.py folder and name it something like "website.py"

finally you need to start the web.py webserver by CDing to the web.py directory (think it is web.py_0.38 by default, I renamed mine to web.py which is why my code refers to /home/pi/web.py/)

python website.py xxxx

where xxxx is the port you want the webserver to run on (e.g. 8888)

then in a browser navigate to the IP address of the PI and the port e.g. if you are on the same local network:

192.168.0.7:8888

If everything works you should after a few seconds see a still webcam image in a webpage.

DISCLAIMER: I have cut my webserver script down a lot to make it clearer, I may have cut something important out accidentally...
DISCLAIMER 2: other python based webservers are available, e.g. simpleHTTPserver is another possibility.
DISCLAIMER 3: if something is wrong in web.py its error messages are super-cryptic. If you have problems let me know....

Code: Select all

import web
import time
import commands
import urllib

urls = (
    '/', 'index'
)
data=""

class index:
    def GET(self):
	a=commands.getoutput("sudo fswebcam -d /dev/video0 --fps 3 -S 3 --subtitle CAMERA -r 640x480 /home/pi/web.py/static/camera.jpg")

	data=	  '<!DOCTYPE html>'
	data=data+'<html>'
	data=data+'<body>'
	data=data+'<b> CAMERA OUTPUT </b>'
	data=data+'<img src="/static/camera.jpg" alt="HTML5 Icon">'
	data=data+'<body>'
	data=data+'<html>'	

	return data

if __name__ == "__main__":
    app = web.application(urls, globals())
    time.sleep(1)
    app.run()




Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: Advice on using an USB webcam on an RPi3?

Wed Aug 19, 2020 6:30 pm

Thanks, I will try it out and report back.
Bo Berglund
Sweden

Return to “General discussion”