maciej-or / hikvision_next

Home Assistant integration for Hikvision NVRs and IP cameras
102 stars 19 forks source link

Feature request: ANPR data and images. #117

Open turbokongen opened 11 months ago

turbokongen commented 11 months ago

It would be really nice to implement ANPR fuctionality to this module. ANPR gives an really detailed output of recognized vehicles. What I imagine this would be set up: Sensor for last recognized plate, with vehicle data, licensplate data and vehiclelist attributes. "Cameras" for pictures retrieved for vehicle and plate. Below are logs from debug: With recognized plate:

2023-08-11 14:49:01.047 DEBUG (MainThread) [custom_components.hikvision_next.notifications] Alert: AlertInfo(channel_id=1, io_port_id=0, event_id='motiondetection', device_serial_no=None, mac='bc:5e:33:62:2a:5c')
2023-08-11 14:49:01.047 DEBUG (MainThread) [custom_components.hikvision_next.notifications] UNIQUE_ID: binary_sensor.ids_2cd7a46g0_p_izhsy20230110aawrl12612790_1_motiondetection
2023-08-11 14:49:01.787 DEBUG (MainThread) [custom_components.hikvision_next.notifications] --- Incoming event notification ---
2023-08-11 14:49:01.788 DEBUG (MainThread) [custom_components.hikvision_next.notifications] Source: 10.2.124.188
2023-08-11 14:49:01.799 DEBUG (MainThread) [custom_components.hikvision_next.notifications] request headers: <CIMultiDictProxy('Content-Type': 'multipart/form-data; boundary=boundary', 'Host': '10.2.124.77:8123', 'Connection': 'close', 'Content-Length': '197650')>
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] part headers: {'Content-Disposition': 'form-data; name="anpr.xml"; filename="anpr.xml"', 'Content-Type': 'text/xml', 'Content-Length': '2603'}
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] part headers: {'Content-Disposition': 'form-data; name="licensePlatePicture.jpg"; filename="2023081113490182400fSXqc8CQHtdNG.jpg"', 'Content-Type': 'image/jpeg', 'Content-Length': '5251'}
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] image found
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] part headers: {'Content-Disposition': 'form-data; name="vehiclePicture.jpg"; filename="2023081113490182400EgqBZCXSSOD9V.jpg"', 'Content-Type': 'image/jpeg', 'Content-Length': '189299'}
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] image found
2023-08-11 14:49:01.801 DEBUG (MainThread) [custom_components.hikvision_next.notifications] alert info: <?xml version="1.0" encoding="UTF-8"?>
<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>10.2.124.188</ipAddress>
<portNo>8123</portNo>
<protocol>HTTP</protocol>
<macAddress>bc:5e:33:62:2a:5c</macAddress>
<channelID>1</channelID>
<dateTime>2023-08-11T13:49:00+01:00</dateTime>
<activePostCount>1</activePostCount>
<eventType>ANPR</eventType>
<eventState>active</eventState>
<eventDescription>ANPR</eventDescription>
<channelName>Camera 01</channelName>
<ANPR>
<country>5</country>
<licensePlate>KH35192</licensePlate>
<line>1</line>
<direction>forward</direction>
<confidenceLevel>100</confidenceLevel>
<plateType>unknown</plateType>
<plateColor>unknown</plateColor>
<licenseBright>0</licenseBright>
<dangmark>no</dangmark>
<twoWheelVehicle>no</twoWheelVehicle>
<threeWheelVehicle>no</threeWheelVehicle>
<plateCharBelieve>99,99,99,99,99,99,99</plateCharBelieve>
<vehicleType>vehicle</vehicleType>
<detectDir>8</detectDir>
<detectType>0</detectType>
<alarmDataType>0</alarmDataType>
<vehicleInfo>
<index>39</index>
<colorDepth>2</colorDepth>
<color>white</color>
<length>0</length>
<vehicleLogoRecog>1060</vehicleLogoRecog>
<vehileSubLogoRecog>0</vehileSubLogoRecog>
<vehileModel>0</vehileModel>
</vehicleInfo>
<pictureInfoList>
<pictureInfo>
<fileName>licensePlatePicture.jpg</fileName>
<type>licensePlatePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20230811134900555</absTime>
<pId>2023081113490182400fSXqc8CQHtdNG</pId>
</pictureInfo>
<pictureInfo>
<fileName>vehiclePicture.jpg</fileName>
<type>vehiclePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20230811134900555</absTime>
<plateRect>
<X>544</X>
<Y>835</Y>
<width>40</width>
<height>35</height>
</plateRect>
<pId>2023081113490182400EgqBZCXSSOD9V</pId>
</pictureInfo>
</pictureInfoList>
<originalLicensePlate>KH35192</originalLicensePlate>
<CRIndex>5</CRIndex>
<vehicleListName>otherList</vehicleListName>
<plateCategory></plateCategory>
<plateSize>0</plateSize>
</ANPR>
<UUID>20230811134901822007gWpiNIuI14ikdwfKR5eDCzuV45RubEmi88qaD5w0YTq</UUID>
<picNum>2</picNum>
<monitoringSiteID>1</monitoringSiteID>
<isDataRetransmission>false</isDataRetransmission>
<DeviceGPSInfo>
<longitudeType>E</longitudeType>
<latitudeType>N</latitudeType>
<Longitude>
<degree>7</degree>
<minute>56</minute>
<sec>9.000000</sec>
</Longitude>
<Latitude>
<degree>58</degree>
<minute>6</minute>
<sec>22.300000</sec>
</Latitude>
</DeviceGPSInfo>
</EventNotificationAlert>

