Linux script for motion detect and snapshot?

beos

n3wb
Joined
Jan 14, 2017
Messages
17
Reaction score
4
Location
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
 

tangent

IPCT Contributor
Joined
May 12, 2016
Messages
4,342
Reaction score
3,524
It probably makes more sense to use the motion detection features built into the camera and have the camera email or ftp the snapshot when it detects motion. You can run an FTP or mail server on your PC.
 

hmjgriffon

Known around here
Joined
Mar 30, 2014
Messages
3,401
Reaction score
980
Location
North Florida
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.
 

tangent

IPCT Contributor
Joined
May 12, 2016
Messages
4,342
Reaction score
3,524
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.
 

beos

n3wb
Joined
Jan 14, 2017
Messages
17
Reaction score
4
Location
Sweden
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.
 

hmjgriffon

Known around here
Joined
Mar 30, 2014
Messages
3,401
Reaction score
980
Location
North Florida
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.
 

tangent

IPCT Contributor
Joined
May 12, 2016
Messages
4,342
Reaction score
3,524
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:

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,930
Reaction score
6,778
Location
Scotland
Though as always with these things, not all the calls are supported on all the devices.
But it provides some pretty good ideas.
 

beos

n3wb
Joined
Jan 14, 2017
Messages
17
Reaction score
4
Location
Sweden
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.
 

curve51

n3wb
Joined
May 4, 2018
Messages
2
Reaction score
0
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
 

beos

n3wb
Joined
Jan 14, 2017
Messages
17
Reaction score
4
Location
Sweden
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
 

faxe2110

n3wb
Joined
Feb 11, 2019
Messages
5
Reaction score
0
Location
Sodra Skoga
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
 
Top