Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

**Feature Request** Smart Motion Detection #164

Closed
DeadEnded opened this issue Oct 1, 2020 · 5 comments
Closed

**Feature Request** Smart Motion Detection #164

DeadEnded opened this issue Oct 1, 2020 · 5 comments

Comments

@DeadEnded
Copy link
Contributor

DeadEnded commented Oct 1, 2020

I recently upgraded a camera to the IPC-HDW5442TM-AS.
This has some new events and I was hoping to use the Smart Motion Detection (can detect humans and vehicles).
Playing with the API calls I found that the getConfig name is SmartMotionDetect

The following command:

http://<IP>/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect

Returns:

table.SmartMotionDetect[0].Enable=true
table.SmartMotionDetect[0].ObjectTypes.Human=true
table.SmartMotionDetect[0].ObjectTypes.Vehicle=false
table.SmartMotionDetect[0].Sensitivity=Middle

This shows that the smart detection is enabled, and for humans but not vehicles - and the sensitivity is set to medium (3 options, low/medium/high).

Using this I expect that the event subscription would be either SmartMotionDetect or SmartVideoMotion based on what is already in this repo. I am a novice, and wasn't sure how to test this. I tried, but was unsuccessful getting a correct response with the existing motion detection (I'm sure I'm doing something wrong though).

When I tried to test some of the commands in the interpreter I expect I am doing it wrong. I am getting generator objects so I expect it is doing something but I am sending the wrong commands or not telling it how to output... as said earlier, I'm a novice 😄 .

>>> import amcrest
>>> camera = amcrest.AmcrestCamera('<IP>',80,'<admin>','<password>').camera
>>> camera.software_information
('version=2.800.0000000.20.R', 'build:2020-09-03\r\n')
>>> camera.event_stream('All')
<generator object Event.event_stream at 0x7f307bfe0900>
>>> camera.event_stream('VideoMotion')
<generator object Event.event_stream at 0x7f307bfe0820>
>>> camera.event_actions('All')
<generator object Event.event_actions at 0x7f307bfe0900>

If this is as simple as adding a new event name, fantastic - but if it needs testing, I would be happy to do it, but might need a little hand holding to start. If I could be told how to test the VideoMotion and get a response correctly, I'm sure I could work from there to get the SmartVideoMotion or SmartMotionDetect whatever they call it figured out.

Thanks!
DeadEnd

@blademckain
Copy link
Collaborator

i think u are using the wrong function
try this

from amcrest import AmcrestCamera, AmcrestError
import logging
logging.basicConfig(level=logging.DEBUG)

_LOGGER = logging.getLogger(__name__)
camera = AmcrestCamera('192.168.x.x', 80, '', '').camera

#Check software information
print (camera.software_information)

while True:
		try:
            for code, payload in camera.event_actions('All', retries=5):
                _LOGGER.debug("Captured event: %s -- %s", code, payload)
                print ("Captured event: %s -- %s", code, payload)
        except AmcrestError as error:
            _LOGGER.warning(
                "Error while processing events from %s camera: %r", name, error
            )

@DeadEnded
Copy link
Contributor Author

DeadEnded commented Oct 2, 2020

moderate success!

