Get passed license plate numbers using ISAPI

Otabek

n3wb
Nov 13, 2024
15
1
Uzbekistan
Hello,

I use Hikvision iDS-2CD7A26G0/P-IZHS IP Camera. I did following to get list of passed license plates but it is not giving expected result. I hoped first item in the list would begin from 2024-11-01. But I get today's list.

1731496935686.png
Please tell me what to do. Thanks in advance.
 
I would highly suggest using Alarm server and parsing real time data and storing to some database.
That sounds like a fantastic idea! I would love to implement it, but I'm not entirely sure where to start. If you wouldn’t mind, could you guide me through the process? I’d really appreciate any help you could offer. Thank you so much in advance!
 
Its fairly simple. Lets start with steps:

1. Create a TCP server listener on your server ip address and desired port. I use 9091 does not need to be 80

Basic Listener without parsing

1731568054783.png

2. Log in to your camera and navigate to Alarm settings
3. Under Server Alarm add ip address of your TCP server listener and port
4. ANR option is optional. This means that if event wasnt handled by server, camera will repeat the same event until server actually said OK. So if you have ANR enabled, on each event you need to send response bytes:
string responseString = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";

5.Once you start receiving events you then parse the data. The data is multipart, meaning it contains XML data depending on vehicle pass and all the information + images. Images are byte array that you can parse and save.
6. Each event you parse, store to database table such as LPRevents.


Thats about it. now you have database of passes which you can pull up anytime you want without interacting and relaying on camera itself.
 
Its fairly simple. Lets start with steps:

1. Create a TCP server listener on your server ip address and desired port. I use 9091 does not need to be 80

Basic Listener without parsing

View attachment 207233

2. Log in to your camera and navigate to Alarm settings
3. Under Server Alarm add ip address of your TCP server listener and port
4. ANR option is optional. This means that if event wasnt handled by server, camera will repeat the same event until server actually said OK. So if you have ANR enabled, on each event you need to send response bytes:
string responseString = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";

5.Once you start receiving events you then parse the data. The data is multipart, meaning it contains XML data depending on vehicle pass and all the information + images. Images are byte array that you can parse and save.
6. Each event you parse, store to database table such as LPRevents.


Thats about it. now you have database of passes which you can pull up anytime you want without interacting and relaying on camera itself.
I configured IP camera and started listening from the specified port. But unfortunately License Plate number is not being received through the socket.
1731576230043.png1731576209111.png
 
Also i noted you have ANR enabled, all the listener apps wont work with it. It will just loop the 1st event it got. Since it does not responds with OK 200 back to camera.

Disable ANR temporary to catch other events.
 
Also i noted you have ANR enabled, all the listener apps wont work with it. It will just loop the 1st event it got. Since it does not responds with OK 200 back to camera.

Disable ANR temporary to catch other events.
ANR has been disabled. Detection mode were 'License Plate & Vehicle':
1731581985984.png
But License Plate No is not being received:
1731582033793.png
 
This is how my listener receives the data:

XML:
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=boundary
Host: 192.168.2.107:9091
Connection: close
Content-Length: 776357

--boundary
Content-Disposition: form-data; name="anpr.xml"; filename="anpr.xml"
Content-Type: text/xml
Content-Length: 3059

