Aspose.Imaging Cloud 20.5 출시와 함께 이미지에서 객체 감지 기능을 발표하게 되어 기쁩니다. 이 기능을 사용하면 사용자는 레이블과 확률을 기반으로 입력 이미지에서 객체 경계를 감지할 수 있습니다. 현재 구현은 COCO 2017 데이터 세트를 사용하여 모델을 학습한 객체를 인식하는 단일 샷 감지기 방법을 지원합니다. SSD 방식은 경계 상자의 출력 공간을 피처 맵 위치당 다양한 종횡비와 스케일에 대한 기본 상자 세트로 이산화합니다.

Aspose.Imaging Cloud는 다음의 4가지 방법을 기반으로 객체 감지를 수행합니다.

  1. 기존 이미지에서 객체를 감지하고 결과를 JSON 객체로 반환합니다.
  2. 기존 이미지에서 객체를 감지하고 결과를 이미지로 반환합니다.
  3. 이미지를 업로드하고 이미지의 객체를 감지하고 결과를 JSON 객체로 반환합니다.
  4. 이미지를 업로드하고, 이미지에서 객체를 감지하고, 결과를 이미지로 반환합니다.

이 섹션에서는 다음 섹션에 대해 더 자세히 논의합니다.

객체 경계 감지

이 접근 방식은 기존 이미지에서 객체를 감지하고 그 결과를 JSON 객체로 반환합니다.

요청 쿼리 매개변수:

  • name(문자열, 필수): 이미지 이름. 현재 BMP, JPEG, JPEG 2000의 3가지 이미지 형식을 지원합니다.
  • 방법(문자열, 선택 사항, 기본값 “ssd”): 객체 감지 방법.
  • 임계값(숫자, 선택 사항, [0 - 100], 기본값 50): 결과에 포함될 최소 감지 객체 확률(백분율).
  • includeLabel(부울, 선택 사항, 기본값 false): 감지된 개체 라벨을 응답에 포함할지 여부입니다.
  • includeScore(부울, 선택 사항, 기본값 false): 감지된 객체 확률을 응답에 포함할지 여부입니다.
  • 폴더(문자열, 선택 사항): 폴더.
  • 저장소(문자열, 선택 사항): 저장소.

cURL 명령을 사용한 객체 감지

Aspose.Imaging Cloud는 cURL 명령을 사용하여 액세스할 수도 있습니다. 다음 명령은 cURL 명령을 사용하여 객체를 감지하고 JSON 객체로 응답을 얻는 방법을 보여줍니다.

우리는 다음 이미지를 사용하여 객체를 감지합니다.

샘플 고양이 이미지

이미지 1:- 출처 이미지

curl "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/cat-pet-animal-domestic-104827.jpeg/bounds?method=ssd&threshold=50&includeLabel=true&includeScore=true" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer <jwt token>"

요청 URL

https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/cat-pet-animal-domestic-104827.jpeg/bounds?method=ssd&threshold=50&includeLabel=true&includeScore=true

응답 기관

{
  "detectedObjects": [
    {
      "label": "cat",
      "score": 0.9450986,
      "bounds": {
        "x": 43,
        "y": 4,
        "width": 401,
        "height": 323
      }
    }
  ]
}

응답 스키마

{
    "type": "object",
    "properties": {
        "detectedObjects": {
            "type": "array",
            "items": [
                {
                    "type": "object",
                    "properties": {
                        "score": {
                            "type": "number"
                        },
                        "label": {
                            "type": "string"
                        },
                        "bounds": {
                            "type": "object",
                            "properties": {
                                "x": {
                                    "type": "number"
                                },
                                "y": {
                                    "type": "number"
                                },
                                "width": {
                                    "type": "number"
                                },
                                "height": {
                                    "type": "number"
                                }
                            },
                            "required": [
                                "x",
                                "y",
                                "width",
                                "height"
                            ]
                        }
                    },
                    "required": [
                        "score",
                        "label",
                        "bounds"
                    ]
                }
            ]
        }
    },
    "required": [
        "detectedObjects"
    ]
}

C#을 사용하여 이미지에서 객체 감지

C# 코드 조각을 사용하여 이미지에서 객체를 감지하려면 다음 코드 조각을 사용해보세요.

C# .NET 코드 조각

