removing overlay not working #762
-
I'm trying dynamic overlay on an axis camera. here's my code: import requests urllib3.disable_warnings(urllib3.execptions.InsecureRequestWarning) username = XXXXXXX for i in range(8): response = request.post(url, json=paramaters, auth=auth, verify=False) This works, but the overlays 1-8 end up on top of eachother. I found out that you have to remove the overlay. I tried this code: for i in range(8): But I get error: {'apiVersion': '1.7', 'error': '{'code': 302, 'message': 'Invalid value for parameter identity'}, 'method': 'remove'} I understand that something is wrong with i in my for-loop but I changed it to a formatted string which doesn't work either. Thanks in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 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.
-
Hi @roomsjesse , Basically 'method': 'addText' is to add a new overlay and return the identity for the new overlay created. Then you can use 'method': 'setText' to update the text. Sample code for your reference: import requests
from requests.auth import HTTPDigestAuth
import urllib3
import time
# Disable warnings about insecure requests (self-signed certificates, etc.)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
username = "Vivek"
password = "Kumar"
auth = HTTPDigestAuth(username, password)
# URL for overlay API
url = 'http://10.176.12.130/axis-cgi/dynamicoverlay/dynamicoverlay.cgi'
# Check for existing overlays
check_overlay_body = {
"apiVersion": "1.0",
"context": "Vivek's API call to list",
"method": "list",
"params": {}
}
response = requests.post(url, json=check_overlay_body, auth=auth, verify=False)
if response.status_code == 200:
response_data = response.json()
existing_text_overlays = response_data.get("data", {}).get("textOverlays", [])
if not existing_text_overlays:
print("No existing text overlays found.")
else:
print(f"Found {len(existing_text_overlays)} existing text overlays:")
for overlay in existing_text_overlays:
identity = overlay.get("identity")
text = overlay.get("text")
position = overlay.get("position")
print(f" - Identity: {identity}, Text: {text}, Position: {position}")
# Prompt the user for overlay_identity
overlay_identity = int(input("Enter the overlay identity number to check: "))
# Search for the overlay_identity in the existing text overlays
overlay_exists = any(overlay.get("identity") == overlay_identity for overlay in existing_text_overlays)
if overlay_exists:
print(f"Overlay with identity {overlay_identity} already exists. Deleting it...")
# Delete the existing overlay
delete_overlay_body = {
"apiVersion": "1.0",
"context": "Vivek's API call to remove",
"method": "remove",
"params": {
"identity": overlay_identity
}
}
delete_response = requests.post(url, json=delete_overlay_body, auth=auth, verify=False)
if delete_response.status_code == 200:
print(f"Overlay with identity {overlay_identity} successfully deleted.")
else:
print(f"Failed to delete overlay: {delete_response.status_code} - {delete_response.text}")
else:
print(f"No overlay with identity {overlay_identity} exists. Proceeding to add a new overlay.")
# Now you can add a new overlay or proceed with further actions
add_overlay_body = {
"apiVersion": "1.0",
"context": "Vivek's API call to add overlay",
"method": "addText",
"params": {
"camera": 1,
"text": "%c",
"position": "topLeft",
"textColor": "white",
"fontSize": 174
}
}
response = requests.post(url, json=add_overlay_body, auth=auth, verify=False)
if response.status_code == 200:
response_data = response.json()
new_overlay_identity = response_data.get("data", {}).get("identity")
if new_overlay_identity is not None:
print(f"New overlay added with identity: {new_overlay_identity}")
# Update overlay in subsequent requests with a 5-second delay
for i in range(8):
set_text_body = {
"apiVersion": "1.0",
"context": "Vivek's API call to set text",
"method": "setText",
"params": {
"identity": new_overlay_identity,
"text": f"Text {i}"
}
}
response = requests.post(url, json=set_text_body, auth=auth, verify=False)
print(f"Response {i}: {response.status_code} - {response.text}")
time.sleep(5) # Add a 5-second delay before the next update
else:
print("Failed to retrieve new overlay identity.")
else:
print(f"Failed to add new overlay: {response.status_code} - {response.text}")
else:
print(f"Failed to list existing overlays: {response.status_code} - {response.text}")
Output:Count_to_7.mp4 |
Beta Was this translation helpful? Give feedback.
Hi @roomsjesse ,
You can find the documentation here: Dynamic overlay API.
Basically 'method': 'addText' is to add a new overlay and return the identity for the new overlay created. Then you can use 'method': 'setText' to update the text.
Sample code for your reference: