blob: a7827b6234d4fcd8afa9a32cf730212b4920c2f1 [file] [log] [blame]
Brian Silverman3fec6482020-01-19 17:56:20 -08001load(":fast_gaussian.bzl", "fast_gaussian")
Alex Perryd5e13572020-02-22 15:15:08 -08002load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library", "flatbuffer_ts_library")
Brian Silverman3fec6482020-01-19 17:56:20 -08003
4cc_binary(
5 name = "fast_gaussian_generator",
6 srcs = [
7 "fast_gaussian_generator.cc",
8 ],
9 restricted_to = [
10 "//tools:k8",
11 "//tools:armhf-debian",
12 ],
13 deps = [
14 "//third_party:halide",
15 "//third_party:halide_gengen",
16 "//third_party:opencv",
17 "@com_github_google_glog//:glog",
18 ],
19)
20
21py_binary(
22 name = "fast_gaussian_runner",
23 srcs = [
24 "fast_gaussian_runner.py",
25 ],
26 data = [
27 ":fast_gaussian_generator",
28 # TODO(Brian): Replace this with something more fine-grained from the
29 # configuration fragment or something.
30 "//tools/cpp:toolchain",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080031 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080032 ],
33 default_python_version = "PY3",
34 main = "fast_gaussian_runner.py",
35 restricted_to = [
36 "//tools:k8",
37 "//tools:armhf-debian",
38 ],
39 srcs_version = "PY2AND3",
40 deps = [
41 "@bazel_tools//tools/python/runfiles",
42 ],
43)
44
45# Each element is [sigma, sigma_name, radius].
46# opencv's default width is calculated as:
47# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
48# Pulling that in helps a lot with making it faster (less data to read, and less
49# math to do), but if you make it too narrow SIFT quickly freaks out.
50sigmas = [
51 [
52 "1.2262734984654078",
53 "1p2",
54 "9",
55 ],
56 [
57 "1.5450077936447955",
58 "1p5",
59 "11",
60 ],
61 [
62 "1.9465878414647133",
63 "1p9",
64 "13",
65 ],
66 [
67 "2.4525469969308156",
68 "2p4",
69 "15",
70 ],
71 [
72 "3.0900155872895909",
73 "3p1",
74 "19",
75 ],
76 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
77 # all the redundant versions for other sizes, and maybe stop doing the one
78 # we don't actually use.
79 [
Brian Silverman950bffa2020-02-01 16:53:49 -080080 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -080081 "1p24",
82 "11",
83 ],
84 [
85 "1.5198683738708496",
86 "1p52",
87 "15",
88 ],
89]
90
91sizes = [
92 [
93 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -080094 960,
Brian Silverman3fec6482020-01-19 17:56:20 -080095 ],
96 [
97 640,
Brian Silverman950bffa2020-02-01 16:53:49 -080098 480,
Brian Silverman3fec6482020-01-19 17:56:20 -080099 ],
100 [
101 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800102 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800103 ],
104 [
105 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800106 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800107 ],
108 [
109 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800110 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800111 ],
112]
113
114fast_gaussian(sigmas, sizes)
115
Brian Silvermanf1196122020-01-16 00:41:54 -0800116cc_library(
117 name = "sift971",
118 srcs = [
119 "sift971.cc",
120 ],
121 hdrs = [
122 "sift971.h",
123 ],
124 restricted_to = [
125 "//tools:k8",
126 "//tools:armhf-debian",
127 ],
128 visibility = ["//visibility:public"],
129 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800130 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800131 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800132 "@com_github_google_glog//:glog",
133 ],
134)
135
136cc_library(
137 name = "fast_gaussian",
138 srcs = [
139 "fast_gaussian.cc",
140 ],
141 hdrs = [
142 "fast_gaussian.h",
143 ],
144 restricted_to = [
145 "//tools:k8",
146 "//tools:armhf-debian",
147 ],
148 deps = [
149 ":fast_gaussian_all",
150 "//third_party:halide_runtime",
151 "//third_party:opencv",
152 "@com_github_google_glog//:glog",
153 ],
154)
155
Brian Silvermane4664162020-02-15 15:27:46 -0800156cc_test(
157 name = "fast_gaussian_test",
158 srcs = [
159 "fast_gaussian_test.cc",
160 ],
161 restricted_to = [
162 "//tools:k8",
163 "//tools:armhf-debian",
164 ],
165 deps = [
166 ":fast_gaussian",
167 "//aos/testing:googletest",
168 "//third_party:opencv",
169 ],
170)
171
Brian Silverman3fec6482020-01-19 17:56:20 -0800172cc_binary(
173 name = "testing_sift",
174 srcs = [
175 "testing_sift.cc",
176 ],
177 restricted_to = [
178 "//tools:k8",
179 "//tools:armhf-debian",
180 ],
181 deps = [
182 ":fast_gaussian",
183 "//aos:init",
184 "//aos/time",
185 "//third_party:opencv",
186 "//y2020/vision/sift:sift971",
187 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800188 ],
189)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800190
191flatbuffer_py_library(
192 name = "sift_fbs_python",
193 srcs = [
194 "sift.fbs",
195 "sift_training.fbs",
196 ],
197 namespace = "frc971.vision.sift",
198 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800199 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800200 "Feature",
201 "Match",
202 "ImageMatch",
203 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800204 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800205 "CameraPose",
206 "ImageMatchResult",
207 "TrainingImage",
208 "TrainingData",
209 ],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800210 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800211)
212
213flatbuffer_cc_library(
214 name = "sift_fbs",
215 srcs = ["sift.fbs"],
216 gen_reflections = True,
217 visibility = ["//visibility:public"],
218)
219
Alex Perryd5e13572020-02-22 15:15:08 -0800220flatbuffer_ts_library(
221 name = "sift_ts_fbs",
222 srcs = ["sift.fbs"],
223 visibility = ["//y2020:__subpackages__"],
224)
225
Brian Silvermanfac9b872020-02-05 20:07:38 -0800226flatbuffer_cc_library(
227 name = "sift_training_fbs",
228 srcs = ["sift_training.fbs"],
229 gen_reflections = True,
230 includes = [":sift_fbs_includes"],
231 visibility = ["//visibility:public"],
232)
Brian Silverman967e5df2020-02-09 16:43:34 -0800233
234py_binary(
235 name = "demo_sift_training",
236 srcs = ["demo_sift_training.py"],
237 default_python_version = "PY3",
238 srcs_version = "PY2AND3",
239 deps = [
240 ":sift_fbs_python",
241 "@opencv_contrib_nonfree_amd64//:python_opencv",
242 ],
243)
244
245genrule(
246 name = "run_demo_sift_training",
247 srcs = [
248 "images/demo/FRC-Image4-cleaned.png",
249 ],
250 outs = [
251 "demo_sift.h",
252 ],
253 cmd = " ".join([
254 "$(location :demo_sift_training)",
255 "$(location images/demo/FRC-Image4-cleaned.png)",
256 "$(location demo_sift.h)",
257 ]),
258 tools = [
259 ":demo_sift_training",
260 ],
261)
262
263cc_library(
264 name = "demo_sift",
265 hdrs = [
266 "demo_sift.h",
267 ],
268 visibility = ["//visibility:public"],
269)