Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Simulate a Webcam with Pictures (Or IP Camera) (http://www.chiefdelphi.com/forums/showthread.php?t=149939)

Technologyman00 08-08-2016 22:03

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?

calcmogul 09-08-2016 03:28

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

%04d represents an integer padded on the left with zeroes to four digits. I used the following script to rename all .jpg files in the current directory to the form the gstreamer command accepts.

Code:

#!/bin/bash
count=0
for file in *.jpg; do
  new=$(printf "img.%04d.jpg" "$count")
  mv -- "$file" "$new"
  let count=count+1
done


adciv 09-08-2016 06:39

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.

billbo911 09-08-2016 10:30

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()

To open a image file instead:
Code:

frame = cv2.imread(PathToImageFile)

virtuald 09-08-2016 13:23

Re: Simulate a Webcam with Pictures (Or IP Camera)
 
mjpg-streamer can send a stream from a directory of jpeg files.


All times are GMT -5. The time now is 09:58.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi