YvesG
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 2:32 pm

@Kevw ok so it's seems to be the same that i got at the beginning (moved from 1080p to something with a better FOV).
I don't know what i changed but this problem has been solved (maybe a raspberry reboot or some swap between video resolutions)
you can try also start and stop button in the UI

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 2:51 pm

If you stop / start pikrellcam after changing resolutions does it get rid of the green video? I'm not seeing a new video header when resolution changes, so I'm looking at that.

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 3:28 pm

Yeah, I was happily throwing the changed header away. I need to look over some other stuff but should have an update up in a few hours.

kevw
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 3:34 pm

That was the ticket, thxs - green pixel line across bottom is still visible in live preview but recorded video isnt green now and plays in browser.

Cheers,

Kev

kevw
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 4:31 pm

Could we have the EV compensation option added to the camera settings please Bill (-10 <-> +10) ?

Cheers,

Kev

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 8:18 pm

I've pushed a new pikrellcam.

Videos after preset switching should be OK. I still need to look at the preview green line.

Raspberrz, the video annotation text is locale enabled.

kevw, OK, Camera Params->Picture->exposure_compensation but works only if Exposure Mode is not off. I also added video_stabilization and rotation.

jbeale - well, my eyes are definitely bad or maybe I was too preoccupied with swinging the bucket to test the motion area feature, but I only just a few minutes ago noticed your question from yesterday. I'll get to that after this post.
There's a new preview-save script in scripts-dist that has a thumb save section based on your psave.sh. If you don't rerun the installer, which should otherwise really not be necessary, copy the scripts-dist/preview-save to the scripts dir and edit or use as a guide. To use the script as is, change in pikrellcam.conf:

Code: Select all

on_motion_preview_save $C/preview-save  $F $m $P $G $i $J $K $Y
%i %J %K %L becomes $i $J $K $Y (I was already using $L). Generally I think it works fine. The one issue is that the motion vectors come from the video capture path while the preview jpeg comes from the preview path and there can be a skew especially for small fast objects. Having the vectors let me put in a compensation which helps. Also there's a new motion_area_min_side in pikrellcam.conf that helps keep things sane. It helps with the skew and the small objects pikrellcam can detect would make the thumbs grainy if there's not some lower limit. Default is 60 pixels and for changing it, it won't be in pikrellcam.conf until you do something to make the program save the config file (modify something). Or you can "echo motion_area_min_side N > ~/pikrellcam/www/FIFO". I haven't put configuration for it in the OSD yet.

User avatar
jbeale
Posts: 3479
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 9:06 pm

Haven't had a chance to play yet, but I glanced over the new code. Wow, you've done a lot of work here, I really appreciate it! Even compensating for the channel skew, and handling small motion areas. Yes, my old solution would sometimes give me a grainy thumbnail from a tiny region with a bird, squirrel or falling leaf.

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 9:20 pm

jbeale wrote:I ran in verbose mode 'pikrellcam -v -vm &' and got some output like what is shown below (at night; car tail-lights). Just to make sure I understand- Are cvec[1,2] separate blobs at (x,y) with some motion vector direction (dx,dy), vector magnitude 'mag2' and above-threshold element count 'count' ?

Code: Select all

cvec[1]: x,y(58,13) dx,dy(8,0) mag2,count(64,5) reject:1 box:4x4
   in_box_count:5 motion:1 vetical: 0 sparkle:4
cvec[2]: x,y(62,13) dx,dy(8,0) mag2,count(64,17) reject:1 box:6x6
   in_box_count:19 motion:2 vetical: 0 sparkle:0
any:28 reject:2 sparkle:4 sparkle_expma:1.1
21:36:26 motion count:2 fail:0 window:8

cvec[1]: x,y(57,13) dx,dy(8,0) mag2,count(64,19) reject:0 box:6x8
   in_box_count:19 motion:2 vetical: 0 sparkle:1
cvec[2]: x,y(60,13) dx,dy(8,0) mag2,count(64,9) reject:2 box:4x6
   in_box_count:16 motion:1 vetical: 0 sparkle:0
