PHP code example of michaeljwright / aws-rekognition

1. Go to this page and download the library: Download michaeljwright/aws-rekognition library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaeljwright / aws-rekognition example snippets



// config/app.php

return [

    // ...

    'providers' => [

        // ...

        /*
         * Package Service Providers...
         */
        MichaelJWright\Rekognition\RekognitionServiceProvider::class, // [a]

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    // ...

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,

        // ...

        'Rekognition' => 'MichaelJWright\Rekognition\RekognitionFacade', // [b]
        'Hash' => Illuminate\Support\Facades\Hash::class,

        // ...
    ],

];




class LabelDetectionImage extends Model
{
    /**
     * Upload image to S3
     *
     * @param Illuminate\Http\UploadedFile  $file
     *
     * @return string
     */
    public function upload(UploadedFile $file) : string
    {
        $name = time() . $file->getClientOriginalName();

        \Rekognition::uploadImageToS3(file_get_contents($file), null, self::BUCKET, $name);

        return $name;
    }
}



// FIRST call startLabelDetection to create a rekognition job

$config = [
       'MinConfidence' => 80, //set confidence level for probability of correct labels
       'Video' => [
           'S3Object' => [
               'Bucket' => 'YOUR_BUCKET_NAME',
               'Name' => 'YOUR_VIDEO_FILE_NAME',
           ],
       ],
   ];
$job = \Rekognition::startLabelDetection($config); //start a job in rekognition for specific video file
dd($job['JobId']); //output job id so you can use it to get the labels

// THEN call getLabelDetection to get the labels for the specific job

$config = [
       'JobId' => 'YOUR_JOB_ID',
       'SortBy' => 'NAME', //set to whatever you want to sort the labels by
   ];
$job = \Rekognition::getLabelDetection($config);
dd($job['Labels']); //output the labels