PiKrellCam: motion vector detect + OSD web interface


1099 posts   Page 1 of 44   1, 2, 3, 4, 5 ... 44
by billw » Mon Jul 13, 2015 3:55 pm
For a while I've had in mind a raspiMJPEG like program with a
different approach to the web interface and I needed a different
internal design to get the features I wanted.

So I've written PiKrellCam and I thought I would go ahead and put
it out there. There's no dependence on any external motion program
and the motion detection does vector processing with what I think
are some pretty good results.

You can see that and the OSD in this video:
http://youtu.be/zyqMqTK994U

And you can find out about it here:
http://billw2.github.io/pikrellcam/pikrellcam.html
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by tomtgrp » Thu Jul 16, 2015 3:31 pm
Hello,

got it up and running within a few minutes and: looks very promising! Congratulations! Great Work!

It will become my top favorite for building serveral rpi surveillance cams.

BR
Tom
Posts: 41
Joined: Thu Jul 09, 2015 8:35 am
by jbeale » Fri Jul 17, 2015 3:49 am
Very impressive work! I love the demo of the swinging can showing the average motion vector in each region.

As you may know, the RPi Cam Web Interface (raspimjpeg) does have a working internal motion vector option as well. The problem I have had with it, both using external 'motion' and the internal motion vector mode, is that I sometimes get a string of "error in i frame list" notes in the log and the program locks up for a variable period of time. Have you experienced anything similar with your code?

I was able to install without any problem. Is there an option to change the camera orientation? Due to the way my camera is mounted (ribbon cable at the top) I want to rotate the image 180 degrees.

EDIT: to answer my own question, just edit rotation 0 to be rotation 180 in the file ~/.pikrellcam.conf
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by billw » Fri Jul 17, 2015 2:28 pm
jbeale wrote:Very impressive work! I love the demo of the swinging can showing the average motion vector in each region.

I thought about training a cat to walk back and forth in front of the camera, but the bucket
saved me some time.
As you may know, the RPi Cam Web Interface (raspimjpeg) does have a working internal motion vector option as well. The problem I have had with it, both using external 'motion' and the internal motion vector mode, is that I sometimes get a string of "error in i frame list" notes in the log and the program locks up for a variable period of time. Have you experienced anything similar with your code?

I haven't seen lock ups or errors like that. But then, I use mutex locks to protect the
key frame and video circular buffer data.
I haven't actually done any debugging of raspimjpeg and I sorta hesitate to say this because
it is just my suspicion, but I honestly wonder how you can expect to get away with running a multi
threaded app without mutex protecting data modified from more than one thread.
I was able to install without any problem. Is there an option to change the camera orientation? Due to the way my camera is mounted (ribbon cable at the top) I want to rotate the image 180 degrees.

EDIT: to answer my own question, just edit rotation 0 to be rotation 180 in the file ~/.pikrellcam.conf

I did steer away from putting configs on the web page that I thought would be very rarely
or only one time changed, but I should point that out in the docs or go ahead and add
to the web page if that's what is wanted. The documentation I have is really just the web
page and the ~/.pikrellcam config files and it's the first cut. As I get feedback I'll try to fill
out the docs or make changes to the program.

EDIT: I'm referring to two different web pages above, the OSD web page for configs and
the pikrellcam home web page for docs.
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by jbeale » Sat Jul 18, 2015 3:14 am
So far, the program is looking very good, thank you for all the work! However, how do I get it to start up from boot in "motion" mode? It does start up, but without the motion detection active so I have to push the button manually to start detecting motion. I do have "motion_enable on" in ~/.pikrellcam/pikrellcam.conf

Code: Select all
pi@rp22 ~ $ cat /tmp/pikrellcam.log

2015-07-17 19:54:51 ==== 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 /home/pi/pikrellcam/media /run/pikrellcam/mjpeg.jpg /home/pi/pikrellcam/www/FIFO /tmp/pikrellcam.log]
  www/media link is already set to /home/pi/pikrellcam/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 /home/pi/pikrellcam/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: 11.00 MBytes (11 seconds at 8.0 Mbits/sec)
