Jorik
Posts: 4
Joined: Mon Aug 19, 2013 10:09 am

Re: Lightweight python motion detection

Mon Aug 19, 2013 4:03 pm

When I type this:

ps -ef | grep raspistill

I get this:


2348 2338 0 15:59 pts/0 00:00:00 grep --color=auto raspistill

Jorik
Posts: 4
Joined: Mon Aug 19, 2013 10:09 am

Re: Lightweight python motion detection

Mon Aug 19, 2013 5:02 pm

OK, thanks.

But does anyone have an other idea how to fix this.

Thanks

Krisduck
Posts: 4
Joined: Thu Jun 06, 2013 6:14 am

Re: Lightweight python motion detection

Tue Aug 20, 2013 6:54 am

kevpatts2 wrote:
Krisduck wrote:Is anyone else getting (mostly) green horizontal lines across their images? It's triggering the motion capture, so I've got a bunch of pics with green lines across them, but with no other movement. It seems like it might mostly be in lower-light situations, but I think there's been a few in brighter shots too. I'll try to keep an eye on it.

Cheers,

Kris
Hey Kris, I'm having no such problems, but it may be due to a subtlety in your code. Can you post the troublesome script and I'll see if I can reproduce the green lines problem?

How low light?
I tried switching to one of the other scripts just to see if there was a problem with the script. It's still capturing pictures when there's no actual motion, but each captured pic seems to be a different colour temp and brightness. Not sure if I can upload attachments yet, but I can probably post it somewhere and link it. It doesn't seem to be doing the green lines so much as before, but that might have been where I placed it.

I tried placing a box right in front of the camera. It still took repeated pictures, though in looking at the pics, I noticed the red LED from the camera reflecting in the glossy surface of the box. Perhaps I'll try messing with the sensitivity enough to not trigger all the time. I'm just concerned about dropping it too much that it's no longer useful.

Thanks for the help so far,

Kris

zeronickname
Posts: 13
Joined: Sat Jul 20, 2013 4:35 pm

Re: Lightweight python motion detection

Tue Aug 20, 2013 1:16 pm

Jorik wrote:Hi,

When I run the script on my Rpi, I always get the same error.
I have really no idea how to fix it.
I also tried the script from pageauc but I get the same error.
This is the error:

Traceback (most recent call last):
File "motiondetect.py", line 69, in <module>
image1, buffer1 = captureTestImage()
File "motiondetect.py", line 39, in captureTestImage
im = Image.open(imageData)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file

I tried an other program to find out of the webcam was working, but it works just fine...
Does anyone know how to fix this?


Thanks in advance!

ps. sorry for my bad English, I'm Dutch
Hi Jorik,

Have you tried just running:
raspistill -w 100 -h 75 -e bmp -n -o test.bmp
and see if it works?

>>I tried an other program to find out of the webcam was working, but it works just fine...
I ask as you say "another program" and "webcam" ...I assume you mean raspistill (or raspivid) along with the Raspberry Pi camera. Just checking :)

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Tue Aug 20, 2013 2:26 pm

I have done all updates/upgrades as needed.
I am using the latest code from github.
I have updated the config.ini file with my username/password/email for photo uploads.
Although I have never had a Picasa account, from what I see, I automatically have one created for me by default of having a Gmail account. Please correct me if I'm wrong.

When I try running the Python script, I get an error as follows:
CRITICAL: Picasa Login failed! Exception: [Errno 97] Address family not supported by protocol

Does anyone have an idea what might be wrong?

In the meantime I am using the picam code, and it saves files locally to the SD card, so for now it is a solution for me.

Jorik
Posts: 4
Joined: Mon Aug 19, 2013 10:09 am

Re: Lightweight python motion detection

Tue Aug 20, 2013 3:41 pm

zeronickname wrote:
Jorik wrote:Hi,

When I run the script on my Rpi, I always get the same error.
I have really no idea how to fix it.
I also tried the script from pageauc but I get the same error.
This is the error:

Traceback (most recent call last):
File "motiondetect.py", line 69, in <module>
image1, buffer1 = captureTestImage()
File "motiondetect.py", line 39, in captureTestImage
im = Image.open(imageData)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file

I tried an other program to find out of the webcam was working, but it works just fine...
Does anyone know how to fix this?


Thanks in advance!

ps. sorry for my bad English, I'm Dutch
Hi Jorik,

Have you tried just running:
raspistill -w 100 -h 75 -e bmp -n -o test.bmp
and see if it works?