<?xml version="1.0" encoding="UTF-8"?>
<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.2.46</ipAddress>
<portNo>9091</portNo>
<protocol>HTTP</protocol>
<macAddress>bc:9b:5e:b3:66:5d</macAddress>
<channelID>1</channelID>
<dateTime>2023-11-02T21:10:32+08:00</dateTime>
<activePostCount>1</activePostCount>
<eventType>ANPR</eventType>
<eventState>active</eventState>
<eventDescription>ANPR</eventDescription>
<channelName>Camera 01</channelName>
<ANPR>
<country>19</country>
<licensePlate>ZG6140G</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>405</index>
<colorDepth>2</colorDepth>
<color>gray</color>
<length>0</length>
<vehicleLo
goRecog>1134</vehicleLogoRecog>
<vehileSubLogoRecog>0</vehileSubLogoRecog>
<vehileModel>0</vehileModel>
</vehicleInfo>
<pictureInfoList>
<pictureInfo>
<fileName>licensePlatePicture.jpg</fileName>
<type>licensePlatePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<pId>2023110221103333400Eqh1QVsXguPWo</pId>
</pictureInfo>
<pictureInfo>
<fileName>vehiclePicture.jpg</fileName>
<type>vehiclePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<plateRect>
<X>448</X>
<Y>406</Y>
<width>117</width>
<height>40</height>
</plateRect>
<pId>2023110221103333400dMbnmyWOBEl9E</pId>
</pictureInfo>
<pictureInfo>
<fileName>detectionPicture.jpg</fileName>
<type>detectionPicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<plateRect>
<X>448</X>
<Y>406</Y>
<width>117</width>
<height>40</height>
</plateRect>
<pId>2023110221103333400F
2DLcGhtwvQgq</pId>
</pictureInfo>
</pictureInfoList>
<originalLicensePlate>ZG6140G</originalLicensePlate>
<CRIndex>19</CRIndex>
<vehicleListName>otherList</vehicleListName>
<plateCategory></plateCategory>
<plateSize>0</plateSize>
</ANPR>
<UUID>2023110221103333200phCHLeHslaDArysAvVOz5HhA01u9tYrAz9UphtSwRP8c</UUID>
<picNum>3</picNum>
<monitoringSiteID></monitoringSiteID>
<isDataRetransmission>false</isDataRetra
nsmission>
<DeviceGPSInfo>
<longitudeType>E</longitudeType>
<latitudeType>N</latitudeType>
<Longitude>
<degree>0</degree>
<minute>0</minute>
<sec>0.000000</sec>
</Longitude>
<Latitude>
<degree>0</degree>
<minute>0</minute>
<sec>0.000000</sec>
</Latitude>
</DeviceGPSInfo>
<detectionBackgroundImageResolution>
<height>1328</height>
<width>1920</width>
</detectionBackgroundImageResolution>
</EventNotificationAlert>

--boundary
Content-Disposition: form-data; name="licensePlatePicture.jpg"; filename="2023110221103333400Eqh1QVsXguPWo.jpg"
Content-Type: image/jpeg
Content-Length: 5008

     JFIF         C

And it keeps going for image bytes,...

I wouldnt rely on done listeners, create your own.
 
This is how my listener receives the data:

XML:
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=boundary
Host: 192.168.2.107:9091
Connection: close
Content-Length: 776357

--boundary
Content-Disposition: form-data; name="anpr.xml"; filename="anpr.xml"
Content-Type: text/xml
Content-Length: 3059

<?xml version="1.0" encoding="UTF-8"?>
<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.2.46</ipAddress>
<portNo>9091</portNo>
<protocol>HTTP</protocol>
<macAddress>bc:9b:5e:b3:66:5d</macAddress>
<channelID>1</channelID>
<dateTime>2023-11-02T21:10:32+08:00</dateTime>
<activePostCount>1</activePostCount>
<eventType>ANPR</eventType>
<eventState>active</eventState>
<eventDescription>ANPR</eventDescription>
<channelName>Camera 01</channelName>
<ANPR>
<country>19</country>
<licensePlate>ZG6140G</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>405</index>
<colorDepth>2</colorDepth>
<color>gray</color>
<length>0</length>
<vehicleLo
goRecog>1134</vehicleLogoRecog>
<vehileSubLogoRecog>0</vehileSubLogoRecog>
<vehileModel>0</vehileModel>
</vehicleInfo>
<pictureInfoList>
<pictureInfo>
<fileName>licensePlatePicture.jpg</fileName>
<type>licensePlatePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<pId>2023110221103333400Eqh1QVsXguPWo</pId>
</pictureInfo>
<pictureInfo>
<fileName>vehiclePicture.jpg</fileName>
<type>vehiclePicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<plateRect>
<X>448</X>
<Y>406</Y>
<width>117</width>
<height>40</height>
</plateRect>
<pId>2023110221103333400dMbnmyWOBEl9E</pId>
</pictureInfo>
<pictureInfo>
<fileName>detectionPicture.jpg</fileName>
<type>detectionPicture</type>
<dataType>0</dataType>
<picRecogMode>0</picRecogMode>
<absTime>20231102211032591</absTime>
<plateRect>
<X>448</X>
<Y>406</Y>
<width>117</width>
<height>40</height>
</plateRect>
<pId>2023110221103333400F
2DLcGhtwvQgq</pId>
</pictureInfo>
</pictureInfoList>
<originalLicensePlate>ZG6140G</originalLicensePlate>
<CRIndex>19</CRIndex>
<vehicleListName>otherList</vehicleListName>
<plateCategory></plateCategory>
<plateSize>0</plateSize>
</ANPR>
<UUID>2023110221103333200phCHLeHslaDArysAvVOz5HhA01u9tYrAz9UphtSwRP8c</UUID>
<picNum>3</picNum>
<monitoringSiteID></monitoringSiteID>
<isDataRetransmission>false</isDataRetra
nsmission>
<DeviceGPSInfo>
<longitudeType>E</longitudeType>
<latitudeType>N</latitudeType>
<Longitude>
<degree>0</degree>
<minute>0</minute>
<sec>0.000000</sec>
</Longitude>
<Latitude>
<degree>0</degree>
<minute>0</minute>
<sec>0.000000</sec>
</Latitude>
</DeviceGPSInfo>
<detectionBackgroundImageResolution>
<height>1328</height>
<width>1920</width>
</detectionBackgroundImageResolution>
</EventNotificationAlert>

