Rasp Pi as web cam server

Anything to do with the Raspberry Pi
a_shorething
Posts: 289
Joined: Sep 10th, 2013, 5:26 pm
Location: New Jersey Shore

Rasp Pi as web cam server

Post by a_shorething »

oooh. I get to be the first one to post in the Raspberry Pi forum! :)

I got one of these with the new HD camera that they have set up for it at Adafruit (http://www.adafruit.com/category/105). This looks like an awesome way to go and blows my previous plan out of the water (so to speak).

For $100 shipped even if you use it for nothing but sending video you get a fully hackable HD webcam. (this vs. the Chinese webcam I was trying to use that has an unintelligible SDK and NO tech support).

This is the software section so I'm going to put this out there (and hopefully answer my own question in the next week or so). Can anyone post step-by-step instructions for setting up a Raspberry Pi right out of the box and set it up as a webcam?

I've found some videos online that I will come back and link in here, but if anyone here has done it, it would be awesome.
Last edited by a_shorething on Nov 12th, 2013, 5:44 pm, edited 1 time in total.
Zaibach
Posts: 48
Joined: Aug 13th, 2013, 9:50 am

Re: Rasp Pi as webserver

Post by Zaibach »

I've gone through a few tutorials with varying degrees of success.

I want to say I initially tried using Motion with limited success. It has been a while but this looks very close to the tutorial I used when I was setting it up http://pingbin.com/2012/12/raspberry-pi ... er-motion/ I wasn't terribly happy with the output, I didn't really spend much time tweaking things tho. Since it didn't really get me closer to a HUD I decided to move on to another part of the project and come back to the video streaming later.

From what I have been reading lately it sounds like it is actually faster to use mjpgstreamer if your webcam supports MJPG formatting the camera ends up doing all the "heavy lifting". Allowing the Pi to skip out on the image processing and just shoot the pre-processed images down the pipe. Haven't tried playing much with that yet but there seemed to be a good tutorial over at http://blog.miguelgrinberg.com/post/how ... spberry-pi. Their usage goes into the PiCamera module specifically so from step 7 on it might not be as useful but it does cover getting Mjpg streaming installed on a Pi.

Course my pi is setup commandline over wifi so I'm puttying in the command for mjpg-streamer seems to work but whenever I try to view it remotely the connection is reset. So I'm going to have to keep playing with that :P
a_shorething
Posts: 289
Joined: Sep 10th, 2013, 5:26 pm
Location: New Jersey Shore

Re: Rasp Pi as web cam server

Post by a_shorething »

Just got the cables I need for my Pi so I'm checking out some stuff now.

I will say that while I was doing my homework for this I found many references to a guy who set up some in-car video to overlay OBD-2 data from his car.
Here: http://www.stuffaboutcode.com/2013/07/r ... h-obd.html
It also shows how he flipped the image vertically and horizontally in the code (his camera was upside down I guess) but this might give those who are looking at automobile back-up cameras an option since that image in typically a mirror image.


I've seen several different tutorials online for setting up the RaspPI as a webcam and I've also seen some stuff for storing HD video onboard.

I hadn't thought about it initially but after speaking with a friend who does some pretty high tech video stuff for the US govt, I realized that I have two separate requirements: 1. navigation and 2. video recording.

I want to have HD video recordings of my dives. I also want to be able to navigate and see what the heck I'm doing. I thought these two were connected but they're separate. He suggested for the purpose of navigation using one resolution and recording in HD, maybe even from a different camera since you may not want the same field of view and you probably would prefer to navigate with a fisheye view.

Armed with this revelation I got a nice big SD card for my PI and I want to try to figure out how to get the best resolution I can for navigation that won't slow things down. Then I'll see if I can set up a completely different configuration for recording on board since that won't cause bandwidth problems and I'll have my video to review afterward when I upload it.

Right now I'm still less than 10 minutes into the initial boot up and tutorials from Adafruit so I can't say how things are going, but it seems to be doing something. :)

Will post back.
Zaibach
Posts: 48
Joined: Aug 13th, 2013, 9:50 am

Re: Rasp Pi as web cam server

Post by Zaibach »

Interesting approach. I was and still am trying to figure out the best way to get a video overlay before transmission. Which is going to take a decent chunk out of processing overhead since I'm hellbent on a nice graphically pleasing HUD (which is actually how/where all my ROV craziness started). Then I was going to do the actual recording topside. Assuming the USB camera I had (sadly past tense) worked I was thinking about seeing how many I could actually run if I alternated between them since at least in theory it should be much more difficult than shutting off /dev/video0 and initializing /dev/video1, video2, video3, etc. If that works it would be easy to go crazy with $20 HD USD webcams. I do have to say the idea of running them all at the same time (resources permitting) is tantalizing.

Sadly my HD USB webcam died on me recently so I'm waiting on Black Friday/Cyber Monday to catch a deal on ordering a few more.
a_shorething
Posts: 289
Joined: Sep 10th, 2013, 5:26 pm
Location: New Jersey Shore

