如何使用Clarifai作物



我可以识别图像并检查诸如NSFW,SFW等的预测,并在Objective-C中使用以下示例代码。

  // 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类创建农作物并使用它来初始化Clarifaiimage。

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

顶部,左,底部和右侧是从图像边界到感兴趣区域的距离的百分比(0到1之间(。在上面的示例中,图像将从每个边缘裁剪10%。

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

最新更新