Object coordinates in Object analytics API #755
-
Is there any support for retrieving an object's coordinates when a detection event occurs for an object analytics scenario? I would like to see the x,y coordinates whenever an active trigger occurs in the Object in Area scenario. Right now it seems only the classType and object ID is being returned from my websocket connection to Axis events. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
Yes, Metadata will return all the data in the view, it does not contain any AOA area or line info. |
Beta Was this translation helpful? Give feedback.
-
Hi @embeddeddev4 , Get the Polygon and scenario details using VAPIX and draw using OpenCV:Device and AOA used:AXIS Q1715 Block Camera import requests
from requests.auth import HTTPDigestAuth
import cv2
import numpy as np
# Replace with your actual device IP or hostname
device = "10.176.12.148"
user = "Vivek"
password = "Kumar"
# URL to request the configuration
url = f"http://{device}/local/objectanalytics/control.cgi"
# Body of the POST request
body = {
"apiVersion": "1.2",
"context": "my context",
"method": "getConfiguration"
}
# Make the POST request using Digest Authentication
response = requests.post(url, json=body, auth=HTTPDigestAuth(user, password))
try:
# Check if the request was successful
response.raise_for_status()
# Check if the response is empty or not
if not response.text.strip():
print("Empty response received from the server.")
exit(1)
# Print the response text to see what is being returned
print("Response Text:", response.text)
# Parse the response JSON
config = response.json()
# Extract relevant information from the JSON
scenario = config["data"]["scenarios"][0]
scenario_name = scenario["name"]
include_area = scenario["triggers"][0]["vertices"]
# RTSP URL (Use your actual RTSP URL here)
rtsp_url = f"rtsp://{user}:{password}@{device}:554/axis-media/media.amp"
# Open the RTSP stream
cap = cv2.VideoCapture(rtsp_url)
# Scaling function to map from normalized (-1.0 to 1.0) to image coordinates
def scale_coordinates(coords, frame_width, frame_height):
return [
(
int((x + 1.0) / 2.0 * frame_width),
int((y + 1.0) / 2.0 * frame_height)
)
for x, y in coords
]
# Process each frame
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
frame_height, frame_width = frame.shape[:2]
# Draw include area
include_pts = scale_coordinates(include_area, frame_width, frame_height)
cv2.polylines(frame, [np.array(include_pts)], isClosed=True, color=(0, 255, 0), thickness=2)
# Overlay the scenario name on the video
cv2.putText(frame, scenario_name, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
# Show the frame
cv2.imshow('RTSP Stream with Overlay', frame)
# Press 'q' to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the capture and close the window
cap.release()
cv2.destroyAllWindows()
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
Get the metadata (SVG data) using the Websocket interface:Topic filter can be changed to get the AXIS Scene Metadata integration{
"eventFilterList": [
{
"topicFilter": "onvif:VideoAnalytics/axis:TrackEnded"
},
{
"topicFilter": "onvif:VideoAnalytics/axis:TrackUpdated"
}
]
} import json
import requests, re
import websockets
import asyncio
import hashlib
import base64
import uuid
import logging
logger = logging.getLogger('websockets')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
def calculate_digest_response(username, realm, password, uri, method, nonce, nc, cnonce):
ha1 = hashlib.md5(f"{username}:{realm}:{password}".encode()).hexdigest()
ha2 = hashlib.md5(f"{method}:{uri}".encode()).hexdigest()
response = hashlib.md5(
f"{ha1}:{nonce}:{nc}:{cnonce}:auth:{ha2}".encode()).hexdigest()
return response
async def connect(nonce):
username = 'Vivek'
password = 'Kumar'
realm = 'AXIS_B8A44FXXXXXX' #B8A44F279CC0 is the the MAC address of the camera.
uri = '/vapix/ws-data-stream?sources=events'
method = 'GET'
nc = '00000001'
cnonce = str(uuid.uuid4())
response = calculate_digest_response(
username, realm, password, uri, method, nonce, nc, cnonce)
print("Digest calculated response:", response, "\n")
authorization_header = f'Digest username="{username}", realm="{realm}", nonce="{nonce}", uri="{uri}", response="{response}", qop=auth, nc={nc}, cnonce="{cnonce}"'
print(" ---- Digest header ---- \n"+authorization_header+"\n")
websocket_uri = "ws://10.176.12.148/vapix/ws-data-stream?sources=events"
websocket_headers = {
"Authorization": authorization_header
}
try:
async with websockets.connect(websocket_uri, extra_headers=websocket_headers, user_agent_header=None) as websocket:
print("WebSocket connection established.")
# Prepare the JSON payload
payload = {
"apiVersion": "1.0",
"method": "events:configure",
"params": {
"eventFilterList": [
{
"topicFilter": "tnsaxis:CameraApplicationPlatform/ObjectAnalytics/xinternal_data"
}
]
}
}
# Convert the payload to JSON string
payload_json = json.dumps(payload)
# Send the JSON payload
await websocket.send(payload_json)
print("JSON payload sent.")
# Continue with WebSocket communication
while True:
message = await websocket.recv()
print(f"Received message: {message}")
except Exception as e:
print(e)
def extract_value(header, key):
match = re.search(fr'{key}="([^"]+)"', header)
if match:
return match.group(1)
return None
def perform_http_request():
username = 'Vivek'
password = 'Kumar'
url = 'http://10.176.12.148/axis-cgi/login.cgi'
# Make a GET request to obtain the Digest authentication headers
response = requests.get(url)
#print(response.text)
# Extract the required headers from the response
nonce = response.headers.get('WWW-Authenticate')
#print(nonce)
match = re.search(r'nonce="([^"]+)"', nonce)
if match:
nonce = match.group(1)
print("Nonce from response:", nonce,"\n")
else:
print("Nonce not found in the string.")
response = requests.get(url, auth=requests.auth.HTTPDigestAuth(username, password))
# Continue with the WebSocket connection using the obtained headers
asyncio.run(connect(nonce))
if __name__ == "__main__":
perform_http_request() |
Beta Was this translation helpful? Give feedback.
Hi @embeddeddev4 ,
Please try this API to enable the "selected_metadata_events" Feature Flag Service. I found this step after requesting the AXIS Scene Metadata MQTT Integration guide from here: AXIS Scene Metadata integration
The feature flag is available from AXIS OS 11.6.
http://10.176.12.148/axis-cgi/featureflag.cgi
JSON input parameters