>>I tried an other program to find out of the webcam was working, but it works just fine...
I ask as you say "another program" and "webcam" ...I assume you mean raspistill (or raspivid) along with the
Raspberry Pi camera. Just checking :)

thanks for your answer!
I am using a usb webcam and I think, after reading your and brainflakes' articles, that's the cause. can I configure raspistill or picam.py that it works with my webcam?

thanks in advance!
Jorik

zeronickname
Posts: 13
Joined: Sat Jul 20, 2013 4:35 pm

Re: Lightweight python motion detection

Tue Aug 20, 2013 6:20 pm

ShaunVW wrote:I have done all updates/upgrades as needed.
I am using the latest code from github.
I have updated the config.ini file with my username/password/email for photo uploads.
Although I have never had a Picasa account, from what I see, I automatically have one created for me by default of having a Gmail account. Please correct me if I'm wrong.

When I try running the Python script, I get an error as follows:
CRITICAL: Picasa Login failed! Exception: [Errno 97] Address family not supported by protocol

Does anyone have an idea what might be wrong?

In the meantime I am using the picam code, and it saves files locally to the SD card, so for now it is a solution for me.
Hi Shaun,

That exception is thrown when I call ProgrammaticLogin(), but it's obviously some kind of socket error; perhaps to the http POST request made by ProgrammaticLogin().

Related questions (based on some cursory google searches): What version of python are you using? Are you using IPv6? Are you using raspbian? Is it just a temporary issue or does it happen all the time?
Can you try running the gdata picasa test to see if that works?

zeronickname
Posts: 13
Joined: Sat Jul 20, 2013 4:35 pm

Re: Lightweight python motion detection

Tue Aug 20, 2013 6:23 pm

Jorik wrote:
thanks for your answer!
I am using a usb webcam and I think, after reading your and brainflakes' articles, that's the cause. can I configure raspistill or picam.py that it works with my webcam?

thanks in advance!
Jorik
Hi Jorik,

It's probably not worth trying to modify this script to do what you want. If you already have the webcam working on the raspberry pi, perhaps try one of the many other available tools? For example, this one. (I've not used it, just the first link off a google search)

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Wed Aug 21, 2013 5:34 am

zeronickname wrote:
ShaunVW wrote:I have done all updates/upgrades as needed.
I am using the latest code from github.
I have updated the config.ini file with my username/password/email for photo uploads.
Although I have never had a Picasa account, from what I see, I automatically have one created for me by default of having a Gmail account. Please correct me if I'm wrong.

When I try running the Python script, I get an error as follows:
CRITICAL: Picasa Login failed! Exception: [Errno 97] Address family not supported by protocol

Does anyone have an idea what might be wrong?

In the meantime I am using the picam code, and it saves files locally to the SD card, so for now it is a solution for me.
Hi Shaun,

That exception is thrown when I call ProgrammaticLogin(), but it's obviously some kind of socket error; perhaps to the http POST request made by ProgrammaticLogin().

Related questions (based on some cursory google searches): What version of python are you using? Are you using IPv6? Are you using raspbian? Is it just a temporary issue or does it happen all the time?
Can you try running the gdata picasa test to see if that works?
Thank you for the quick response.
The Python version I am using is 2.7.3
The OS is what comes standard on the SD card, Raspbian Wheezy (but fully updated)
Not using IPV6 (as far as I'm aware, I haven't done anything specific to set this up)
I ran the service_test.py, it gives a similar error, on the testInsertPhotoUpdateBlobAndDelete, and the testUploadGetAndDeletePhoto procedures, with the same "Address family not supported by protocol" message.
Further info, I have this set up at work on our domain using a wireless connection to the network, however I have created a file 10proxy with the following line in it : Acquire::http::Proxy "http://anon:[email protected]:8080"; - this is our proxy server address.
This allows me access to the internet.
Also, we run an Endian firewall here at work, and I have given the IP it uses access through the firewall.
I'm not sure if this has got anything to do with it, but if need be, I will bypass the firewall if need be if I can't figure out the issue.

zeronickname
Posts: 13
Joined: Sat Jul 20, 2013 4:35 pm

Re: Lightweight python motion detection

Wed Aug 21, 2013 6:52 am

