|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Simulate a Webcam with Pictures (Or IP Camera)
Does anyone know of an easy way or some free software that you can run on the RPI (Raspberry Pi) to simulate a webcam or make a IP camera with sets of pictures that are in a folder?
|
|
#2
|
||||
|
||||
|
Re: Simulate a Webcam with Pictures (Or IP Camera)
You could use gstreamer to do that. The following script will run an MJPEG server on localhost port 8080 using JPEG images from the current directory that match the name pattern. They will be served in a loop until the server is killed.
Code:
#!/bin/bash
gst-launch-1.0 multifilesrc location="img.%04d.jpg" index=0 \
caps="image/jpeg,framerate=\(fraction\)12/1" loop=true ! jpegdec ! \
videoconvert ! videorate ! jpegenc ! queue ! multipartmux ! \
tcpserversink host=127.0.0.1 port=8080
Code:
#!/bin/bash count=0 for file in *.jpg; do new=$(printf "img.%04d.jpg" "$count") mv -- "$file" "$new" let count=count+1 done |
|
#3
|
|||
|
|||
|
Re: Simulate a Webcam with Pictures (Or IP Camera)
The key thing to remember about webcams is they just send a series of still JPG images with some header information. It's nothing more complex than that. It wouldn't take much to write your own streaming service.
|
|
#4
|
||||
|
||||
|
Re: Simulate a Webcam with Pictures (Or IP Camera)
It will depend on what you are using to open those images for processing on the Pi.
If you use OpenCV, it is as simple as using one command line to open an image vs another to grab a frame from a video stream. I'm certain most other image processing code works almost identically. For example, to grab a video frame, you could do this: Code:
camera = cv2.VideoCapture(0) # Later followed by this to grab the frame (grabbed, frame) = camera.read() Code:
frame = cv2.imread(PathToImageFile) |
|
#5
|
||||
|
||||
|
Re: Simulate a Webcam with Pictures (Or IP Camera)
mjpg-streamer can send a stream from a directory of jpeg files.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|