any:31 reject:2 sparkle:1 sparkle_expma:1.1
21:36:26 motion count:2 fail:0 window:7  ***MOTION***

cvec[1]: x,y(49,14) dx,dy(8,0) mag2,count(64,23) reject:4 box:6x8
   in_box_count:22 motion:2 vetical: 0 sparkle:0
cvec[2]: x,y(69,11) dx,dy(9,0) mag2,count(81,4) reject:1 box:4x4
   in_box_count:4 motion:1 vetical: 0 sparkle:2
any:34 reject:5 sparkle:2 sparkle_expma:1.1
21:36:27 motion count:2 fail:0 window:4  ***MOTION***
There's one cvec (composite vector) possible for each motion region but the x,y coordinates are with respect to the total frame.. So there can be only one "blob" detected per region, which means that motion detect effectiveness can improve if there is more than one motion region even if for the scene you could have only one detect region. A failure in one region invalidates a positive detection in another region because there's a good chance the failure is from noise and the positive detection was then suspect. If that's wrong, one of the next detect tries is likely to succeed - except when there's sparkles - see below.
Here's another segment of output (again night; car headlights going by). It looks like valid motion needs (motion_count > 0 && fail_count == 0). I'm guessing it was rejected as a motion event due to a high "sparkle" count? So if I want to detect headlights at night, I need to change the existing code that increments "fail_count" when ( mreg->sparkle_count > 3 ) or change the threshold for detecting sparkles?
This is exactly the area I have on my list to go back to. The sparkle count limit of 3 is too restrictive and is a result of some early issues I had before refining the direction and density filtering. The test could be completely removed for almost all situations. I've left it in so far because how I change it is going to be coordinated with how I deal with the sunrise/sunset high sparkle count...
By the way, it is my observation that the camera image is very noisy right around sunset/sunrise, I guess you need high sparkle rejection around at that time, but through the night it is actually rather low-noise due to MMAL noise reduction / crushing of black values.

Code: Select all

cvec[2]: x,y(71,15) dx,dy(37,-1) mag2,count(1370,38) reject:23 box:8x10
   in_box_count:29 motion:2 vetical: 0 sparkle:2
cvec[3]: x,y(92,13) dx,dy(25,-1) mag2,count(626,8) reject:3 box:4x6
   in_box_count:7 motion:0 vetical: 0 sparkle:2
any:81 reject:26 sparkle:7 sparkle_expma:0.3
21:47:40 motion count:1 fail:1 window:4

cvec[0]: x,y(18,25) dx,dy(43,-4) mag2,count(1865,30) reject:32 box:8x8
   in_box_count:13 motion:0 vetical: 0 sparkle:3
cvec[1]: x,y(56,15) dx,dy(40,-2) mag2,count(1604,13) reject:3 box:6x6
   in_box_count:13 motion:0 vetical: 0 sparkle:1
cvec[2]: x,y(66,15) dx,dy(39,-1) mag2,count(1522,35) reject:16 box:8x10
   in_box_count:18 motion:0 vetical: 0 sparkle:1
any:134 reject:51 sparkle:5 sparkle_expma:0.4
21:47:40 motion count:0 fail:3 window:3

cvec[0]: x,y(19,24) dx,dy(45,-3) mag2,count(2034,47) reject:33 box:10x10
   in_box_count:31 motion:0 vetical: 0 sparkle:4
cvec[2]: x,y(69,16) dx,dy(34,-1) mag2,count(1157,20) reject:11 box:6x8
   in_box_count:16 motion:2 vetical: 0 sparkle:0
any:116 reject:44 sparkle:5 sparkle_expma:0.4
21:47:40 motion count:1 fail:1 window:2

cvec[0]: x,y(20,24) dx,dy(48,-4) mag2,count(2320,60) reject:78 box:12x12
   in_box_count:18 motion:0 vetical: 0 sparkle:4
cvec[1]: x,y(45,18) dx,dy(41,-1) mag2,count(1682,27) reject:15 box:8x8
   in_box_count:0 motion:0 vetical: 0 sparkle:0
any:184 reject:93 sparkle:4 sparkle_expma:0.5
21:47:41 motion count:0 fail:2 window:1