ShaunVW wrote: Thank you for the quick response.
The Python version I am using is 2.7.3
The OS is what comes standard on the SD card, Raspbian Wheezy (but fully updated)
Not using IPV6 (as far as I'm aware, I haven't done anything specific to set this up)
I ran the service_test.py, it gives a similar error, on the testInsertPhotoUpdateBlobAndDelete, and the testUploadGetAndDeletePhoto procedures, with the same "Address family not supported by protocol" message.
Further info, I have this set up at work on our domain using a wireless connection to the network, however I have created a file 10proxy with the following line in it : Acquire::http::Proxy "http://anon:[email protected]:8080"; - this is our proxy server address.
This allows me access to the internet.
Also, we run an Endian firewall here at work, and I have given the IP it uses access through the firewall.
I'm not sure if this has got anything to do with it, but if need be, I will bypass the firewall if need be if I can't figure out the issue.
I'm not entirely sure what the 10proxy file does (is it just used by apt? Does, for example, ping 8.8.8.8 work for you?)
Can you type in "env" to see if http_proxy is set? if not, you'll need to add

Code: Select all

export http_proxy="http://anon:[email protected]:8080"
to

Code: Select all

/etc/environment

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Wed Aug 21, 2013 8:12 am

zeronickname wrote:
ShaunVW wrote: Thank you for the quick response.
The Python version I am using is 2.7.3
The OS is what comes standard on the SD card, Raspbian Wheezy (but fully updated)
Not using IPV6 (as far as I'm aware, I haven't done anything specific to set this up)
I ran the service_test.py, it gives a similar error, on the testInsertPhotoUpdateBlobAndDelete, and the testUploadGetAndDeletePhoto procedures, with the same "Address family not supported by protocol" message.
Further info, I have this set up at work on our domain using a wireless connection to the network, however I have created a file 10proxy with the following line in it : Acquire::http::Proxy "http://anon:[email protected]:8080"; - this is our proxy server address.
This allows me access to the internet.
Also, we run an Endian firewall here at work, and I have given the IP it uses access through the firewall.
I'm not sure if this has got anything to do with it, but if need be, I will bypass the firewall if need be if I can't figure out the issue.
I'm not entirely sure what the 10proxy file does (is it just used by apt? Does, for example, ping 8.8.8.8 work for you?)
Can you type in "env" to see if http_proxy is set? if not, you'll need to add

Code: Select all

export http_proxy="http://anon:[email protected]:8080"
to

Code: Select all

/etc/environment
I can't ping 8.8.8.8.
Typing in env, it tells me info on the SHELL, TERM, XDG_SESSION_COOCKIE, HUSHLOGIN, USER, LS_COLORS, MAIL, PATH, PWD, LANG, SHLVL, HOE, LOGNAME & OLDPWD.
Nothing mentioned about http_proxy.
Adding "export http://anon:[email protected]:8080 to the etc/environment file, and rebooting, when I now do an env command, it shows the http_proxy=http://anon:[email protected]:8080 entry right after HUSHLOGIN.
Trying to ping 8.8.8.8 still doesn't work though.
Trying my luck and trying to run RasPiCamera.py again still gives me the same error.

Regarding the 10proxy file, yes, I added it to cd /etc/apt/apt.conf.d folder.
Don't ask me to explain it, I have VERY limited Linux knowledge/experience, but when I first got the RPi, this is what I found to do to get internet access here at work.

11MeG
Posts: 1
Joined: Wed Aug 21, 2013 6:52 pm

Re: Lightweight python motion detection

Wed Aug 21, 2013 7:02 pm

Hello,

I tried the script and it work out of the box very nice.

But I was wondering if it was posible to upload the images to a ftp server instead of a ssh server?

I did manage to make a bash script that does the trick for one image like;

Code: Select all

now=$(date +"%d-%m-%Y_%H-%M")
raspistill -h 768 -w 1024 -q 50 -o /home/pi/$now.jpg
sleep 30s

HOST='ftp_hostname'
USER='ftp_username'
PASSWD='ftp_password'
DIR='dir_on_ftphost'
FILE=$now.jpg

#FTPLOG='/home/pi/temp/ftplogfile'
ftp -inv $HOST <<! > $FTPLOG
quote USER $USER
quote PASS $PASSWD
cd $DIR
put $FILE
quit
!
But how can this be made in a python script?

Hope anyone can help.

Greetz,
Jeroen

JiriW
Posts: 2
Joined: Sat Aug 24, 2013 4:51 pm

Re: Lightweight python motion detection

Sat Aug 24, 2013 5:02 pm

Hello, thank you brainflakes, pageauc, peewee2 and Kesthal for nice python script!!! Works fine for me. I have only one problem. After 24-48 hours of running the script, raspberrypi completly freeze. Maybe the internal memory is filled or something. I have still a lot freespace on sdcard so not sure where is the issue.