Without recognized plate:

2023-08-11 15:02:30.048 DEBUG (MainThread) [custom_components.hikvision_next.notifications] Alert: AlertInfo(channel_id=1, io_port_id=0, event_id='motiondetection', device_serial_no=None, mac='bc:5e:33:62:2a:5c')
2023-08-11 15:02:30.048 DEBUG (MainThread) [custom_components.hikvision_next.notifications] UNIQUE_ID: binary_sensor.ids_2cd7a46g0_p_izhsy20230110aawrl12612790_1_motiondetection
2023-08-11 15:02:36.118 DEBUG (MainThread) [custom_components.hikvision_next.notifications] --- Incoming event notification ---
2023-08-11 15:02:36.118 DEBUG (MainThread) [custom_components.hikvision_next.notifications] Source: 10.2.124.188
2023-08-11 15:02:36.175 DEBUG (MainThread) [custom_components.hikvision_next.notifications] request headers: <CIMultiDictProxy('Content-Type': 'multipart/form-data; boundary=boundary', 'Host': '10.2.124.77:8123', 'Connection': 'close', 'Content-Length': '832166')>
2023-08-11 15:02:36.180 DEBUG (MainThread) [custom_components.hikvision_next.notifications] part headers: {'Content-Disposition': 'form-data; name="anpr.xml"; filename="anpr.xml"', 'Content-Type': 'text/xml', 'Content-Length': '2329'}
2023-08-11 15:02:36.182 DEBUG (MainThread) [custom_components.hikvision_next.notifications] part headers: {'Content-Disposition': 'form-data; name="vehiclePicture.jpg"; filename="2023081114023616000te10ogXYgHMUv.jpg"', 'Content-Type': 'image/jpeg', 'Content-Length': '829517'}
2023-08-11 15:02:36.182 DEBUG (MainThread) [custom_components.hikvision_next.notifications] image found
2023-08-11 15:02:36.182 DEBUG (MainThread) [custom_components.hikvision_next.notifications] alert info: <?xml version="1.0" encoding="UTF-8"?>
<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>10.2.124.188</ipAddress>
<portNo>8123</portNo>
<protocol>HTTP</protocol>
<macAddress>bc:5e:33:62:2a:5c</macAddress>
<channelID>1</channelID>
<dateTime>2023-08-11T14:02:35+01:00</dateTime>
<activePostCount>1</activePostCount>
<eventType>ANPR</eventType>
<eventState>active</eventState>
<eventDescription>ANPR</eventDescription>
<channelName>Camera 01</channelName>
<ANPR>
<country>0</country>
<licensePlate>unknown</licensePlate>
<line>1</line>
<direction>forward</direction>
<confidenceLevel>0</confidenceLevel>
<plateType>unknown</plateType>
<plateColor>unknown</plateColor>
<licenseBright>0</licenseBright>
<dangmark>unknown</dangmark>
<twoWheelVehicle>no</twoWheelVehicle>
<threeWheelVehicle>no</threeWheelVehicle>
<plateCharBelieve></plateCharBelieve>
<vehicleType>SUVMPV</vehicleType>
<detectDir>8</detectDir>
<detectType>0</detectType>
<alarmDataType>0</alarmDataType>
<vehicleInfo>
<index>93</index>
<colorDepth>2</colorDepth>
<color>white</color>
<length>0</length>
<vehicleLogoRecog>1036</vehicleLogoRecog>
<vehileSubLogoRecog>0</vehileSubLogoRecog>
<vehileModel>0</vehileModel>
</vehicleInfo>
<pictureInfoList>
<pictureInfo>
<fileName>vehiclePicture.jpg</fileName>
<type>vehiclePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20230811140235286</absTime>
<plateRect>
<X>0</X>
<Y>0</Y>
<width>0</width>
<height>0</height>
</plateRect>
<pId>2023081114023616000te10ogXYgHMUv</pId>
</pictureInfo>
</pictureInfoList>
<originalLicensePlate>unknown</originalLicensePlate>
<CRIndex>0</CRIndex>
<vehicleListName>otherList</vehicleListName>
<plateCategory></plateCategory>
<plateSize>0</plateSize>
</ANPR>
<UUID>2023081114023615800vefGxfobg2fpWcnGtTmw4kkii7gsXTdT58WIAeZZkGfh</UUID>
<picNum>1</picNum>
<monitoringSiteID>1</monitoringSiteID>
<isDataRetransmission>false</isDataRetransmission>
<DeviceGPSInfo>
<longitudeType>E</longitudeType>
<latitudeType>N</latitudeType>
<Longitude>
<degree>7</degree>
<minute>56</minute>
<sec>9.000000</sec>
</Longitude>
<Latitude>
<degree>58</degree>
<minute>6</minute>
<sec>22.300000</sec>
</Latitude>
</DeviceGPSInfo>
</EventNotificationAlert>