command_process: motion_enable toggle

Also, below is a sample of the log file from a motion-triggered capture. I'm curious about saving the mjpeg.jpg image four times, and then later throwing it away. Is there a config option to save a still preview for captured video, which I don't have selected?
Code: Select all
Video record: /home/pi/pikrellcam/media/videos/motion_2015-07-17_21.55.16_23.mp4.h264 ...
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-17_21.55.16_23.jpg
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-17_21.55.16_23.jpg
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-17_21.55.16_23.jpg
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-17_21.55.16_23.jpg
Video motion record stopped.
execl:[(MP4Box -quiet -fps 25 -add /home/pi/pikrellcam/media/videos/motion_2015-07-17_21.55.16_23.mp4.h264 /home/pi/pikrellcam/media/videos/motion_2015-07-17_21.55.16_23.mp4 2> /dev/null ; rm /home/pi/pikrellcam/media/videos/motion_2015-07-17_21.55.16_23.mp4.h264)]
event_preview_dispose(); removing /run/pikrellcam/motion_2015-07-17_21.55.16_23.jpg
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by billw » Sat Jul 18, 2015 2:31 pm
="jbeale"So far, the program is looking very good, thank you for all the work! However, how do I get it to start up from boot in "motion" mode? It does start up, but without the motion detection active so I have to push the button manually to start detecting motion. I do have "motion_enable on" in ~/.pikrellcam/pikrellcam.conf

Is it possible you edited the option with the program running and then pikrellcam over wrote the config file before you restarted? Check the config file again after pikrellcam starts and see if the option is still on. If it is but motion didn't start up enabled correctly, it's a bug.
But I just restarted here several times and it is working for me so please can you verify that.

You can also change the option in the gui, then restart:
Setup->Motion->Settings->Startup_Motion
When you change the option to "on", you have to hit the SEL button to actually get the option set.
Also, below is a sample of the log file from a motion-triggered capture. I'm curious about saving the mjpeg.jpg image four times, and then later throwing it away. Is there a config option to save a still preview for captured video, which I don't have selected?

If preview_save_mode is "best" a preview jpeg is saved during a motion record each time a motion vector is judged better, so there can be several saves. If the mode is "first", it will be done once.

Ah, and for a still preview save, I see I forgot something but I just pushed an update. So if you do a update with a git pull, you can set the on_motion_begin command to run an internal command:
Code: Select all
    on_motion_begin @still

Without that you can still do it if you write a script that writes a "still" command to the FIFO and set the on_motion_begin to your script.

Then there's the on_preview_save_cmd which I use to email me a motion event jpeg. You could write script that does that if you want and copies the jpeg to the stills directory or anywhere. Something like:
Code: Select all
    on_preview_save_cmd   my_script   $F  $m/still  $P  any_other_arg_you_need

The $F specifies the jpeg preview file and $m is the media directory and $P the FIFO.
But $F is the smaller preview sized jpeg and may not be what you want so this script could also write a "still" command to the FIFO to get a full sized jpeg.

So I guess I've left this feature as something for users to set up how they want and if there is some missing flexibility I would tackle it by adding more information that can be passed to a script rather than hardwiring a still save. Maybe there could be a default script users could edit...
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by jbeale » Sat Jul 18, 2015 3:16 pm
I just did a git pull and reinstalled, and I got an error in the startup config:
Code: Select all
Starting PiKrellCam install...
No packages need to be installed.
    Bad config_value_bool_set: on
Bad config file option: motion_enable on

So what should it be? 'motion_enable True' or something else?

