vision

package module
v0.0.0-...-185a1b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2016 License: MIT Imports: 11 Imported by: 0

README

microsoft-vision-golang

A library for communication with microsoft cognitive services API written in Golang

Build Status Coverage Status GoDoc GoReport

Dependencies

Nothing ! I wrote this library on Golang 1.5.4 linux/amd64

According to travis-cl will work on Golang 1.2 or later

RTFM !

The full documention of microsoft cognitive services API is in this link and API reference is in here

How to use ?

First of all download the library

go get github.com/ahmdrz/microsoft-vision-golang

Here is a simple code

The key is subscription key which provides access to this API. Found in your subscriptions.

Tags :

// test project main.go
package main

import (
	"fmt"

	"github.com/ahmdrz/microsoft-vision-golang"
)

func main() {
	fmt.Println("Hello World!")
	vision, err := vision.New("<KEY>")
	if err != nil {
		panic(err)
	}

	result, err := vision.Tag("https://portalstoragewuprod2.azureedge.net/vision/Analysis/1.jpg")
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}

Analyze :

// test project main.go
package main

import (
	"fmt"

	"github.com/ahmdrz/microsoft-vision-golang"
)

func main() {
	fmt.Println("Hello World!")
	vis, err := vision.New("<KEY>")
	if err != nil {
		panic(err)
	}

	result, err := vis.Analyze("https://portalstoragewuprod2.azureedge.net/vision/Analysis/1.jpg",
		vision.VisualFeatures{
			Adult: true,
			Tags:  true,
		})
	if err != nil {
		panic(err)
	}

	fmt.Println(result)
}
License

MIT License

Copyright (c) 2016 Ahmadreza Zibaei

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package vision is a library for micrsoft vision api

Let's start to make a request to bing vision Full documention is on https://dev.projectoxford.ai/docs/services/56f91f2d778daf23d8ec6739/

Installation : go get github.com/ahmdrz/microsoft-vision-golang

First of all , let me to explain how to use image from url.

Tag method :

func main() {
	vision, err := vision.New("<KEY>")
    if err != nil {
        panic(err)
    }

    result, err := vision.Tag("https://portalstoragewuprod2.azureedge.net/vision/Analysis/1.jpg")
    if err != nil {
        panic(err)
    }
    fmt.Println(result)
}

Analyze method :

func main() {
	vis, err := vision.New("<KEY>")
    if err != nil {
        panic(err)
    }

    result, err := vis.Analyze("https://portalstoragewuprod2.azureedge.net/vision/Analysis/1.jpg",
        vision.VisualFeatures{
            Adult: true,
            Tags:  true,
        })
    if err != nil {
        panic(err)
    }
}

------

In analyze method we have VisualFeatures , Source of VisualFeatures struct is

type VisualFeatures struct {
	Categories  bool
	Tags        bool
	Description bool
	Faces       bool
	ImageType   bool
	Color       bool
	Adult       bool
}

... and func (order VisualFeatures) String() (string, error) can make a string from this struct

vision project vision.go license MIT powered by github.com/ahmdrz full api reference on https://dev.projectoxford.ai/docs/services/56f91f2d778daf23d8ec6739/

Index

Constants