DEBUG:amcrest.http:<FrontPorchCam:serial#####> HTTP query 8: http://<IP>:80/cgi-bin/eventManager.cgi?action=attach&codes=[All]
DEBUG:amcrest.http:<FrontPorchCam:serial#####> Running query 8 attempt 1
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): <IP>:80
DEBUG:urllib3.connectionpool:http://<IP>:80 "GET /cgi-bin/eventManager.cgi?action=attach&codes=%5BAll%5D HTTP/1.1" 401 0
DEBUG:urllib3.connectionpool:Resetting dropped connection: 10.20.30.201
DEBUG:urllib3.connectionpool:http://<IP>:80 "GET /cgi-bin/eventManager.cgi?action=attach&codes=%5BAll%5D HTTP/1.1" 200 None
DEBUG:amcrest.http:<FrontPorchCam:serial#####> Query 8 worked. Exit code: <200>
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "Id" : [ 0 ],\n   "RegionName" : [ "Region1" ],\n   "SmartMotionEnable" : true\n'
DEBUG:__main__:Captured event: VideoMotion -- True
Captured event: %s -- %s VideoMotion True
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "Id" : [ 0 ],\n   "RegionName" : [ "Region1" ],\n   "SmartMotionEnable" : true\n'
DEBUG:__main__:Captured event: VideoMotion -- False
Captured event: %s -- %s VideoMotion False
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "Id" : [ 0 ],\n   "RegionName" : [ "Region1" ],\n   "SmartMotionEnable" : true\n'
DEBUG:__main__:Captured event: VideoMotion -- True
Captured event: %s -- %s VideoMotion True
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:> event info: '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "Id" : [ 0 ],\n   "RegionName" : [ "Region1" ],\n   "SmartMotionEnable" : true\n'
DEBUG:__main__:Captured event: VideoMotion -- False
Captured event: %s -- %s VideoMotion False
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=SmartMotionHuman;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ],\n   "WindowId" : [ 0 ],\n   "object" : [\n      {\n         "HumamID" : 6962,\n         "Rect" : [ 5112, 2800, 5752, 5560 ]\n      }\n   ]\n'
DEBUG:__main__:Captured event: SmartMotionHuman -- True
Captured event: %s -- %s SmartMotionHuman True
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=SmartMotionHuman;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ],\n   "WindowId" : [ 0 ],\n   "object" : [\n      {\n         "HumamID" : 6962,\n         "Rect" : [ 1528, 3128, 1984, 4920 ]\n      },\n      {\n         "HumamID" : 6965,\n         "Rect" : [ 1824, 3384, 2296, 5040 ]\n      }\n   ]\n'
DEBUG:__main__:Captured event: SmartMotionHuman -- False
Captured event: %s -- %s SmartMotionHuman False

Here at the end I see the capture event for the SmartMotionHuman - yay!
I assume then there is also a SmartMotionVehicle as well, as long as I'm digging into this, might as well do both...
.... okay, enabled vehicle, and confirmed it:

DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=SmartMotionVehicle;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ],\n   "WindowId" : [ 0 ],\n   "object" : [\n      {\n         "Rect" : [ 1712, 0, 3160, 816 ],\n         "VehicleID" : 7212\n      }\n   ]\n'
DEBUG:__main__:Captured event: SmartMotionVehicle -- True
Captured event: %s -- %s SmartMotionVehicle True
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=VideoMotionInfo;action=State;index'
DEBUG:amcrest.event:<FrontPorchCam:serial#####> event info: '\r\nCode=SmartMotionVehicle;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ],\n   "WindowId" : [ 0 ],\n   "object" : [\n      {\n         "Rect" : [ 1712, 0, 3160, 816 ],\n         "VehicleID" : 7212\n      }\n   ]\n'
DEBUG:__main__:Captured event: SmartMotionVehicle -- False
Captured event: %s -- %s SmartMotionVehicle False

So, what is the next step...
Is it as simple as adding these to a list of events to listen for, or more complicated than that?

Thanks for the help!
DeadEnd

@DeadEnded
Copy link
Contributor Author

Looking at the code (but again, novice here...) and looking at tthe event.py specifically the existing VideoMotion for reference....

We would add to the comment for event_channels_happened and event_stream for these two new events.
Then, add another property for each, something like this (making an assumption on vehicle since I haven't tested it)?

    @property
    def is_human_detected(self):
        event = self.event_channels_happened('SmartMotionHuman')
        if 'channels' not in event:
            return False
        return True

    @property
    def is_vehicle_detected(self):
        event = self.event_channels_happened('SmartMotionVehicle')
        if 'channels' not in event:
            return False
        return True

Still looking to see what other code would need updated.
But that's at least a start... If it doesn't get much more complicated, I'd be happy to try and do the pull request - always like to try and contribute!

DeadEnd

@DeadEnded
Copy link
Contributor Author

Using the event_channels_happened I first confirmed I could do it correctly:

bash-5.0# amcrest-cli --camera fpcam --event-channels-happened VideoMotion
channels[0]=0

And then ran for SmartMotionHuman to see if it had the same design/schema/whatever you want to call it:
(this took some time to wait for someone to walk by!)

bash-5.0# amcrest-cli --camera fpcam --event-channels-happened SmartMotionHuman
channels[0]=0

I believe that we can add them with the same design as the VideoMotion.
So - my question to someone who knows the code - is there anything more that needs to be done?
I would like to do the change but am not sure if anything else is needed...
Should I just create a pull request and see how far it gets 😄?

I would like to eventually even possibly get this into HA as a sensor - but I'll start with this step first...

Cheers!
DeadEnd

@DeadEnded
Copy link
Contributor Author

Merged - closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants