Programmatic
- Last UpdatedFeb 12, 2024
- 3 minute read
Use the Programmatic option in cases where AVEVA Vision AI Assistant does not have direct access to the camera but the image datasets are available in a secondary location, or the camera is connected to a non-Microsoft Windows computer.
You can use REST API calls to send images from the secondary location to the skill securely. The API uses a secure application token configured in the AVEVA Vision AI Web Client to send images to the skill. The application token is a global setting for the specific computer where AVEVA Vision Service is installed and is not restricted to a skill. You can create multiple secure application tokens for different image locations. An expiration date is set for each token when they are created. You must create a new token once its date expires. This security token is separate to the System Management Server security configuration during installation. For more information on how to create an application token, see Application tokens.
After training the skill, a URL encapsulating the API, skill details, and security token can be used within a script to send images to the skill. See the following sample script.
Sample Script
FileInfo file = new FileInfo(@"image_file_path");
var imgBytes = File.ReadAllBytes(file.FullName);
Dictionary<string, object> postData = new Dictionary<string, object>();
postData.Add("img", imgBytes);
Dictionary<string, object> metaData = new Dictionary<string, object>();
metaData.Add("fileName", file.Name);
metaData.Add("dateTimeUTC", file.CreationTimeUtc.ToString("O"));
postData.Add("metaData", metaData);
var cancellationToken = new CancellationTokenSource();
cancellationToken.CancelAfter(60000); // cancel request after 60 seconds
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {your_bearer_token}");
HttpContent httpContent = new StringContent(JsonSerializer.Serialize(postData), Encoding.UTF8, "application/json");
var respose = client.PostAsync("https://host:port/apis/cameras/your_camera_guid/models/your_model_guid/prediction/data", httpContent, cancellationToken.Token);
respose.Result.EnsureSuccessStatusCode();
var result = respose.Result.Content.ReadAsStringAsync().Result;
var predictions = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(result);
The metaData in the sample script is the extracted EXIF from the image.
The upload strips the original EXIF data from the original image for security purposes.
Provide or specify the following from the sample script
-
image_file_path – Provide the path to the image location
-
your_bearer_token – Provide the token generated from the web client
-
your_camera_guid – Specify the unique ID identifying the camera
-
your_model_guid – Specify the unique ID identifying the skill
To configure a camera using the Programmatic option
-
On the Cameras side sheet page, select
(Add Camera).
The New Camera page opens, where you can now add a camera.
-
In the Camera Name box, enter a name for the camera.
-
From the Camera Type list, select Programmatic.
-
Select Save.
-
On the Cameras side sheet page, select the configured camera.
The camera is associated with the skill.
-
Select Next.
The Review and Run AI page appears.
-
On the Properties side sheet page, select the Programmatic tab.
The links for the Post and Get endpoints appear.
-
Optional: In the Image Timestamp box, enter a custom timestamp to display with the image.
A custom timestamp is accurate for tracking information. If you leave the Image Timestamp box blank, then the prediction displays the current timestamp instead.
-
Select Copy.
The endpoints are copied to use in the script.

-
Select Upload Image.
You can now test the programmatic camera and upload one image at a time.