cvec[0]: x,y(11,24) dx,dy(55,-3) mag2,count(3034,45) reject:29 box:10x10
   in_box_count:33 motion:2 vetical: 0 sparkle:3
cvec[1]: x,y(38,16) dx,dy(43,-6) mag2,count(1885,12) reject:4 box:6x6
   in_box_count:12 motion:0 vetical: 0 sparkle:0
any:93 reject:33 sparkle:3 sparkle_expma:0.5
21:47:41 motion count:1 fail:1 window:0

cvec[0]: x,y(21,26) dx,dy(47,-3) mag2,count(2218,42) reject:17 box:10x10
   in_box_count:13 motion:0 vetical: 0 sparkle:3
any:62 reject:17 sparkle:3 sparkle_expma:0.5
21:47:41 motion count:0 fail:1 window:0
Yes, you have pretty much pinned down the area where I'm planning to spend effort to improve the motion detection. The thing is, I really think it detects motion otherwise pretty well, so I plan to be careful about how I change things. I spent a good bit of time comparing the -vm cvec output to what I was seeing on the OSD and that drove the evolution of how I wrote the detection routine. It was pretty quickly apparent to me that it was easy to detect motion - the trick was finding a reason to reject motion and that led to the direction filtering and density check. One day after adjusting ratios and trying a few things, I noticed motion detection was working pretty well. I let it run for a day, and then another, and I finally turned to my friend and told her "I can't believe this is working like this... I'm not touching this code again!" Well, except for the sparkle stuff I would probably be sticking to that statement.
Also, could you comment on the goal of the code below? You're creating a nearly-square search box by adding two counts to width or height each time? Is this to avoid a square-root operation?

Code: Select all

		/* Get a box that will hold at least 2x mag2_limit_count vectors
		|  and count the vectors within the box.
		*/
		for (mreg->box_w = 4, mreg->box_h = 4;
					mreg->box_w * mreg->box_h <= 2 * cvec->mag2_count;   )
			{
			if (mreg->box_h <= mreg->box_w)
				mreg->box_h += 2;
			else
				mreg->box_w += 2;
			}
Yeah, I was developing on a Pi 2 and I wasn't sure if I might be putting too much of a load on a B+. So yes, I did avoid sqrt(). The box is for a vector density check and is square because I wasn't making any assumptions about object geometry. I have thought about doing a count by walking through adjacent touching vectors, but that is getting into heavier processing and it might begin to push a B+. Plus I don't know if any issues can come up just from spending too much time in a mmal callback thread.

User avatar
jbeale
Posts: 3479
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 10:44 pm

All versions of R-Pi have hardware floating point support, and a single sqrt() call may actually be faster than a bunch of iterations of a loop that includes a multiply, but I haven't tested that. http://www.roylongbottom.org.uk/Raspber ... hmarks.htm says that the RPi at 700 MHz clock has 58 MFLOPS of performance (single-precision), and the RPi-2 at 900 MHz has 156 MFLOPS. So yes, RPi2 is faster, but I think they're both pretty fast in this context. EDIT: I found a reference suggesting SQRT is about 30 times slower than a multiply, so maybe the for-loop approach is justified.

Having been through the iterative-optimization process a few times with other image detection systems... it would be great if you could expose as many detection parameters as possible in a config file. Almost everyone will simply accept the defaults, but those who want to tune to a specific situation have that flexibility, and if someone comes up with a better general-purpose tuning, you can adopt that at any later time.

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Wed Jul 22, 2015 11:29 pm

jbeale wrote: it would be great if you could expose as many detection parameters as possible in a config file.
That's a good idea. Other environments maybe could find some useful tuning of the parameters.

User avatar
jbeale
Posts: 3479
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 5:05 am

Excellent work with the active-area thumbnail option. Together with a simple PHP page like below added to /home/pi/pikrellcam/www I can see at a glance what's been going on in the yard.

Code: Select all

