如何使用 Clarifai 作物?

How to use Clarifai crop?

我可以使用 objective-c 中的以下示例代码识别图像并检查 nsfw、sfw 等预测。

  // Initialize the Clarifai app with your app's ID and Secret.
ClarifaiApp *app = [[ClarifaiApp alloc] initWithAppID:@""
                                            appSecret:@""];

// Fetch Clarifai's general model.
[app getModelByName:@"general-v1.3" completion:^(ClarifaiModel *model, NSError *error) {
    // Create a Clarifai image from a uiimage.
    ClarifaiImage *clarifaiImage = [[ClarifaiImage alloc] initWithImage:image];

    // Use Clarifai's general model to pedict tags for the given image.
    [model predictOnImages:@[clarifaiImage] completion:^(NSArray<ClarifaiOutput *> *outputs, NSError *error) {
        if (!error) {
            ClarifaiOutput *output = outputs[0];

            // Loop through predicted concepts (tags), and display them on the screen.
            NSMutableArray *tags = [NSMutableArray array];
            for (ClarifaiConcept *concept in output.concepts) {
                [tags addObject:concept.conceptName];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                self.textView.text = [NSString stringWithFormat:@"Tags:\n%@", [tags componentsJoinedByString:@", "]];
            });
        }

      dispatch_async(dispatch_get_main_queue(), ^{
        self.button.enabled = YES;
      });

    }];
}];

为此,我可以获得模型,并从该模型中预测图像。

问题:

如何实现裁剪功能? 我无法获得 Clarifai 中可用的裁剪功能。

任何想法。

您可以使用 ClarifaiCrop class and using it to initialize a ClarifaiImage 创建裁剪。

ClarifaiCrop *crop = [[ClarifaiCrop alloc] initWithTop:0.1 
                                                  left:0.1
                                                bottom:0.1
                                                 right:0.1];

其中 top、left、bottom 和 right 是从图像边界到感兴趣区域的距离的百分比(介于 0 和 1 之间)。在上面的示例中,图像将从每个边距裁剪 10%。

ClarifaiImage *clarifaiImage = [[ClarifaiImage alloc] initWithImage:image 
                                                            andCrop:crop];