:idea: Could someone implement some clearing internal memory after a few hours of running or restarting? I have raspberrypi only a week so its all new for me. Thank you!

chrisidc
Posts: 2
Joined: Sun Nov 18, 2012 6:57 pm

Re: Lightweight python motion detection

Mon Aug 26, 2013 5:27 am

@JiriW: I can confirm this freeze after about 24-48 hours. I have the same issue.

zard_cz
Posts: 24
Joined: Tue Aug 14, 2012 3:35 pm

Re: Lightweight python motion detection

Mon Aug 26, 2013 8:45 am

Hi!

First of all, thank you very much for your code in the very first post, that could server as an amazing basis for further development!

I've added google drive upload and it all works like a charm. However, I think I now need to work on a more sophisticated motion detection algorithm - I've got a few trees in the view of the camera and their movement in the wind tends to trigger the capture more often that I would've liked.

I've got some PIR sensors lying around, maybe I would make the capture trigger from that sensor to restrict the the "trigger" range..

Thank you for a great post!

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Lightweight python motion detection

Mon Aug 26, 2013 10:31 am

This is awesome well done all and a massive thanks.
The addition of adding to Picasa is great, the tiniest of bug bears for me though is that it uploads with sharing on.
Although i want to see the pictures those following me on google arent so happy about it spamming their walls.
Is there a way in the upload to set sharing as private?

Once again thanks all love this script.

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Tue Aug 27, 2013 7:40 am

I have successfully set up the script to auto-start at boot, and it updates to Picasa/Gmail account. This is at home, I never did get it to upload from work.
When I run the python script though, it seems to give a flash of a preview image, then returns to the console. It does this about every second.
This is whether I manually start the script, or do it through the auto run at startup.
Is this normal behaviour? Can I switch off the preview part? In the config.ini file, I don't see any reference to this preview, looking at the command line options, this would be set with a -p option.
The issue is that while it is running, it is obviously very distracting if I am working in the console.

Just as an aside, I eventually set my quality to 8 to get decent upload speed. It now gives files about 120kB in size. (I only have a 2Mbps line)
A problem I have though is that it seems to upload pictures that look identical! Is the best option to change sensitivity, or threshold?

And if I may, one more question please! I remember reading on someone's post that Google has a program that automatically combines the images into a video clip? How exactly do I access it from the Gmail account? I don't see it in the options in the menus.
Thank you.

zeronickname
Posts: 13
Joined: Sat Jul 20, 2013 4:35 pm

Re: Lightweight python motion detection

Tue Aug 27, 2013 9:31 am

ShaunVW wrote:Can I switch off the preview part? In the config.ini file, I don't see any reference to this preview, looking at the command line options, this would be set with a -p option.
The issue is that while it is running, it is obviously very distracting if I am working in the console.
You can set any additional camera options directly in the ini file with the cam_options setting. Unfortunately, it appears that I am not using this setting for when the initial preview image is taken. For the time being, perhaps you can directly edit the line for the preview image to add the -p option? Sorry, I didn't spot this as I'm running it in headless mode. Next version will have the fix.
ShaunVW wrote:Just as an aside, I eventually set my quality to 8 to get decent upload speed. It now gives files about 120kB in size. (I only have a 2Mbps line)
A problem I have though is that it seems to upload pictures that look identical! Is the best option to change sensitivity, or threshold?
As I mentioned above, the actual motion detection is done on the preview image, and the jpeg quality settings are only set for the files uploaded to picasa. So this should not affect your false matches. You could try using the selective scan modes to only look for movement in certain parts of the image. Setting scanDebugMode will also generate a bmp file that will tell you what parts of the picture the code things has changed (which should again help you to tweak the threshold & sensitivity)

ShaunVW wrote:And if I may, one more question please! I remember reading on someone's post that Google has a program that automatically combines the images into a video clip? How exactly do I access it from the Gmail account? I don't see it in the options in the menus.
Thank you.
This happens automatically for me because of the Auto Awesome feature. Have you tried going to http://plus.google.com/photos?
zard_cz wrote:I think I now need to work on a more sophisticated motion detection algorithm - I've got a few trees in the view of the camera and their movement in the wind tends to trigger the capture more often that I would've liked.

