CognitiveServices
Namespace: Wisej.Ext.CognitiveServices
Assembly: Wisej.Ext.CognitiveServices (4.1.0.0)
The CognitiveServices component represents an object able to programmatically analyse images.
- C#
- VB.NET
public class CognitiveServices : Component, IComponent
Public Class CognitiveServices
Inherits Component
Implements IComponent
Constructors
CognitiveServices()
Initializes a new instance of the CognitiveServices class.
Example:
var cognitiveServices = new CognitiveServices();
cognitiveServices.UriBase = "https://eastus.api.cognitive.microsoft.com/vision/v1.0/analyze";
cognitiveServices.SubscriptionKey = "<your-subscription-key>";
CognitiveServices(container)
Initializes a new instance of the CognitiveServices class together with the specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | A IContainer that represents the container for the component. |
Throws:
- ArgumentNullException container is null.
Example:
// in a Wisej Form or Page, add the component to the designer's container
// so it is disposed together with the form.
this.cognitiveServices1 = new CognitiveServices(this.components);
this.cognitiveServices1.SubscriptionKey = "<your-subscription-key>";
Properties
DesignMode
Boolean: Returns a value that indicates whether the IComponent is currently in design mode.
Value: true if the IComponent is in design mode; otherwise, false.
LastRequest
Request: Returns the last request.
RequestParameters
String: Request Parameters that control the Cognitive Services. e.g. visualFeatures=Categories,Description,Color,Faces&language=en&details=Celebrities (Default: "")
SubscriptionKey
String: Subscription key which provides access to Cognitive Services (Default: "")
UriBase
String: Base Uri for Cognitive Services. Depends on region server. Please note that the region must match with your subscription. e.g. href="https://eastus.api.cognitive.microsoft.com/vision/v1.0/analyze" (Default: "")
Methods
StartAnalysisRequest(imageData)
Starts the analysis of the specified image using the Computer Vision REST API.
| Parameter | Type | Description |
|---|---|---|
| imageData | Byte[] | The image to analyze, as a byte array (JPEG, PNG, GIF or BMP). |
The image is posted as application/octet-stream to UriBase followed by ? and RequestParameters, using SubscriptionKey in the Ocp-Apim-Subscription-Key header. The method returns immediately; the request runs asynchronously.
Example:
var cognitiveServices = new CognitiveServices();
cognitiveServices.UriBase = "https://eastus.api.cognitive.microsoft.com/vision/v1.0/analyze";
cognitiveServices.SubscriptionKey = "<your-subscription-key>";
cognitiveServices.RequestParameters = "visualFeatures=Categories,Description,Color&language=en";
byte[] imageData = File.ReadAllBytes(Application.MapPath("Images/photo.jpg"));
cognitiveServices.StartAnalysisRequest(imageData);