Re: Rasp Pi as web cam server

Post by a_shorething »

In case anyone is interested here's a link from a guy who set up a dash cam for his car using Rpi.

http://pidashcam.blogspot.com/

The reason I'm posting is that he is using a Raspberry pi camera, a USB camera as a picture in picture, and he got GPS and timestamp information to display and record in an OSD setup.

I haven't read how he did it yet, but the picture is awesome and the techniques would be very useful in an ROV.

I'll post when I learn more about it.
(about 30 seconds in he switches on the PIP and you see the rear-view cam in the upper left)
User avatar
olegodo
Posts: 222
Joined: Aug 30th, 2013, 9:47 am
Location: Bergen, Norway

Re: Rasp Pi as web cam server

Post by olegodo »

Hi!

I have also played around with "motion" on the raspberry pi, and it seems that anything above 640x480 is pretty much useless, even at that resolution i can only get around 10-15fps before the PI's cpu is maxed.

I haven't managed to get mjpg-streamer to work yet, but while searching around I found this guy who is streaming h.264 from the PI-cam directly to VLC. At 720p, it only uses around 10% of the PI's cpu power. Witch is quite impressive.


As you can see, there is some delay, but at that resolution I haven't seen anything better yet. And maybe it could improve even more with some tweaking.
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Rasp Pi as web cam server

Post by Moki »

Most (if not all) of the above Camera + OSD examples.... record the video and the data into files.
So they can later combine both of them, into one video (that's cheating ;) )

Looks great on Youtube, but not really usefull for ROV's

Best result I got so far, is using mjpg_streamer with 2 webcams (Logitech C510) (ofcourse no OSD (yet))

Code: Select all

cd /root/mjpg-streamer
./mjpg_streamer -i "./input_uvc.so -n -f 25 -r 640x480 -d /dev/video0" -o "./output_http.so -n -w ./www/stream2 -p 8080" >/dev/null 2>&1 &
sleep 2
./mjpg_streamer -i "./input_uvc.so -n -f 25 -r 640x480 -d /dev/video1" -o "./output_http.so -n -w ./www/stream2 -p 8081" >/dev/null 2>&1 &
Viewing using IE
http://<PI IP Address>:8080/javascript_simple.html
http://<PI IP Address>:8081/javascript_simple.html

Or make you own webpage, using <IFrame>, you would get something like this:
Attachments
Schermafdruk 2014-10-29 13.04.17.png
Schermafdruk 2014-10-29 13.04.17.png (662.1 KiB) Viewed 10574 times
User avatar
olegodo
Posts: 222
Joined: Aug 30th, 2013, 9:47 am
Location: Bergen, Norway

Re: Rasp Pi as web cam server

Post by olegodo »

Moki,
What kind of resolution and frames per second do you get?
NVM, I see the resolution in the code ;)
Is it able to keep 25fps on both cameras?
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Rasp Pi as web cam server

Post by Moki »

Indeed, resolution is 640x480... It could do better, have tested 960x720.. But that didn't fit on my screen side-by-side anymore :)
Its using about 10% CPU for each stream (100Mb connection), I am sure it could do 4 streams (not tested)

Not sure how many FPS I get, I have set F 25... no errors show ;)
So looks real-time (eq motion, looks like motion.. no stutter), which is good enough for me.
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Rasp Pi as web cam server

Post by Moki »

Just build a new PI, with 2 Logitech C525 webcams.

This is how I did it:

Code: Select all

apt-get install libjpeg62-dev
apt-get install cmake
apt-get install apache2
apt-get install subversion

git clone https://github.com/jacksonliam/mjpg-streamer.git

cd mjpg-streamer/
cd mjpg-streamer-experimental/

make
make install

cp /usr/local/www/javascript_simple.html /var/www

export LD_LIBRARY_PATH=/usr/local/lib
mjpg_streamer -b -i "input_uvc.so -n -f 25 -r 640x480 -d /dev/video0" -o "output_http.so -n -w /var/www -p 8080"
mjpg_streamer -b -i "input_uvc.so -n -f 25 -r 640x480 -d /dev/video1" -o "output_http.so -n -w /var/www -p 8081"
edit /var/www/index.html (Replace <PI_IP_ADRESS> with your Pi's IP.)

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Moki ROV</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="style.css" type="text/css" />
    <!--[if IE 6]>
    <link rel="stylesheet" href="fix.css" type="text/css" />
    <![endif]-->
  </head>

  <body>
<iframe frameborder="0" scrolling="no" width="640" height="480"
   src="http://<PI_IP_ADRESS>:8080/javascript_simple.html" name="imgbox" id="imgbox">
   <p>iframes are not supported by your browser.</p>
</iframe>
<iframe frameborder="0" scrolling="no" width="640" height="480"
   src="http://<PI_IP_ADRESS>:8081/javascript_simple.html" name="imgbox" id="imgbox">
   <p>iframes are not supported by your browser.</p>
</iframe>

  </body>
</html>
Open your webbrowser, go to: http://<PI_IP_ADRESS>
Post Reply