EDIT: after setting it in the browser as you explained, it does work. I also tried saving a still with 'on_motion_begin @still' , which works but has the undesirable side effect of skipping several frames (looks like about 1/2 second worth) in the video at the moment of saving the still. I think that is unavoidable if you switch MMAL from video to still mode to grab a full-res still, instead of just using the MJPEG frame as the still.
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by billw » Sat Jul 18, 2015 4:03 pm
Yeah, I think the video glitch is unfortunately unavoidable. After the git pull you should not need to rerun the install script but regardless I need to look at that error. Meanwhile I put together a script I'm thinking I will add to the scripts dir. You can uncomment sections for emailing the preview, for copying the preview or for taking a full res still. Just use the preview copy part to avoid the video glitch.
Put this as the on_motion_preview_save command in pikrellcam.conf:
Code: Select all
on_motion_preview_save   $C/preview-save $F $m $P $G

And copy this as the "preview-save" command in the scripts directory (make it executable):

Code: Select all
#!/bin/bash

# This is a motion event on_motion_preview_save  script.
#
# Argument substitution done by PiKrellCam before running this script:
#   $C - scripts directory so this script is found.
#   $F - the preview jpeg filename.
#   $m - the media directory full path
#   $P - the command FIFO
#   $G - log file configured in ~/.pikrellcam/pikrellcam.conf.
#
# In ~/.pikrellcam.conf, set the on_motion_preview_save as:
#
# on_motion_preview_save  $C/preview-save  $F $m $P $G

PREVIEW_JPEG=$1
MEDIA_DIR=$2
FIFO=$3
LOG_FILE=$4

# uncomment any echo to the LOG_FILE if you want logging.

# uncomment and set your email address to email the preview jpeg.
#
#mpack -s pikrellcam@$HOSTNAME $PREVIEW_JPEG myuser@gmail.com
#echo "mpack -s pikrellcam@$HOSTNAME $PREVIEW_JPEG myuser@gmail.com" >> $LOG!

# uncomment to copy the low resolution preview jpeg to the stills directory.
# You can copy it anywhere you want.
#
#cp $PREVIEW_JPEG $MEDIA_DIR/stills
#echo "cp $PREVIEW_JPEG $MEDIA_DIR/stills" >> $LOG_FILE

# uncomment if you want to take a still.  This is probably only useful if
# preview_save_mode is "first" because if the mode is "best" the still will
# be taken after the action has ended.   So use the on_motion_begin command
# to take a still if preview_save_mode is "best".  The on_motion_begin
# command can be a script like this or the internal command "@still"
# Note that taking a full resolution still can put a glitch into the motion
# video being recorded because the camera has to switch modes.
#
#echo "still" > $FIFO
#echo "preview save script still." >> $LOG_FILE

# TODO: add a mechanism to discover the still file name so it can be post
# processed or moved.  And/or add ability for a named still.


And yeah, I messed up the names in my previous post. It's on_motion_preview_save and not on_preveiw_save_cmd as I wrote.

EDIT: and I've had to edit this post twice and who knows, maybe counting, to get "on_motion_preview_save" written correctly. Sheesh, I created the name and I can't even get it straight!
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by billw » Sat Jul 18, 2015 6:06 pm
jbeale wrote:I just did a git pull and reinstalled, and I got an error in the startup config:
Code: Select all
Starting PiKrellCam install...
No packages need to be installed.
    Bad config_value_bool_set: on
Bad config file option: motion_enable on

So what should it be? 'motion_enable True' or something else?

During the install pikrellcam is run to check that config files exist and it failed to recognize your setting of "motion_enable on" and the boolean read function says it couldn't read "on". But it's exactly supposed to read that as well as "yes", "true", or "1". But I can reproduce if I put a TAB or space after the "on" so I'm going to assume something like that happened and I'll add something to prevent that.
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by jbeale » Sat Jul 18, 2015 7:25 pm
Good stuff! After installing /home/pi/pikrellcam/scripts/preview-save and editing to uncomment the
Code: Select all
cp $PREVIEW_JPEG $MEDIA_DIR/stills

