ZM working with Raspberry Pi Camera

Forum for questions and support relating to the 1.27.x releases only.
Locked
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

ZM working with Raspberry Pi Camera

Post by liderbug »

Thought I'd share. Not happy with current camera (died), price of replacements, "No you can't have the login/passwrod." etc etc etc. I already had a RasPi board so I ordered a camera for $25. I have to say basic information - data structure etc - is a bit scarse/hidden. Seems the i developers like Python so the examples you get reads "RaspiCam::open ( bool StartCapture )". I learned to program in assy - lac, dac, jmp, isz... Not that there isn't a place for Python, Cobol, Fortran, Snobol, Ruby. But I'm off on a toot...

So I've been playing and got this to work: It's giving me aprox 5 fps. I plan on rewritting it in C using INT instead of CHAR - should be 3? 4? times faster.

Code: Select all

<?php
$len=0; $data = ""; $curfrm = "";
$fd1 = @fopen ("/dev/video0", "rb");
while ( $data = fread ($fd1, 4096) )
{
  $m = strpos($data, 'Exif');
  if ($m > 0)
  {
      $tailofframe = substr($data, 0, $m-6);
      $headofnew = substr($data, $m-6);
      $curfrm = $curfrm . $tailofframe;
      $len = strlen($curfrm);
      $fn = "/run/shm/ras~.jpg";
      $fd2 = @fopen ($fn, "wb");
      fwrite ($fd2, $curfrm, $len);
      fclose ($fd2);
      shell_exec("mv /run/shm/ras~.jpg /var/www/html/ras~.jpg ; mv /var/www/html/ras~.jpg /var/www/html/ras.jpg" );
      $curfrm = $headofnew;
  } else { 
      $curfrm = $curfrm . $data;
  }
}
?>
Image
That's true color - this morning, the sun, the clouds, just right, the world is ... pastel.
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: [SOLVED] [I think] ZM working with Raspberry Pi Camer

Post by liderbug »

On my RasPi:
w&h 1280x1024

raspivid -o - -w $w -h $h -t 0 -n -fps 15 | cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

I orig. didn't have -fps and it was running a bit hot - took forever to ssh to my Pi
(nohup and & of course)

Then in ZM FFMPEG, rtsp://raspi:8554/ WxH and Ta I went and treated myself to some leftover dessert from last night.

OH PROBLEM: in the process the ZM "Source" button went poof. I've restarted the brower, ZM and Name[Driveway], Function[Modect], Source [ ] Ah??? any ideas?

Full scripts & code on request (PM)
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: ZM working with Raspberry Pi Camera

Post by liderbug »

Another update. I've switched over to raspimjpeg. It allows, via http://raspi/index.php, to adjust bright, contrast, ISO, and another 15? things that take effect on the spot. The program ouputs a jpg at 25 fps (selectable - around 80 at 480x320) - I've got it set to 1280 @ 25fps. The load seems to be very low. Only problem I've seen is every several seconds-minutes ZM gets a wild-hair frame - goes 100% - which zone control pitches.
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: ZM working with Raspberry Pi Camera

Post by liderbug »

I think I know the problem to the bad frames. I think the jpg is being read while the program is writing it.

-rw-r--r-- 1 apache apache 187574 Nov 2 10:26 008-capture.jpg
-rw-r--r-- 1 apache apache 20619 Nov 2 10:26 009-capture.jpg
-rw-r--r-- 1 apache apache 187470 Nov 2 10:26 010-capture.jpg

Any thoughts on how to fix - or do I just ignore?

Thanks
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: ZM working with Raspberry Pi Camera

Post by liderbug »

Update #whateverrrr...

Yesterday: I'm running raspimjpeg on my RasPi. 1280x1024@20 -> /run/shm/cam.jpg. top says < 9% cpu.Then a soft link to /var/www/html/cam.jpg. Seems to run and run and run - just fine.

Then (on my desktop 3.8, 6 core) ZM, Remote, Modect, HTTP, Simple, raspi, 80, /cam.jpg. Runs fine, detects ... Then after a few minutes my network? modem(DSL)? locks up and I have to hard reboot my modem. Not just once but every time (momma not happy).

So, I wrote a php cURL script (on desktop) - get (raspi)cam.jpg>(local)/run/shm/cam.jpg and set ZM, File, Modect, /run/shm/cam.jpg - runs great, network doesn't lockup, car drives by - no detection...

I would really appreciate any suggestions.
Thanks
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: ZM working with Raspberry Pi Camera

Post by liderbug »

Did some web research on speeding up cURL and found out PHP will will run cURL at about 5 per second and a bash script will run at about 30+ per second (going to my raspi and bringing back a frame) - Who'da thunk?

Code: Select all

while [ 1 ]
do
  curl -s "http://raspi/cam.jpg" > /run/shm/cam~.jpg
  mv /run/shm/cam~.jpg /run/shm/cam.jpg
  usleep 30000  #throttles to about 15 fps
 done
[code]

Then set ZM to file from /run/shm/cam.jpg.  I don't seem to get any short frames.
Trigun
Posts: 6
Joined: Thu Nov 16, 2017 12:14 pm

Re: ZM working with Raspberry Pi Camera

Post by Trigun »

hi, what kind of OS are you running on the pi to get it working with ZM?
so far, it seems I've tried it all but can't seem to get the picture in ZM.

perhaps you are willing to help me out here.

thnx in advance!
liderbug
Posts: 125
Joined: Wed Dec 19, 2007 4:46 pm

Re: ZM working with Raspberry Pi Camera

Post by liderbug »

sorry for the delay - raspbarian
Locked