Skip to main content

CognitiveServices

Namespace: Wisej.Ext.CognitiveServices

Assembly: Wisej.Ext.CognitiveServices (4.1.0.0)

The CognitiveServices component represents an object able to programmatically analyse images.

public class CognitiveServices : Component, IComponent

Constructors​

Instance member 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>";

Instance member CognitiveServices(container)​

Initializes a new instance of the CognitiveServices class together with the specified container.

NameTypeDescription
containerIContainerA IContainer that represents the container for the component.

Throws:

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​

Protected member 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.

Instance member LastRequest​

Request: Returns the last request.

Instance member RequestParameters​

String: Request Parameters that control the Cognitive Services. e.g. visualFeatures=Categories,Description,Color,Faces&language=en&details=Celebrities (Default: "")

Instance member SubscriptionKey​

String: Subscription key which provides access to Cognitive Services (Default: "")

Instance member 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​

Instance member StartAnalysisRequest(imageData)​

Starts the analysis of the specified image using the Computer Vision REST API.

ParameterTypeDescription
imageDataByte[]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);