part, and making it executable, and restarting now I am seeing the preview stills in the stills directory, very good! I also changed the setting to "preview clean" to avoid the misc. text overlay on the saved preview at lower left.

This is already a great system, very usable and so far I have not seen the glitches I had with the older RPi Cam Web Interface system (raspimjpeg etc). Very impressed with how it can pick up smaller moving objects, while so far ignoring tree branches in the wind.

New feature request: is there a way to export the (x,y)(w,h) or (x1,y1)(x2,y2) coordinates of a rectangle around the area of motion in the saved preview? That way an external script can use imagemagick, etc. to crop out just the area with the detected object. I have done this with the old "motion" program and it was useful to generate a preview page when you have a lot of events, which occupy a small fraction of the whole field of view. Otherwise a page of thumbnail images isn't useful when the moving object is too small to see in a thumbnail.

Thanks again for this great contribution to the R-Pi software ecosystem!
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by billw » Sat Jul 18, 2015 8:12 pm
jbeale wrote:This is already a great system, very usable and so far I have not seen the glitches I had with the older RPi Cam Web Interface system (raspimjpeg etc). Very impressed with how it can pick up smaller moving objects, while so far ignoring tree branches in the wind.

Thanks, it can be fooled from time to time, but wind blown tree branches can have motion vector direction variability and I think the vector direction filtering helps there. Let me take this opportunity to mention a couple of things. Tree branch shadows on some high contrasting ground coverings (concrete) do pose a risk for false triggering but maybe a custom motion region configuration set for various times of the day could help if you have that problem. Also, there's a few minutes after sunset and before sunrise when the camera can produce many of the "sparkle" vectors and the way I have it set up now, motion detection is mostly blocked for those minutes. I will be making changes though. Worst case should be that for that time I'll auto adjust the sensitivity a little bit and not do a hard block based on the sparkle count.
New feature request: is there a way to export the (x,y)(w,h) or (x1,y1)(x2,y2) coordinates of a rectangle around the area of motion in the saved preview? That way an external script can use imagemagick, etc. to crop out just the area with the detected object. I have done this with the old "motion" program and it was useful to generate a preview page when you have a lot of events, which occupy a small fraction of the whole field of view. Otherwise a page of thumbnail images isn't useful when the moving object is too small to see in a thumbnail.

The information is there so it should be no problem. I expect in a day or two I can add it in and test it. But each motion region can produce a composite vector. Two objects moving in different regions or a larger single object spanning two regions will do it. So I'll have to come up with a way to pass multiple sets of coordinates. Maybe a varargs to the script approach. $1 the number of sets, and the script then can know how many sets to read. But you've done this, so let me know if you have a preference for how to handle this. Or would you prefer just passing the largest count vector, or maybe call the script separately for each box?
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by jbeale » Sat Jul 18, 2015 8:41 pm
Interesting point, you could have more than one region of motion. In the past that wasn't an issue because I was dealing with a simpler system that lumped everything together (largest bounding rectangle). My preference would be a single rectangle enclosing the largest detected region of motion, or if it is any easier, a rectangle enclosing all (above-threshold) areas of motion. For my purpose (just generating a page of thumbnail images) I don't want to deal with handling more than one separate motion area in the same frame.
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by billw » Sat Jul 18, 2015 8:59 pm
jbeale wrote:Interesting point, you could have more than one region of motion. In the past that wasn't an issue because I was dealing with a simpler system that lumped everything together (largest bounding rectangle). My preference would be a single rectangle enclosing the largest detected region of motion, or if it is any easier, a rectangle enclosing all (above-threshold) areas of motion. For my purpose (just generating a page of thumbnail images) I don't want to deal with handling more than one separate motion area in the same frame.

