2017-06-02 5 views
-1

イメージを認識し、nsfw、sfwなどのような予測を調べるには、次のサンプルコードをobjective-cで実行します。Clarifai cropの使い方は?

// 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で利用可能な作物機能に到達する方法を得ていません。

アイデア

答えて

1

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]; 
+0

@D Cirne返信ありがとう –

関連する問題