-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcapture_for_hdr.rb
85 lines (66 loc) · 2.33 KB
/
capture_for_hdr.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
require './lib/theta_initiator.rb'
require 'FileUtils'
require 'open3'
require 'optparse'
#Luminance HDR をインストール、luminance-hdr-cliのPath設定が必要です。
#動作環境 Win7/Mac Yosemite
ThetaInitiator.open do |initiator|
inputs = ARGV.getopts('','b:-2000,0,2000','t:mantiuk08')
brightness = inputs['b'].split(",")
brightness.map!(&:to_i)
tmo = inputs["t"]
current = Dir.pwd
brightness_num = brightness.length
t = Time.now
date = "#{t.year}-#{t.month}-#{t.day}-#{t.hour}#{t.min}#{t.sec}"
FileUtils.mkdir_p("./outputs/HDR-#{date}")
object_handles = Array.new(3)
file_path = Array.new(3)
osn = RbConfig::CONFIG['host_os']
os = osn =~ /mswin(?!ce)|mingw|cygwin|bccwin/ ? "win" : "other"
i = 0
for value in brightness
initiator.operation(:SetDevicePropValue,
[initiator.device_property_code(:ExposureBiasCompensation)],[value].pack('S').unpack('C*'))
response = initiator.operation(:GetDevicePropValue,
[initiator.device_property_code(:ExposureBiasCompensation)])
puts "ExposureBiasCompensation: #{response[:data].pack('C*').unpack('s')[0].inspect}"
initiator.operation :InitiateCapture, [0,0]
response = initiator.wait_event #InitiateCaptureが終わるまで待機
object_handles[i] = response[:parameters][0]
initiator.wait_event #object_handles=respose[:parameters][0]が終わるまで待機
i+=1
end
i=0
a=0
for value in brightness
puts "GetObject...#{i+1}/#{brightness_num}"
file_path[i] = "/outputs/HDR-#{date}/theta_pic_#{value}.jpg"
data_size = File.open(".#{file_path[i]}", "wb") do |f|
response = initiator.operation(:GetObject, [object_handles[i]]) do |data|
f.write data
a+=1
if a%100 == 0 then
print "."
end
end
puts""
puts "#{i+1}/#{brightness_num} Saved (data_size : #{response[:data_size]} byte)"
end
i+=1
end
i=0
input_file_path =""
for value in brightness
input_file_path += current.to_s + file_path[i].to_s + " "
i+=1
end
#Open3.capture 出力抑制のため
luminance = os == "win" ? "luminance-hdr-cli.exe" : "luminance-hdr-cli"
puts "Create HDR file..."
Open3.capture3 ("#{luminance} --tmo #{tmo} -o #{current}/outputs/HDR-#{date}/HDR.jpg #{input_file_path}")
puts "Finish"
puts "Create LDR file..."
Open3.capture3 ("#{luminance} -o #{current}/outputs/HDR-#{date}/LDR.jpg #{input_file_path}")
puts "Finish"
end