--boundary
Content-Disposition: form-data; name="licensePlatePicture.jpg"; filename="2023110221103333400Eqh1QVsXguPWo.jpg"
Content-Type: image/jpeg
Content-Length: 5008

     JFIF         C

And it keeps going for image bytes,...

I wouldnt rely on done listeners, create your own.

I also created socket server using Python:

import socket

IP_ADDRESS = '10.142.47.118'
PORT = 21

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_socket.bind((IP_ADDRESS, PORT))
print(f"Server is listening on {IP_ADDRESS}:{PORT}")

server_socket.listen(1)

while True:
client_socket, client_address = server_socket.accept()
print(f"Connected by {client_address}")

data = client_socket.recv(776357)
if data:
print("Received:", data.decode())

client_socket.close()

Here is the receiving data. But no any license plate number:
Connected by ('172.16.66.230', 59186)
Received: POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=boundary
Host: 10.142.47.118:21
Connection: close
Content-Length: 1125

--boundary
Content-Disposition: form-data; name="TrafficFlow"
Content-Type: application/json
Content-Length: 990

{
"ipAddress": "172.16.66.230",
"portNo": 21,
"protocol": "HTTP",
"macAddress": "5c:34:5b:9e:c8:cc",
"channelID": 1,
"dateTime": "2024-11-15T08:46:54+05:00",
"activePostCount": 1,
"eventState": "active",
"channelName": "Kirish",
"eventType": "TPSRealTime",
"eventDescription": "traffic pass statistics real-time",
"Target": [{
"recognitionType": "vehicle",
"TargetInfo": {
"snapTime": "2024-11-15T08:46:54+05:00",
"totalLaneNum": 1,
"LaneInfo": [{
"laneNo": 1,
"volum": 100,
"downwardFlow": 99,
"upwardFlow": 1
}],
"speed": "unknown",
"vehicleType": "unknown",
"plateNo": "unknown"
}
}, {
"recognitionType": "motorcycle",
"TargetInfo": {
"snapTime": "2024-11-15T08:46:54+05:00",
"totalLaneNum": 1,
"LaneInfo": [{
"laneNo": 1,
"volum": 0,
"downwardFlow": 0,
"upwardFlow": 0
}],
"speed": "unknown",
"vehicleType": "unknown",
"plateNo": "unknown"
}
}]
}
--boundary--
 
What you are getting is not ANPR event, you are getting TPSRealTime event which is vehicle counter not ANPR.
Factory restore and try again if you upgraded firmware.
 
  • Like
Reactions: Otabek
What you are getting is not ANPR event, you are getting TPSRealTime event which is vehicle counter not ANPR.
Factory restore and try again if you upgraded firmware.
PUT /ISAPI/Event/notification/httpHosts/1

Authorization
Digest Auth
username: admin
password: password

Headers
Content-Type: application/xml

Body
raw, XML:
<HttpHostNotification version="2.0" xmlns="">
<id>1</id>
<url></url>
<protocolType>HTTP</protocolType>
<parameterFormatType>XML</parameterFormatType>
<addressingFormatType>ipaddress</addressingFormatType>
<ipAddress>10.142.47.118</ipAddress>
<portNo>22</portNo>
<userName></userName>
<httpAuthenticationMethod>none</httpAuthenticationMethod>
<httpBroken>true</httpBroken>
<ANPR>
<detectionUploadPicturesType opt="all, licensePlatePicture, detectionPicture">all</detectionUploadPicturesType>
</ANPR>
</HttpHostNotification>

1731733666664.png


1731900542650.png


Thank you very much for your invaluable assistance Trempa92. Utilizing the provided API with Postman and changing settings has enabled me to successfully initiate ANPR notifications through a TCP Socket Server.

However, I have noticed that notifications are not triggered when the operator opens the barrier using the remote control. Could you kindly advise me on how to resolve this issue?

I greatly appreciate your guidance and support.
 
Last edited:
Thats for recieving events, upload to memorycard or FTP is not necesary.

Already got everything set for my integration to work as it should.


1732198438337.png
1732198170151.png

1732198201980.png

1732198312481.png1732198333635.png1732198392192.png