15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/microsoft_computer_vision/command_builder.rb', line 15
def run
program :name, 'mscv'
program :version, MicrosoftComputerVision::VERSION
program :description, 'Microsoft Computer Vision API for cli'
command 'analyze' do |c|
c.syntax = 'mscv analyze /path/to/image'
c.description = 'Microsoft Computer Vision API Analyze'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.option '--visual_features STRING', String, 'visualFeatures param'
c.option '--details STRING', String, 'details param'
c.action do |args, options|
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).analyze(args.first, {
visual_features: options.visual_features,
details: options.details
})
puts result.body
end
end
command 'describe' do |c|
c.syntax = 'mscv describe /path/to/image'
c.description = 'Microsoft Computer Vision API Describe'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.option '--max_candidates STRING', String, 'maxCandidates param'
c.action do |args, options|
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).describe(args.first, {
max_candidates: options.max_candidates
})
puts result.body
end
end
command 'thumbnail' do |c|
c.syntax = 'mscv thumbnail /path/to/image'
c.description = 'Microsoft Computer Vision API Get Thumbnail'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.option '--output STRING', String, 'Output thumbnail path'
c.option '--width INTEGER', Integer, 'width param'
c.option '--height INTEGER', Integer, 'height param'
c.option '--smart_cropping BOOLEAN', 'smartCropping param'
c.action do |args, options|
options.default smart_cropping: true, output: './out.jpg'
if options.width.nil? || options.height.nil?
puts 'Please input width and height(--width, --height)'
exit
end
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).thumbnail(args.first, {
width: options.width,
height: options.height,
smart_cropping: options.smart_cropping
})
File.write options.output, result.body
puts "Created #{options.output}"
end
end
command 'ocr' do |c|
c.syntax = 'mscv ocr /path/to/image'
c.description = 'Microsoft Computer Vision API OCR'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.option '--language STRING', String, 'language param'
c.option '--detect_orientation', 'detectOrientation param'
c.action do |args, options|
options.default detect_orientation: true
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).ocr(args.first, {
language: options.language,
detect_orientation: options.detect_orientation
})
puts result.body
end
end
command 'model' do |c|
c.syntax = 'mscv model /path/to/image'
c.description = 'Microsoft Computer Vision API Domain Model'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.option '--model STRING', String, 'model param'
c.action do |args, options|
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).domain_model(args.first, {
model: options.model
})
puts result.body
end
end
command 'tag' do |c|
c.syntax = 'mscv tag /path/to/image'
c.description = 'Microsoft Computer Vision API Tag'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.action do |args, options|
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).tag(args.first)
puts result.body
end
end
command 'models' do |c|
c.syntax = 'mscv models'
c.description = 'Microsoft Computer Vision API Domain Models'
c.option '--subscription_key STRING', String, 'Microsoft Computer Vision API Subscription Key'
c.action do |args, options|
result = MicrosoftComputerVision::Client.new(get_subscription_key(options)).domain_models
puts result.body
end
end
run!
end
|