-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.lua
65 lines (52 loc) · 1.5 KB
/
init.lua
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
require('torch')
local ffi = require('ffi')
ffi.cdef[[
void gSLICr_init(int x, int y, int no_segs, int spixel_size,
int coh_weight, int no_iters, int color_space,
int seg_method, bool do_enforce_connectivity);
void gSLICr_feed(uint8_t *input);
void gSLICr_process();
void gSLICr_get_seg(float *output);
void gSLICr_retrieve(uint8_t *output);
]]
local gSLICr = {
C = ffi.load(package.searchpath('libgSLICr', package.cpath)),
}
local COLOR_SPACE = {
CIELAB = 0,
XYZ = 1,
RGB = 2,
}
local SEG_METHOD = {
GIVEN_NUM = 0,
GIVEN_SIZE = 1,
}
function gSLICr.init(arg)
local arg = arg or {}
local x = arg.x or 640
local y = arg.y or 480
local no_segs = arg.no_segs or 2000
local spixel_size = arg.spixel_size or 16
local coh_weight = arg.coh_weight or 0.6
local no_iters = arg.no_iters or 5
local color_space = arg.color_space or COLOR_SPACE.XYZ
local seg_method = arg.seg_method or SEG_METHOD.GIVEN_SIZE
local do_enforce_connectivity = arg.do_enforce_connectivity or true
gSLICr.C['gSLICr_init'](
x, y, no_segs, spixel_size, coh_weight, no_iters,
color_space, seg_method, do_enforce_connectivity
)
end
function gSLICr.feed(input)
gSLICr.C['gSLICr_feed'](torch.data(input))
end
function gSLICr.process()
gSLICr.C['gSLICr_process']()
end
function gSLICr.get_seg(output)
gSLICr.C['gSLICr_get_seg'](torch.data(output))
end
function gSLICr.retrieve(output)
gSLICr.C['gSLICr_retrieve'](torch.data(output))
end
return gSLICr