<?php
function showGallery( $pathToImages, $pathToThumbs, $rThumbs )
{
  $output = "<html>";
  $output .= "<head><title>Thumbnails</title></head>";
  $output .= "<body>";
  $output .= "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">";
  $output .= "<tr>";

  $dir = opendir( $pathToThumbs );   // open the directory
  $a=array();  // hold filenames in array so we can sort them in order
  while (false !== ($fname = readdir($dir)))   // loop through the directory
  {
    if ($fname != '.' && $fname != '..')  // strip the . and .. entries out
    {
      $a[]=$fname;  // add this filename to the array
    }
  }
  closedir( $dir );    // close the directory

  $counter = 0;
  sort($a);  // sorts the array of filenames in-place
  foreach($a as $fname){
      $output .= "<td valign=\"middle\" align=\"center\"><a href=\"{$fname}\">";
      $output .= "<img src=\"{$rThumbs}{$fname}\" border=\"0\" />";
      $output .= "</a></td>";

      $counter += 1;
      if ( $counter % 5 == 0 ) { $output .= "</tr><tr>"; }  // 5 columns
  }

  $output .= "</tr>";
  $output .= "</table>";
  $output .= "</body>";
  $output .= "</html>";
  echo $output;  // send out the HTML page
}
showGallery("media/stills/","media/stills/","media/stills/");
?>

kevw
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 8:33 am

billw wrote:I've pushed a new pikrellcam.

kevw, OK, Camera Params->Picture->exposure_compensation but works only if Exposure Mode is not off. I also added video_stabilization and rotation.
Great, thanks Bill appreciated - I have an area that doesn't work well for spot or average exposure so need to bump it up

If you change image resolution after setting the EV value it resets it back to 0, so you need to go change the EV value again - fyi

Cheers,

Kev

YvesG
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 9:01 am

Hi Bill, could you also add a function "on_still_creation" similar to "on_motion_preview_save"? I would like to be able to automatically send me a mail with the picture taken manually...

Thanks
Yves

kevw
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 11:11 am

Not sure what changed but video hung and I cant get it working again - same symptoms after reboots :-/ I upgraded to the latest version this morning and have been playing with options within the OSD.

[email protected] ~/pikrellcam $ pikrellcam
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Segmentation fault

[email protected] ~/pikrellcam $ tail -n 30 /tmp/pikrellcam.log

2015-07-23 12:08:10 ==== PiKrellCam started ====
using FIFO: /home/pi/pikrellcam/www/FIFO
using mjpeg: /run/pikrellcam/mjpeg.jpg
execl:[/home/pi/pikrellcam/scripts-dist/init /home/pi/pikrellcam /var/www/media /run/pikrellcam/mjpeg.jpg /home/pi/pikrellcam/www/FIFO /tmp/pikrellcam.log]
www/media link is already set to /var/www/media
/home/pi/pikrellcam/www/config.php: MJPEG_FILE not changed.
/home/pi/pikrellcam/www/config.php: FIFO_FILE not changed.
/home/pi/pikrellcam/www/config.php: PIKRELLCAM not changed.
execl:[/home/pi/pikrellcam/scripts/startup /home/pi/pikrellcam /var/www/media /tmp/pikrellcam.log]
MOUNT_DISK is not set.
execl:[sudo mkdir -p /run/pikrellcam]
execl:[sudo chown pi.www-data /run/pikrellcam]
execl:[sudo chmod 775 /run/pikrellcam]
circular buffer allocate: 29.25 MBytes (13 seconds at 18.0 Mbits/sec)
camera_component_create: mmal_component_enable failed. Status: Out of resources
[email protected] ~/pikrellcam $

YvesG
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 11:39 am

