Code Monkey home page Code Monkey logo

alt's Introduction

This project is now available at captionai.co

CaptionAI effortlessly generates automatic image captions (alternate text), description, tags, and helps you categorize images using the power of AI.

alt  Build Status

This project is no longer maintained.

Automatic alternative (alt) text for images using object detection with pre-trained model.

Overview

A very simple PHP library to generate alternative (alt) text for images using pre-trained tensorflow model to detect objects in an image. These texts can provide context about image to visitors who are unable to see images in their browser for whatever reasons. Alt texts can also be picked up by screen readers to convert it to speech, thus, providing additional context to visually impaired people and enhancing our user experience.

This nifty little tool is inspired by facebook alt text generation process.

Example

Image may contain: cup, potted plant, laptop
Image may contain: cup, potted, laptop
Image may contain: 6 person, cup, laptop
Image may contain: 6 person, cup, laptop
Image may contain: 5 person, car, motorcycle
Image may contain: 5 person, car, motorcycle
Image may contain: 1 person, car, bus, truck, traffic light
Image may contain: 1 person, car, bus, truck, traffic light
Image may contain: chair, couch
Image may contain: chair, couch
Image may contain: pizza, dining table
Image may contain: pizza, dining table
Image may contain: dog
Image may contain: dog
Image may contain: bird
Image may contain: bird

Installation

Requires: PHP 7.1.3+, OpenCV, PHP OpenCV
Model used: SSDLite COCO v2

Pull the package via composer.

$ composer require ankitpokhrel/alt

Usage

$alt = new \Alt\Alt('/path/to/image.ext');

echo $alt->alt(); // Image may contain: 6 person, cup, laptop

$alt->setImage('/path/to/image.ext')->alt(); // Image may contain: car, motorcycle

Threshold

The classification threshold is set to 30 by default. You can adjust it as your need.

$alt->setThreshold(25);

Prefix

By default the alt is prefixed with Image may contain: . You can change this as below:

$alt->setPrefix('Image has: ');

Countable

If you want to display the count of an object, you can do so by setting countable array. person is countable by default.

$alt->setImage('/path/to/image.ext')->alt(); // Image may contain: 5 person, dog, cup

// Adding dog as countable
$alt->setCountable(['person', 'dog'])->alt(); // Image may contain: 5 person, 2 dog, cup

Default text

Default text is used if the model is not able to predict any objects within a given threshold. Default default text is No photo description available..

$alt->setDefaultText('Some scenery.');

alt's People

Contributors

ankitpokhrel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.