Yeah I just thought of something similar. If more than one vector I'll combine them into a total frame composite box. If it's one object spanning two regions that's really what you want. If it's two objects separated you might get a bigger box than you want, but actually that is the less likely scenario. Usually motion is triggered by a single object or maybe a couple of people walking together. I haven't seen much of two independent objects generating simultaneous triggers.
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by jbeale » Sat Jul 18, 2015 9:34 pm
Just for reference, here's what I did earlier with mmal-motion (similar to standard 'motion') to extract the region of interest from the full frame preview JPEG using ImageMagick 'convert':
https://www.raspberrypi.org/forums/view ... 5&p=405266

Code: Select all
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
; on_picture_save value
on_picture_save /home/pi/mmal/psave.sh %f %i %J %K %L


Code: Select all
#!/bin/bash
XT=`expr $2 / 2`
XO=`expr $4 - $XT`
YT=`expr $3 / 2`
YO=`expr $5 - $YT`
convert $1 -crop $2x$3+$XO+$YO -resize 200x200 /home/pi/mvideo/thumbs/${1#/home/pi/mvideo/}
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by jbeale » Sun Jul 19, 2015 4:46 am
Just to extoll the virtues of this program a bit more- local sunset was at 8:26 pm today, and PiKrellCam continued to capture several events up to a half an hour later (8:54 pm) without any false detects. I had to look several times at the still capture before realizing that was a bicycle going by. Well done!

Image

The (1920x1080, 24 fps, 8 Mbps) video capture on this event was significantly darker than the preview still JPEG- I suspect the h264 compressor (or MMAL preprocess before video output) just crushes the noisy near-black pixels to true black, to reduce bitrate.

Image
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by YvesG » Sun Jul 19, 2015 3:53 pm
Very nice and impressive work! thanks for sharing this with us.
Until now i was using motion but your program seems much more easy to use and configure...

One question, i changed video preset from 1080p to 1296x972 (in order to get a larger field of view) the preview is OK but the video recording is KO (a green picture with artifacts) with this resolution. Is it working for you? what i am doing wrong?

Update : works fine now with 1296x972 don't know what i have changed
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm
by Raspberrz » Mon Jul 20, 2015 1:45 pm
YvesG wrote:Very nice and impressive work! thanks for sharing this with us.

+1 Yes!
I'm playing with it for some days and it is detecting motion almost dead reliable!!!
I'm a little confused about the annotate function to mmaling(?) the date string into the pictures. How can I get this to use my locale to display the date in my language?
Posts: 11
Joined: Sat Nov 23, 2013 11:17 pm
by billw » Mon Jul 20, 2015 2:37 pm
[
I'm a little confused about the annotate function to mmaling(?) the date string into the pictures. How can I get this to use my locale to display the date in my language?

I could be wrong, but I remember reading on the forum that the annotation was originally just for gpu/mmal development debugging so I'm not sure it has the font display capability to do it for all locales. Regardless, I'll need to add a locale setting function to the program before you can even try it.
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by lassiko » Tue Jul 21, 2015 10:10 am
Hi. Just tried to install this but cannot get it working.
No matter if i select default port (80) or set my own i cannot access it through website.

http://my_pi_IP only shows text: Welcome to nginx!

ps -Af shows that pikrellcam is running:
Code: Select all
 pi        2187  2177  8 13:01 ?        00:00:17 /home/pi/pikrellcam/pikrellcam


/tmp/pikrellcam/pikrellcam.log
Code: Select all
2015-07-21 13:01:30 ==== 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 /home/pi/pikrellcam/media /run/pikrellcam/mjpeg.jpg /home/pi/pikrellcam/www/FIFO /tmp/pikre$
  www/media link is already set to /home/pi/pikrellcam/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 /home/pi/pikrellcam/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: 26.25 MBytes (35 seconds at 6.0 Mbits/sec)


Maybe some settings are mixing from my RPi cam web interface which i was running before on a same RPi?
Posts: 10
Joined: Tue May 12, 2015 7:04 pm
by billw » Tue Jul 21, 2015 2:48 pm
lassiko wrote:Hi. Just tried to install this but cannot get it working.
No matter if i select default port (80) or set my own i cannot access it through website.

http://my_pi_IP only shows text: Welcome to nginx!

If you try to set up port 80, there should be a file: /etc/nginx/sites-available/pikrellcam
If you are running wheezy, that file should have the lines:
Code: Select all
listen 80;
...
root /home/pi/pikrellcam/www;

or if you are running jessie:
Code: Select all
listen 80 default_server;
...
root /home/pi/pikrellcam/www;

And there should be a link in /etc/nginx/sites-enabled:
Code: Select all
default -> /etc/nginx/sites-available/pikrellcam

If you set a port other than 80, that port number should replace the 80 in /etc/nginx/sites-available/pikrellcam
and the link in /etc/nginx/sites-enabled should be:
Code: Select all
pikrellcam -> /etc/nginx/sites-available/pikrellcam

If you edit files or change links restart nginx with:
Code: Select all
sudo service nginx restart

If that doesn't help, post the output you get by running:
Code: Select all
cd /etc/nginx
ls -Rl; grep -r listen sites-*; grep -r root sites-*
Posts: 303
Joined: Tue Sep 18, 2012 8:23 pm
by lassiko » Tue Jul 21, 2015 6:01 pm
I needed to install nginx again to get it working, now it seems to work.
Posts: 10
Joined: Tue May 12, 2015 7:04 pm
by jbeale » Wed Jul 22, 2015 4:52 am
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***

Video record: /home/pi/pikrellcam/media/videos/motion_2015-07-21_21.36.26_3.mp4.h264 ...
Event add [motion preview save] period=0
Event func -> [motion preview save] period=0
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-21_21.36.26_3.jpg
cvec[1]: x,y(55,14) dx,dy(9,0) mag2,count(81,27) reject:1 box:8x8
   in_box_count:27 motion:2 vetical: 0 sparkle:3
any:32 reject:1 sparkle:4 sparkle_expma:1.1
21:36:26 motion count:1 fail:0 window:6  ***MOTION***

Event add [motion preview save] period=0
Event func -> [motion preview save] period=0
event preview save: copy /run/pikrellcam/mjpeg.jpg -> /run/pikrellcam/motion_2015-07-21_21.36.26_3.jpg
cvec[1]: x,y(52,14) dx,dy(9,0) mag2,count(81,25) reject:3 box:8x8
   in_box_count:25 motion:2 vetical: 0 sparkle:0
any:31 reject:3 sparkle:3 sparkle_expma:1.1
21:36:26 motion count:1 fail:0 window:5  ***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***

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?

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

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;
         }
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by kevw » Wed Jul 22, 2015 11:16 am
Hi,

looking forward to playing with this although after a bit off difficulty getting it working (needed php-fpm installing) I find that videos aren't able to be played - I get either a green overlay or the greyish corruption. Are there any settings causing this or any other video dependancies? I'm running an RPI2 that I've been using with the web cam interface with no issues.

Cheers,

Kev
Posts: 22
Joined: Wed Aug 27, 2014 1:49 pm
by YvesG » Wed Jul 22, 2015 12:24 pm
kevw wrote: I find that videos aren't able to be played - I get either a green overlay or the greyish corruption. Are there any settings causing this or any other video dependancies? I'm running an RPI2 that I've been using with the web cam interface with no issues.


Hi, i am using a RPI2 too with no problem of video corruption and no other specific packages than those described into the installation notes. So can you try with different browsers (i am using Firefox) and can you stop/start PiKrellCam and change video presets also...
Posts: 46
Joined: Wed Oct 03, 2012 6:54 pm
by kevw » Wed Jul 22, 2015 12:38 pm
Hi Yves,

yep its a resolution thing - 1080p is fine but I'm needing the wider field of view so selected 1296x972. I actually see a bit of a green strip at the bottom on the live preview with this setting. When recording video, either manually or motion I get green in FF & Chrome and nothing at all in Safari. The video file itself doesn't play properly in quicktime or VLC.

Cheers,

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