Hi Kev, just a guess (i don't have any trouble with the new version), can you check the split between memory and GPU (advanced option of raspi-config)?

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 2:08 pm

kevw wrote: [email protected] ~/pikrellcam $ pikrellcam
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Segmentation fault
Make sure there's not a pikrellcam still running. That error happens when something else (another pikrellcam or other program) has opened the camera so it's busy. Do a killall -9 pikrellcam.

Raspberrz
Posts: 11
Joined: Sat Nov 23, 2013 11:17 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 2:18 pm

billw wrote:Raspberrz, the video annotation text is locale enabled.
And it's working like a charm!!!
Thank you very much!!! :D

...now I'm looking at the "active-area thumbnail option": You guys are so wonderful :P

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 3:33 pm

YvesG, OK, on_still_capture command is added. Either add it to pikrellcam with for example:

Code: Select all

on_still_capture mpack -s [email protected]$H $s [email protected]
or
on_still_capture $C/still-capture $s $P $G
Or run pikrellmcam, modify something in the config to make it write a new config file, and then stop
and pikrellcam.conf should be written with the option available to edit.

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 3:36 pm

kevw, so far when I change exposure compensation the value stays OK, so I'm not sure and
will check some more. Also, I may be wrong about the mmal error being another process having
the camera open. I checked and that is not the exact error I get when the camera is busy.

YvesG
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 3:49 pm

billw wrote:YvesG, OK, on_still_capture command is added.
Thanks Bill !!! works as expected !!!

caldimerda
Posts: 67
Joined: Tue Oct 09, 2012 9:41 am

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 3:52 pm

Hi billw

Nice interface. Thanks for making it available. One question. I use a Pi Noir and set saturation to 99 for the day and -99 at night. Is it possible to set that in at-commands.conf? Do you accept the same FIFO commands as Raspimjpeg?

Thanks

kevw
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 4:18 pm

billw wrote:
kevw wrote: [email protected] ~/pikrellcam $ pikrellcam
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Segmentation fault
Make sure there's not a pikrellcam still running. That error happens when something else (another pikrellcam or other program) has opened the camera so it's busy. Do a killall -9 pikrellcam.
Thanks and sorry - I'll hold my hands up and let you know I'm testing this on pi that already has RPI Web Cam Interface on and you were right, another process (raspimjpeg) was nabbing the cam - this along with apache2 :-|

Mental note is to ensure apache2 is shut and no RPI cam i/f process isnt running before posting!

Thanks so much for opening up the features and developing software - its really appreciated. I saw (like jbeale) a great example last night where motion was picked up in such low light I thought it was a false positive.

billw
Posts: 402
Joined: Tue Sep 18, 2012 8:23 pm

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 4:57 pm

caldimerda wrote: Nice interface. Thanks for making it available. One question. I use a Pi Noir and set saturation to 99 for the day and -99 at night. Is it possible to set that in at-commands.conf? Do you accept the same FIFO commands as Raspimjpeg?
For sure most FIFO commands are different, maybe all because I think Raspimjpeg uses two
character codes for its commands and I'm a lot more verbose :)

So, edit at-commands.conf and add in:

Code: Select all

daily sunrise-5 "@saturation 99" 
daily sunset+5 "@saturation -99"
Substitute in however many minutes offset you want, or you can use dusk-N and dawn+N
for minutes offset from dusk/dawn
Your latitude and longitude needs to be set in pikrellcam.conf and you need the quotes around
the FIFO command. The '@' flags it as a FIFO command, otherwise it's a system command
or script. All at-command.conf file modification will be reloaded into the program on the minute
tick, so you should not need to restart. Check log file (default /tmp/pikrellcam.log) if you want to
verify that the new commands were automatically loaded in OK.

EDIT: but you will need to restart pikrellcam if you edit pikrellcam.conf for latitude/longitude.

EDIT2: Well, I should be accurate. An at-command.conf command "@command" is an internal
command that does not actually go through the FIFO. It runs "as if" it came through the FIFO.
If you have an at_command like: daily sunrise "$C/some-script $P"
Then the script is passed the FIFO path $P as an argument and it can send commands actually
through the FIFO.

caldimerda
Posts: 67
Joined: Tue Oct 09, 2012 9:41 am

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 7:35 pm

Thankyou very much. Not had much luck with the motion app so I'll let you know how I get on with this.

caldimerda
Posts: 67
Joined: Tue Oct 09, 2012 9:41 am

Re: PiKrellCam: motion vector detect + OSD web interface

Thu Jul 23, 2015 9:11 pm

Ah. No picture at night. I would normally (raspimjpeg) get a reasonable image in dim light. There's an IR light too so it should work all night. But the image is black so there's a setting not right. Exposure mode is 'night'. Saturation -99. Any ideas?

Thanks

Return to “Camera board”