View Source
const (
	URL                     string = "https://api.projectoxford.ai/vision/v1.0"
	LANG_AutoDetect         string = "unk"
	LANG_ChineseSimplified  string = "zh-Hans"
	LANG_ChineseTraditional string = "zh-Hant"
	LANG_Czech              string = "cs"
	LANG_Danish             string = "da"
	LANG_Dutch              string = "nl"
	LANG_English            string = "en"
	LANG_Finnish            string = "fi"
	LANG_French             string = "fr"
	LANG_German             string = "de"
	LANG_Greek              string = "el"
	LANG_Hungarian          string = "hu"
	LANG_Italian            string = "it"
	LANG_Japanese           string = "Ja"
	LANG_Korean             string = "ko"
	LANG_Norwegian          string = "nb"
	LANG_Polish             string = "pl"
	LANG_Portuguese         string = "pt"
	LANG_Russian            string = "ru"
	LANG_Spanish            string = "es"
	LANG_Swedish            string = "sv"
	LANG_Turkish            string = "tr"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adult

type Adult struct {
	IsAdultContent bool    `json:"isAdultContent"`
	IsRacyContent  bool    `json:"isRacyContent"`
	AdultScore     float64 `json:"adultScore"`
	RacyScore      float64 `json:"racyScore"`
}

type Caption

type Caption struct {
	Text       string  `json:"text"`
	Confidence float64 `json:"confidence"`
}

type Category

type Category struct {
	Name  string  `json:"name"`
	Score float32 `json:"score"`
}

type Color

type Color struct {
	DominantColorForeground string   `json:"dominantColorForeground"`
	DominantColorBackground string   `json:"dominantColorBackground"`
	AccentColor             string   `json:"accentColor"`
	IsBWImg                 bool     `json:"isBWImg"`
	DominantColors          []string `json:"dominantColors"`
}

type Description

type Description struct {
	Tags     []string  `json:"tags"`
	Captions []Caption `json:"captions"`
}

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type Face

type Face struct {
	Age           int       `json:"age"`
	Gender        string    `json:"gender"`
	FaceRectangle Rectangle `json:"faceRectangle"`
}

type Image

type Image struct {
	Image []byte
}

func (Image) Save

func (image Image) Save(path string) error

type ImageType

type ImageType struct {
	ClipArtType     int `json:"clipArtType"`
	LineDrawingType int `json:"lineDrawingType"`
}

type Line

type Line struct {
	BoundingBox string `json:"boundingBox"`
	Words       []Word `json:"words"`
}

type MetaData

type MetaData struct {
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Format string `json:"format"`
}

type Model

type Model struct {
	Name       string   `json:"name"`
	Categories []string `json:"categories"`
}

type OCROption

type OCROption struct {
	Language          string
	DetectOrientation bool
}

func (OCROption) String

func (order OCROption) String() string

type Rectangle

type Rectangle struct {
	Top    int `json:"top"`
	Left   int `json:"left"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

type Region

type Region struct {
	BoundingBox string `json:"boundingBox"`
	Lines       []Line `json:"lines"`
}

type Tag

type Tag struct {
	Name       string  `json:"name"`
	Confidence float64 `json:"confidence"`
}

type ThumbnailOrder

type ThumbnailOrder struct {
	Width         int
	Height        int
	SmartCropping bool
}

type Vision

type Vision struct {
	BingKey       string
	LastRequestID string
}

Main struct of library , contains BingKey for saving token and LastRequestID for determine the request id of last method.

func New

func New(key string) (*Vision, error)

func (*Vision) Analyze

func (vision *Vision) Analyze(url string, order VisualFeatures) (VisionResult, error)

func (*Vision) AnalyzeFile

func (vision *Vision) AnalyzeFile(path string, order VisualFeatures) (VisionResult, error)

func (*Vision) Describe

func (vision *Vision) Describe(url string, max int) (VisionResult, error)

func (*Vision) DescribeFile

func (vision *Vision) DescribeFile(path string, max int) (VisionResult, error)

func (*Vision) GetModels

func (vision *Vision) GetModels() ([]Model, error)

func (*Vision) OCR

func (vision *Vision) OCR(url string, order OCROption) (VisionOCRResult, error)

func (*Vision) OCRFile

func (vision *Vision) OCRFile(path string, order OCROption) (VisionOCRResult, error)

func (*Vision) Tag

func (vision *Vision) Tag(url string) (VisionResult, error)

func (*Vision) TagFile

func (vision *Vision) TagFile(path string) (VisionResult, error)

func (*Vision) Thumbnail

func (vision *Vision) Thumbnail(url string, order ThumbnailOrder) (Image, error)

type VisionOCRResult

type VisionOCRResult struct {
	Language    string   `json:"language"`
	TextAngle   float64  `json:"textAngle"`
	Orientation string   `json:"orientation"`
	Regions     []Region `json:"regions"`
}

func (VisionOCRResult) String

func (order VisionOCRResult) String() (result string)

this method can make a full sentence from OCR result

type VisionResult

type VisionResult struct {
	RequestID   string      `json:"requestId"`
	Categories  []Category  `json:"categories"`
	Adult       Adult       `json:"adult"`
	Faces       []Face      `json:"faces"`
	ImageType   ImageType   `json:"imageType"`
	Color       Color       `json:"color"`
	MetaData    MetaData    `json:"metadata"`
	Description Description `json:"description"`
	Tags        []Tag       `json:"tags"`
}

type VisualFeatures

type VisualFeatures struct {
	Categories  bool
	Tags        bool
	Description bool
	Faces       bool
	ImageType   bool
	Color       bool
	Adult       bool
}

func (VisualFeatures) String

func (order VisualFeatures) String() (string, error)

type Word

type Word struct {
	BoundingBox string `json:"boundingBox"`
	Text        string `json:"text"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL