Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Imaging-Cloud-NET
This Gist repository contains code snippet related to Aspose.Imaging.Cloud SDK for NET
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void BoundsAnImageInCloud()
{
// Input formats could be one of the following:
// bmp, jpeg, and jpeg2000
string sampleImageFileName = "object_detection_example.jpg";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new GetObjectBoundsRequest(sampleImageFileName, method, threshold, includeLabel, includeScore, folder, storage);
var detectedObjectList = this.ImagingApi.GetObjectBounds(request);
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void BoundsAnImageFromRequestBody()
{
// Input formats could be one of the following:
// bmp, jpeg, and jpeg2000
string sampleImageFileName = "object_detection_example.jpg";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string outPath = null;
string storage = null; // We are using default Cloud Storage
var request = new CreateObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, outPath, storage);
DetectedObjectList detectedObjectList = this.ImagingApi.CreateObjectBounds(request);
}
}
/// <summary>
/// Detect object on an image that is passed in a request stream.
/// </summary>
public void CountObjectOnPicture()
{
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
{
//detect objects on an image
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string outPath = null;
string storage = null;
var objectDetectionRequest = new CreateObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, outPath, storage);
DetectedObjectList detectedObjectList = this.ImagingApi.CreateObjectBounds(objectDetectionRequest);
var format = "jpg";
foreach(var obj in detectedObjectList.DetectedObjects)
{
//create crop request
var cropRequest =
new CreateCroppedImageRequest(
inputImageStream,
(int)obj.Bounds.X,
(int)obj.Bounds.Y,
(int)obj.Bounds.Width,
(int)obj.Bounds.Height,
format,
outPath,
storage);
using (var updatedImage = ImagingApi.CreateCroppedImage(cropRequest))
{
//...do something with a cropped image
}
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void DeskewAnImageInCloud()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "DeskewSampleImage.tif";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
bool resizeProportionally = true;
string bkColor = "white";
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new DeskewImageRequest(SampleImageFileName, resizeProportionally, bkColor, folder, storage);
using (Stream updatedImage = this.ImagingApi.DeskewImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "DeskewSampleImage_out.tiff")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet/tree/master/Examples
public void DeskewAnImageInRequestBody()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "DeskewSampleImage.tif";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))
{
bool resizeProportionally = true;
string bkColor = "white";
string storage = null; // We are using default Cloud Storage
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
var request = new CreateDeskewedImageRequest(inputImageStream, resizeProportionally, bkColor, outPath, storage);
using (Stream updatedImage = this.ImagingApi.CreateDeskewedImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "GDeskewSampleImage_out.tif")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
}
/// <summary>
/// Detect object on an image that is passed in a request stream.
/// </summary>
public void DetectObjectMovements(string objectLabel, int initTopLeftX, int initTopLeftY)
{
Console.WriteLine("Detect objects on an image. Image data is passed in a request stream");
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
{
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string outPath = null;
string storage = null; // We are using default Cloud Storage
var request = new CreateObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, outPath, storage);
Console.WriteLine($"Call CreateObjectBoundsRequest with params: method:{method}, threshold:{threshold}, include label: {includeLabel}, includeScore: {includeScore}");
DetectedObjectList detectedObjectList = this.ImagingApi.CreateObjectBounds(request);
foreach(var detectedObject in detectedObjectList)
{
if(detectedObject.Label == objectLabel)
{
if(detectedObject.Bounds.X != initTopLeftX
|| detectedObject.Bounds.Y != initTopLeftY)
{
//object moved
ShowAlertMessage();
}
}
}
}
Console.WriteLine();
}
/// <summary>
/// Detect object on an image that is passed in a request stream.
/// </summary>
public void DetectUndesiredObjects(string undesiredLabel)
{
Console.WriteLine("Detect objects on an image. Image data is passed in a request stream");
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
{
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string outPath = null;
string storage = null; // We are using default Cloud Storage
var request = new CreateObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, outPath, storage);
Console.WriteLine($"Call CreateObjectBoundsRequest with params: method:{method}, threshold:{threshold}, include label: {includeLabel}, includeScore: {includeScore}");
DetectedObjectList detectedObjectList = this.ImagingApi.CreateObjectBounds(request);
foreach(var detectedObject in detectedObjectList)
{
if(detectedObject.Label == undesiredLabel)
{
ShowAlertMessage();
}
}
}
Console.WriteLine();
}
/// <summary>
/// Detect objects on an image from a cloud storage.
/// </summary>
public static void DetectObjectsImageFromStorage()
{
string MyAppKey = "xxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
string MyAppSid = "xxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string folder = ""; // Input file is saved at default folder in the storage
string storage = null; // We are using default Cloud Storage
// Initialize Aspose.Imaging Cloud object
ImagingApi imagingApi = new ImagingApi(appKey: MyAppKey, appSid: MyAppSid, debug: false);
imagingApi.UploadFile(new Aspose.Imaging.Cloud.Sdk.Model.Requests.UploadFileRequest("dog-and-cat-cover.jpg", File.Open("dog-and-cat-cover.jpg", FileMode.Open), null));
var request = new Aspose.Imaging.Cloud.Sdk.Model.Requests.GetObjectBoundsRequest("dog-and-cat-cover.jpg", method, threshold, includeLabel, includeScore, folder, storage);
Console.WriteLine($"Call ObjectBoundsRequest with params: method:{method}, threshold:{threshold}, include label: {includeLabel}, includeScore: {includeScore}");
Aspose.Imaging.Cloud.Sdk.Model.DetectedObjectList detectedObjectList = imagingApi.GetObjectBounds(request);
// get count of objects in image file
Console.WriteLine("Objects detected: " + detectedObjectList.DetectedObjects.Count);
}
/// <summary>
/// Visualize detected object on an image that is passed in a request stream.
/// </summary>
public static void VisualizeObjectsImageFromRequestBody()
{
Console.WriteLine("Detect objects on an image. Image data is passed in a request stream");
string MyAppKey = "xxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
string MyAppSid = "xxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
// Initialize Aspose.Imaging Cloud object
ImagingApi imagingApi = new ImagingApi(appKey: MyAppKey, appSid: MyAppSid, debug: false);
using (FileStream inputImageStream = File.OpenRead("dog-and-cat-cover.jpg"))
{
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string color = null;
string outPath = null;
string storage = null; // We are using default Cloud Storage
var request = new Aspose.Imaging.Cloud.Sdk.Model.Requests.CreateVisualObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, color, outPath, storage);
Console.WriteLine($"Call CreateVisualObjectBoundsRequest with params: method:{method}, threshold:{threshold}, include label: {includeLabel}, include score: {includeScore}");
using (Stream updatedImage = imagingApi.CreateVisualObjectBounds(request))
{
// save updated image stream to system location
System.Drawing.Image img = System.Drawing.Image.FromStream(updatedImage);
img.Save("/Users/Aspose/Desktop/myImage.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
Console.WriteLine();
}
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void ConvertImageFromStorage()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string fileName = "WaterMark.bmp";
// Upload local image to Cloud Storage
using (FileStream localInputImage = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
var uploadFileRequest = new UploadFileRequest(fileName, localInputImage);
FilesUploadResult result = this.ImagingApi.UploadFile(uploadFileRequest);
}
// Please refer to https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats
// for possible output formats
string format = "pdf";
string folder = null; // Input file is saved at the root of the storage
string storage = null; // Cloud Storage name
var request = new ConvertImageRequest(fileName, format, folder, storage);
Stream updatedImage = this.ImagingApi.ConvertImage(request);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "Watermark_out." + format))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void CreateConvertedImageFromRequestBody()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string fileName = "WaterMark.bmp";
using (FileStream inputImageStream = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
// Please refer to https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats
// for possible output formats
string format = "pdf";
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
string storage = null; // Cloud Storage name
var request = new CreateConvertedImageRequest(inputImageStream, format, outPath, storage);
Stream updatedImage = this.ImagingApi.CreateConvertedImage(request);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "Watermark_out." + format))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void GrayscaleImageFromStorage()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "FilterEffectSampleImage.psd";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
var filterType = "GaussianBlur";
var filterProperties = new GaussianBlurFilterProperties
{
Radius = 4,
Sigma = 2.1
};
var format = "bmp";
var folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var filterEffectRequest = new FilterEffectImageRequest(SampleImageFileName, filterType, filterProperties,
format, folder, storage);
using (Stream updatedImage = this.ImagingApi.FilterEffectImage(filterEffectRequest))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "FilterEffectSampleImage_out.bmp")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void GetFrameRangeFromImageStorage()
{
string sampleImageFileName = "MultipageFile.djvuf";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
var startFrameId = 17; // Index of the first frame in range
var endFrameId = 23; // Index of the last frame in range
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new GetImageFrameRangeRequest(cloudFileName, startFrameId, endFrameId);
using (Stream frameRange = ImagingApi.GetImageFrameRange(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "DeskewSampleImage_out.tiff")))
{
frameRange.Seek(0, SeekOrigin.Begin);
frameRange.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet/tree/master/Examples
public void GetFrameRangeFromImageRequestBody()
{
string sampleImageFileName = "MultipageFile.djvu";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))
{
var startFrameId = 17; // Index of the first frame in range
var endFrameId = 23; // Index of the last frame in range
string storage = null; // We are using default Cloud Storage
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
var request = new CreateImageFrameRangeRequest(cloudFileName, startFrameId, endFrameId);
using (Stream frameRange = this.ImagingApi.CreateImageFrameRange(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "MultipageFile_out.djvu")))
{
frameRange.Seek(0, SeekOrigin.Begin);
frameRange.CopyTo(fileStream);
}
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void GrayscaleImageFromStorage()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "GrayscaleSampleImage.bmp";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new GrayscaleImageRequest(sampleImageFileName, folder, storage);
using (Stream updatedImage = this.ImagingApi.GrayscaleImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "GrayscaleSampleImage_out.bmp")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet/tree/master/Examples
public void CreateGrayscaledImageFromRequestBody()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "GrayscaleSampleImage.bmp";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))
{
String outPath = null; // Path to updated file (if this is empty, response contains streamed image).
String storage = null; // We are using default Cloud Storage
var request = new CreateGrayscaledImageRequest(inputImageStream, outPath, storage);
using (Stream updatedImage = this.ImagingApi.CreateGrayscaledImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "GrayscaleSampleImage_out.bmp")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void VisualBoundsAnImageInCloud()
{
// Input formats could be one of the following:
// bmp, jpeg, and jpeg2000
string sampleImageFileName = "object_detection_example.jpg";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string color = "blue";
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new GetVisualObjectBoundsRequest(SampleImageFileName, method, threshold, includeLabel, includeScore, color, folder, storage);
using (Stream updatedImage = this.ImagingApi.GetVisualObjectBounds(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "object_detection_example_out.jpg")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void VisualBoundsAnImageFromRequestBody()
{
// Input formats could be one of the following:
// bmp, jpeg, and jpeg2000
string sampleImageFileName = "object_detection_example.jpg";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string color = null;
string outPath = null;
string storage = null; // We are using default Cloud Storage
var request = new CreateVisualObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, color, outPath, storage);
using (Stream updatedImage = this.ImagingApi.CreateVisualObjectBounds(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "object_detection_example_out.jpg")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.