From charlesreid1

Line 46: Line 46:
=Motion program for camera stream (Success)=
=Motion program for camera stream (Success)=


You can also stream from your camera using the motion program. (Apparently. Haven't gotten it working yet.)
You can also stream from your camera using the motion program.


The problem: can't stream images using the motion program. I know the camera works with the Pi b/c I can capture still images, so it isn't a power issue. I can see motion dumping out still images, so it isn't a communication issue with the camera.
The problem: can't stream images using the motion program. I know the camera works with the Pi b/c I can capture still images, so it isn't a power issue. I can see motion dumping out still images, so it isn't a communication issue with the camera.

Revision as of 15:55, 22 October 2017

Motivation

I'm done trying to get this cheap-o Pi camera, with the clumsy ribbon cable, to try and work. The whole design, all of it reeks of cheaply-manufactured hardware incapable of anything but the most inane projects. (Hence the plethora of "how to photograph your cat" videos, and nothing more interesting or heavy-duty.)

The Hardware

I ordered a USB camera (1080 P, 2 MP?) from Amazon:

USBCamera1.jpg

USBCamera2.jpg

Fswebcam (Success)

The camera didn't come with instructions, but controlling it was insanely easy [1]:

$ apt-get install fswebcam
$ fswebcam image.jpg

aaaaand, now you have your first picture. To serve it up with a lightweight Python web server,

$ python -m SimpleHTTPServer 8000

Then point browser to 192.168.0.111:8000, and voila, the image is there and ready:

MyFirstUSBWebcamPhoto.jpg

Better Pictures

For best quality, use:

fswebcam -r 1280x720 --no-banner image.jpg

this results in a better image resolution without the obnoxious timestamp banner:

USBWebcamPhoto2.jpg

Wow! That's good enough to use for computer vision to detect cat faces.

Motion program for camera stream (Success)

You can also stream from your camera using the motion program.

The problem: can't stream images using the motion program. I know the camera works with the Pi b/c I can capture still images, so it isn't a power issue. I can see motion dumping out still images, so it isn't a communication issue with the camera.

Installing motion

$ apt-get install motion

Configuring motion

Now modify the motion config file to allow for webcam streaming:

$ sudo vim /etc/motion/motion.conf

change these lines:

stream_localhost on
webcontrol_localhost on

to these lines:

stream_localhost off
webcontrol_localhost off

Start motion daemon

To start the motion daemon:

$ sudo motion
[0] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "sdl_threadnr"
[0] [NTC] [ALL] motion_startup: Motion 3.2.12+git20140228 Started
[0] [NTC] [ALL] motion_startup: Logging to syslog
[0] [NTC] [ALL] motion_startup: Using log type (ALL) log level (NTC)
[0] [NTC] [ALL] become_daemon: Motion going to daemon mode
$ 

Ensure it is running:

$ ps aux | grep motion
root      3239 10.5  1.2  55940 10692 ?        Sl   19:30   0:01 motion

Ensure it is listening for connections:

$ sudo netstat -apt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:tproxy                *:*                     LISTEN      3239/motion

Monitoring stream

The monitoring stream is set in the configuration file to port 8080:

############################################################
# Live Stream Server
############################################################

# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 8080

go to the IP address of the Pi and tack on a :8080 to view the camera stream:

MotionCameraStream.png

Control stream

Control of the camera can be done via the web interface as well (including pan and tilt controls, if you have that set up). That's also set in the configuration file:

############################################################
# HTTP Based Control
############################################################

# TCP/IP port for the http server to listen on (default: 0 = disabled)
webcontrol_port 8081

This isn't terribly interesting, but it is useful:

MotionCameraControl.png

Projects

Now that we have the camera up and operational, and we're happy with the preliminary results... what next?

Timelapse 4

See RaspberryPi/Timelapse 4

Flags