Relevant output from logs:

2023-08-11 14:38:00.788 DEBUG (MainThread) [custom_components.hikvision_next.isapi] http://10.2.124.188/ISAPI/Event/notification/httpHosts {'HttpHostNotificationList': {'@version': '2.0', '@xmlns': 'http://www.hikvision.com/ver20/XMLSchema', 'HttpHostNotification': [{'@version': '2.0', '@xmlns': 'http://www.hikvision.com/ver20/XMLSchema', 'id': '1', 'url': '/api/hikvision', 'protocolType': 'HTTP', 'parameterFormatType': 'XML', 'addressingFormatType': 'ipaddress', 'ipAddress': '10.2.124.77', 'portNo': '8123', 'userName': None, 'httpAuthenticationMethod': 'none', 'httpBroken': 'true', 'ANPR': {'detectionUpLoadPicturesType': {'@opt': 'all,licensePlatePicture,detectionPicture', '#text': 'all'}}}, {'@version': '2.0', '@xmlns': 'http://www.hikvision.com/ver20/XMLSchema', 'id': '2', 'url': '/', 'protocolType': 'HTTP', 'parameterFormatType': 'XML', 'addressingFormatType': 'ipaddress', 'ipAddress': '0.0.0.0', 'portNo': '80', 'userName': None, 'httpAuthenticationMethod': 'none', 'httpBroken': 'true', 'ANPR': {'detectionUpLoadPicturesType': {'@opt': 'all,licensePlatePicture,detectionPicture', '#text': 'all'}}}, {'@version': '2.0', '@xmlns': 'http://www.hikvision.com/ver20/XMLSchema', 'id': '3', 'url': '/', 'protocolType': 'HTTP', 'parameterFormatType': 'XML', 'addressingFormatType': 'ipaddress', 'ipAddress': '0.0.0.0', 'portNo': '80', 'userName': None, 'httpAuthenticationMethod': 'none', 'httpBroken': 'true', 'ANPR': {'detectionUpLoadPicturesType': {'@opt': 'all,licensePlatePicture,detectionPicture', '#text': 'all'}}}]}}
maciej-or commented 11 months ago

I would be a cool feature. It's possible and log certainly will help.