Class: DeepStack

Inherits:
Object
  • Object
show all
Includes:
CustomModel, Detection, Face, Scene
Defined in:
lib/deep_stack/version.rb,
lib/deep_stack/face.rb,
lib/deep_stack/scene.rb,
lib/deep_stack/detection.rb,
lib/deep_stack/deep_stack.rb,
lib/deep_stack/custom_model.rb

Overview

DeepStack API

Defined Under Namespace

Modules: CustomModel, Detection, Face, Scene

Constant Summary collapse

VERSION =

Returns Version of DeepStack helper libraries.

Returns:

  • (String)

    Version of DeepStack helper libraries

'1.5.0'

Instance Method Summary collapse

Methods included from CustomModel

#custom_model

Methods included from Scene

#identify_scene

Methods included from Detection

#detect_objects

Methods included from Face

#delete_face, #delete_faces, #detect_faces, #face_list, #face_match, #recognize_faces, #register_face

Constructor Details

#initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil) ⇒ DeepStack

Create a deepstack object connected to the given URL

Examples:

DeepStack.new('http://127.0.0.1:5000')

# Using API KEY:
DeepStack.new('http://127.0.0.1:5000', api_key: 'secret', admin_key: 'supersecret')

# Connect to SSL with a self-signed certificate
DeepStack.new('https://localhost:443', verify_mode: OpenSSL::SSL::VERIFY_NONE)

Parameters:

  • base_url (String)

    the url to DeepStack’s server:port

  • api_key (String) (defaults to: nil)

    an optional API-KEY to use when connecting to DeepStack

  • api_key (String) (defaults to: nil)

    an optional API-KEY to use when connecting to DeepStack

  • verify_mode (Integer) (defaults to: nil)

    sets the flags for server the certification verification at beginning of SSL/TLS session. OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER are acceptable.



37
38
39
40
41
42
43
44
# File 'lib/deep_stack/deep_stack.rb', line 37

def initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil)
  @base_url = base_url
  @auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values
  uri = URI(base_url)
  http_options = {}
  http_options[:verify_mode] = verify_mode if verify_mode
  @http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.instance_of?(URI::HTTPS), **http_options)
end

Instance Method Details

#api_post(path, *images, **args) ⇒ Hash

Make a POST request to DeepStack path target

Parameters:

  • path (String)

    to the DeepStack API URL

  • images (Array)

    zero or more images to post

  • args (Hash)

    additional named fields to post

Returns:

  • (Hash)

    if successful, the json data returned by DeepStack, nil otherwise

Raises:

  • (Net::HTTPClientException)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/deep_stack/deep_stack.rb', line 55

def api_post(path, *images, **args)
  uri = build_uri(path)
  args = @auth.merge(args)

  result = nil
  10.times do
    result = images ? post_files(uri, images.flatten, **args) : post(uri, args)
    break unless result.is_a?(Net::HTTPRedirection)

    uri.path = result['location']
  end
  raise Net::HTTPClientException, 'Too many redirections' if result.is_a?(Net::HTTPRedirection)

  process_result(result)
end

#closeObject

Close the HTTP connection to DeepStack server



74
75
76
# File 'lib/deep_stack/deep_stack.rb', line 74

def close
  @http.finish if @http&.started?
end