Skip to content

Latest commit

 

History

History
74 lines (61 loc) · 2.55 KB

README.md

File metadata and controls

74 lines (61 loc) · 2.55 KB

JuiceKit Watson

Build Status Codacy Badge Codacy Badge

JuiceKit Watson is a PHP implementation of IBM's Watson REST API.

Note: Currently, only the VisualRecognition API is supported, other APIs will be supported in the future. For more information on available Watson APIs visit http://www.ibm.com/watson/developercloud/

Installation

composer require juicekit/watson

Example Usage

Classify an image from a url or file

<?php
require_once '../vendor/autoload.php';

use JuiceKit\Watson as Watson;

$visualRecognition = new Watson\VisualRecognition\v3\VisualRecognition('YOUR_API_KEY', 'YOUR_VERSION');

/**
 * $responseWithImageUrl = [
 *      'custom_classes'=> 0,
 *      'images'=> [
 *          [
 *              'classifiers'=> [
 *                  'classes'=> [
 *                      [
 *                          'class'=> 'person',
 *                          'score'=> '0.999999',
 *                          'type_hierarchy'=> '/people'
 *                      ]
 *                  ],
 *                  'classifier_id'=> 'default',
 *                  'name'=> 'default'
 *              ]
 *          ]
 *      ],
 *      'images_processed'=> 1
 * ]
 */
$responseWithImageUrl = $visualRecognition->classify('http://your-image-resource.com/image.jpg');

$imageResource = fopen('your-image.jpg', 'r');

/**
 * $responseWithImageFile = [
 *      'custom_classes'=> 0,
 *      'images'=> [
 *          [
 *              'classifiers'=> [
 *                  'classes'=> [
 *                      [
 *                          'class'=> 'person',
 *                          'score'=> '0.999999',
 *                          'type_hierarchy'=> '/people'
 *                      ]
 *                  ],
 *                  'classifier_id'=> 'default',
 *                  'name'=> 'default'
 *              ]
 *          ]
 *      ],
 *      'images_processed'=> 1
 * ]
 */
$responseWithImageFile = $visualRecognition->classify($imageResource);