///<summary>
/// 클라우드 저장소의 이미지에서 객체를 감지합니다.
///</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

    // Aspose.Imaging Cloud 객체를 초기화합니다.
    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);
    // 이미지 파일에 있는 객체의 개수를 구하다
    Console.WriteLine("Objects detected: " + detectedObjectList.DetectedObjects.Count);
}

객체 경계를 감지하고 이미지로 반환

이미지를 업로드하고, 객체를 감지하고, 객체 주위에 경계를 그린 다음 결과를 이미지로 반환합니다.

요청 쿼리 매개변수:

  • name(문자열, 필수): 이미지 이름. 현재 3가지 이미지 형식이 지원됩니다: bmp, jpg, jpeg, jpeg2000.
  • 방법(문자열, 선택 사항, [“ssd”], 기본값 “ssd”): 객체 감지 방법.
  • 임계값(숫자, 선택 사항, [0 - 100], 기본값 50): 결과에 포함될 최소 개체의 확률(백분율).
  • includeLabel(부울, 선택 사항, 기본값 false): 감지된 개체 라벨을 응답에 포함할지 여부입니다.
  • includeScore(부울, 선택 사항, 기본값 false): 감지된 객체 확률을 응답에 포함할지 여부입니다.
  • color(문자열, 선택 사항): 감지된 객체 경계 및 정보의 사용자 지정 색상. null과 같은 경우, 다른 레이블의 객체는 다른 색상의 경계를 갖습니다.
  • 폴더(문자열, 선택 사항): 폴더.
  • 저장소(문자열, 선택 사항): 저장소.

cURL 명령을 사용하여 객체 결정

Aspose.Imaging Cloud는 cURL 명령을 통해서도 액세스할 수 있습니다. 그러나 전제 조건으로 먼저 클라이언트 자격 증명을 기반으로 JWT 액세스 토큰을 생성해야 합니다. 다음 명령을 실행하여 JWT 토큰을 생성하세요.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=4ccf1790-accc-41e9-8d18-a78dbb2ed1aa&client_secret=caac6e3d4a4724b2feb53f4e460eade3" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

이제 다음 명령을 실행하여 객체 경계를 감지하고 이를 이미지로 반환합니다.

curl -v "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/dog-and-cat-cover.jpg/visualbounds?method=ssd&threshold=50&includeLabel=false&includeScore=false&color=Red" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

요청 URL

https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/dog-and-cat-cover.jpg/visualbounds?method=ssd&threshold=50&includeLabel=false&includeScore=false&color=Red

위 요청에서는 강조 색상으로 빨간색이 지정되었습니다.

C#.NET 코드 조각

다음 코드 조각은 두 개의 객체(개와 고양이)가 포함된 이미지 파일을 로드하는 단계를 보여줍니다. 이 두 객체는 모두 Aspose.Imaging Cloud API를 사용하여 식별됩니다. 강조 표시된 객체가 있는 결과 이미지는 시스템 드라이브에 저장됩니다.

///<summary>
/// 요청 스트림을 통해 전달된 이미지에서 감지된 객체를 시각화합니다.
///</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/
    // Aspose.Imaging Cloud 객체를 초기화합니다.
    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))
        {
            // 업데이트된 이미지 스트림을 시스템 위치에 저장
            System.Drawing.Image img = System.Drawing.Image.FromStream(updatedImage);
            img.Save("/Users/Aspose/Desktop/myImage.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
    Console.WriteLine();
}
고양이와 개 표지 이미지

이미지 2: 고양이와 개가 있는 입력 이미지

식별된 객체를 강조하는 처리된 이미지

이미지 3: 식별된 객체를 강조하는 처리된 이미지

이미지 검색에 대한 자세한 내용은 역방향 이미지 검색을 방문하세요.

결론

이 글에서는 이미지에서 객체 감지를 위한 Aspose.Imaging Cloud의 기능에 대해 알아보았습니다. 이미지에서 객체를 식별하려면 코드 조각을 사용하거나 cURL 명령을 사용할 수 있습니다. 또한 고객의 편의를 위해 프로그래밍 언어별 SDK를 만들었고 위의 글에서는 객체 감지를 위한 Aspose.Imaging Cloud SDK for .NET의 기능을 살펴보았습니다. SDK의 전체 소스 코드는 GitHub에서 다운로드할 수 있습니다.

관련기사

자세한 내용을 알아보려면 다음 링크를 방문하세요.