I've got some PIR sensors lying around, maybe I would make the capture trigger from that sensor to restrict the the "trigger" range.
If the trees are in a certain part of the picture, you can ready tell the script not ignore that part of the picture (thanks to kesthal) -- if that's not good enough and you'd like to trigger from an external source, this should certainly be possible without too much effort. Any patches would be most welcome :)
bighead85 wrote:The addition of adding to Picasa is great, the tiniest of bug bears for me though is that it uploads with sharing on.
Although i want to see the pictures those following me on google arent so happy about it spamming their walls.
Is there a way in the upload to set sharing as private?
That is really odd... The album is explicitly set to be private when created. Are you creating the album manually and then pointing the script to it? Otherwise all photos within it should be automatically private (it inherits the album permissions). Or am I missing something?

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Lightweight python motion detection

Tue Aug 27, 2013 9:54 am

That is really odd... The album is explicitly set to be private when created. Are you creating the album manually and then pointing the script to it? Otherwise all photos within it should be automatically private (it inherits the album permissions). Or am I missing something?
No the script is creating it, although as standard my new albums do share with a set of circles. Maybe this is Google being too clever and thinking I actually want it for all (when in this situation I do not).

Not to worry I will hunt around a bit more in the Google settings must be there somewhere if the script is sending it as private.

Many thanks

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Tue Aug 27, 2013 9:58 am

Thank you for the feedback.
I have seen that AutoAwesome setting, I will change it.
I will also add the no preview into the config file.

I eventually downloaded all my pictures (and then had to rename them by adding .jpg since Google downloads it with a file name only, no extension). I then combined them into a video clip using ImageToAVI, and what I noticed is that the sun is causing the image to change ever so slightly as it moves, this is why the image is showing as changed. However it took watching it as a clip to notice it.

Are there other bug fixes/enhancements that you plan on adding in the future?

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Lightweight python motion detection

Tue Aug 27, 2013 11:52 am

Im sure this is another easy one for someone, but i am clueless.
So script runs, awesome.
I then kill the script (kill <id>)
Then i cannot run the script or raspistill / raspivid again until after restart of pi.

I do not currently wish it to be autostart with the pi, but do want to be able to start/stop on demand as running it behind RASPBMC, so when i want to watch a film i would like to stop the script (if it was running) and when done restart.

What am i missing?
Many thanks in advance

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Wed Aug 28, 2013 5:11 am

With regards to the preview issue, I found that by adding the switch -n for no preview, my captured images were very dark. Initially I thought it was to do with the low light conditions, and so added the switch -ex night, but this had no effect. Then taking off the -n switch again, the picture was nice and bright again.

tvoverbeek
Posts: 98
Joined: Mon Feb 04, 2013 9:50 am
Location: Fieberbrunn, Austria

Re: Lightweight python motion detection

Wed Aug 28, 2013 6:00 am

ShaunVW wrote:With regards to the preview issue, I found that by adding the switch -n for no preview, my captured images were very dark. Initially I thought it was to do with the low light conditions, and so added the switch -ex night, but this had no effect. Then taking off the -n switch again, the picture was nice and bright again.
The "dark images without preview" issue was fixed in a recent update of raspistill. Update your firmware to the latest using rpi-update and see if the dark images have gone when using no preview.

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Lightweight python motion detection

Wed Aug 28, 2013 4:35 pm

bighead85 wrote:Im sure this is another easy one for someone, but i am clueless.
So script runs, awesome.
I then kill the script (kill <id>)
Then i cannot run the script or raspistill / raspivid again until after restart of pi.

I do not currently wish it to be autostart with the pi, but do want to be able to start/stop on demand as running it behind RASPBMC, so when i want to watch a film i would like to stop the script (if it was running) and when done restart.

What am i missing?
Many thanks in advance
Hey All,
I have discovered this only happens with the first scripts the latest with uploader does not cause this problem.
So now that isnt a problem i just need to work out how to save images locally as well and pass in which options to use when i run.
e.g. picam -l (local only) picam -u (upload) this way i cover bases for when in places without internet access also.

Keep up the good work all!

ShaunVW
Posts: 37
Joined: Tue Aug 28, 2012 5:11 pm

Re: Lightweight python motion detection

Thu Aug 29, 2013 5:11 am

tvoverbeek wrote:
ShaunVW wrote:With regards to the preview issue, I found that by adding the switch -n for no preview, my captured images were very dark. Initially I thought it was to do with the low light conditions, and so added the switch -ex night, but this had no effect. Then taking off the -n switch again, the picture was nice and bright again.
The "dark images without preview" issue was fixed in a recent update of raspistill. Update your firmware to the latest using rpi-update and see if the dark images have gone when using no preview.
I did a sudo apt-get update & sudo apt-get upgrade, this issue still exists with the -n switch.
I tried sudo rpi-update, the command wasn't recognised.

Return to “Camera board”