Linux script for motion detect and snapshot?

beos

n3wb
Jan 14, 2017
17
4
Sweden
Hi, new to this forum. Before I dig in to this myself I would like to ask if anybody has done this before:

Would like to have a simple script for doing the following

1. By polling the camera (or by camera triggered action?) detect motion
2. Upon detection of motion, request a snapshot from the camera

Have seen that the API/CGI command for step 2, for Hikvision, is
http://<username>:<password>@<ip address>/Streaming/channels/1/picture

is this correct? A corresponding command to get the motion detect status?
Have done a similar script in Python for a Foscam device, but prefer to wait and see if somebody already has done this for Hikvision, than inventing the wheel again...

Regards
 
Hi, new to this forum. Before I dig in to this myself I would like to ask if anybody has done this before:

Would like to have a simple script for doing the following

1. By polling the camera (or by camera triggered action?) detect motion
2. Upon detection of motion, request a snapshot from the camera

Have seen that the API/CGI command for step 2, for Hikvision, is
http://<username>:<password>@<ip address>/Streaming/channels/1/picture

is this correct? A corresponding command to get the motion detect status?
Have done a similar script in Python for a Foscam device, but prefer to wait and see if somebody already has done this for Hikvision, than inventing the wheel again...

Regards
Also you'll get spammed, the software motion detection sucks, it's much better in bi but still not as good as a real motion sensor. Use external PIR and contact switches and stuff to trigger cameras. I've got a hik cube in the house and the PIR hasn't false alarmed once, I will say when I used bi motion sensing with it, it only alarmed when the camera switched day and night modes.
 
  • Like
Reactions: beos
Passive infrared sensor - Wikipedia
BI would be a reference to Blue Iris.

The quality of the motion detection on camera varies a lot. Some cameras have smarter features like line crossing or the ability to detect an "intrusion" in to a specific region you specify. Blue iris is a piece of software you can use to record cameras on a computer it can also do video based motion detection with higher accuracy than the standard motion detection you find on many cameras.
 
  • Like
Reactions: beos
Thanks, but I still wan't to do the script. Represents a small effort that is easy to tweak to my likings. Yes I get quite a lot of false detections but is OK for my use.
 
Thanks, but I still wan't to do the script. Represents a small effort that is easy to tweak to my likings. Yes I get quite a lot of false detections but is OK for my use.

in what use is it okay to get tons of false alerts? lol the small amount of effort to implement real motion detection is well worth it.
 
Hikvision doesn't have a documented API. The cameras can already do what you're asking email or ftp the picture, your approach is a little odd.

If you want to do other actions script that... run a local mail server or watch for files being added to a folder.
 
Last edited:
  • Like
Reactions: hmjgriffon
OK, thanks all, I'm up and running now. The two API commands needed where

http://<username>:<password>@<ip address>/IO/outputs/1/status and
http://<username>:<password>@<ip address>/Streaming/channels/1/picture

You configure (from the web interface) motion detection (in my case I used the "intrusion detection" only, seems to give less false positives) to trigger (linkage) the "Trigger Alarm Output", A -> 1 (don't forget to set up the arming schedule for both the intrusion detection and the alarm output, I forgot that and could not for the world understand why I couldn't trigger the alarm output...)

Then you just monitor the /IO/outputs/1/status for changing from "inactive" to "active" and upon change to "active", take on or more snapshots with the second API command.
 
OK, thanks all, I'm up and running now. The two API commands needed where

http://<username>:<password>@<ip address>/IO/outputs/1/status and
http://<username>:<password>@<ip address>/Streaming/channels/1/picture

You configure (from the web interface) motion detection (in my case I used the "intrusion detection" only, seems to give less false positives) to trigger (linkage) the "Trigger Alarm Output", A -> 1 (don't forget to set up the arming schedule for both the intrusion detection and the alarm output, I forgot that and could not for the world understand why I couldn't trigger the alarm output...)

Then you just monitor the /IO/outputs/1/status for changing from "inactive" to "active" and upon change to "active", take on or more snapshots with the second API command.


Hi, how do you store ( http://<username>:<password>@<ip address>/Streaming/channels/1/picture ) that picture? , THX
 
Something like
curl -o `date +%Y-%m-%dT%H-%M-%S`snap.jpg http://<username>:<password>@<ip address>/Streaming/channels/1/picture
Saves a snapshot as a jpg image with current date and time as filename
 
  • Like
Reactions: curve51
OK, thanks all, I'm up and running now. The two API commands needed where

http://<username>:<password>@<ip address>/IO/outputs/1/status and
http://<username>:<password>@<ip address>/Streaming/channels/1/picture

You configure (from the web interface) motion detection (in my case I used the "intrusion detection" only, seems to give less false positives) to trigger (linkage) the "Trigger Alarm Output", A -> 1 (don't forget to set up the arming schedule for both the intrusion detection and the alarm output, I forgot that and could not for the world understand why I couldn't trigger the alarm output...)

Then you just monitor the /IO/outputs/1/status for changing from "inactive" to "active" and upon change to "active", take on or more snapshots with the second API command.

Hallo,

i´m trying to figure out how you are getting the "inactive" to "active" ??
I´m running an DS-2CD2120F-I but if i use different of the commands, i´m always getting

<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<requestURL>/ISAPI/System/IO/outputs/1/status</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
<subStatusCode>invalidOperation</subStatusCode>
</ResponseStatus>

Was thinking about the same as @beos if MotionDetection get a signal, i want to save/send a pic. to a device.

In MotionDetection A1 is enabled.
What am i doing wrong??

Best