blob: c2a71fe6f0fe886e112c95fbf66bde4cd5ba4139 [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
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08004cc_library(
5 name = "get_gaussian_kernel",
6 hdrs = [
7 "get_gaussian_kernel.h",
8 ],
9)
10
11cc_test(
12 name = "get_gaussian_kernel_test",
13 srcs = [
14 "get_gaussian_kernel_test.cc",
15 ],
16 deps = [
17 ":get_gaussian_kernel",
18 "//aos/testing:googletest",
19 "//third_party:opencv",
20 "@com_github_google_glog//:glog",
21 ],
22)
23
Brian Silverman3fec6482020-01-19 17:56:20 -080024cc_binary(
25 name = "fast_gaussian_generator",
26 srcs = [
27 "fast_gaussian_generator.cc",
28 ],
Brian Silverman4b0bcaf2022-01-01 22:48:55 -080029 linkopts = [
30 "-lpthread",
31 "-ldl",
32 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080033 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -080034 deps = [
Brian Silverman4b0bcaf2022-01-01 22:48:55 -080035 ":get_gaussian_kernel",
Brian Silverman3fec6482020-01-19 17:56:20 -080036 "//third_party:halide",
37 "//third_party:halide_gengen",
Brian Silverman4b0bcaf2022-01-01 22:48:55 -080038 # This somehow brings in a zlib that libllvm needs?
39 # TODO(Brian): Remove this dependency, it's not really used.
Brian Silverman3fec6482020-01-19 17:56:20 -080040 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -080041 ],
42)
43
44py_binary(
45 name = "fast_gaussian_runner",
46 srcs = [
47 "fast_gaussian_runner.py",
48 ],
49 data = [
50 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080051 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080052 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080053 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080054 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080055 toolchains = [
56 "@bazel_tools//tools/cpp:current_cc_toolchain",
57 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080058 deps = [
59 "@bazel_tools//tools/python/runfiles",
60 ],
61)
62
63# Each element is [sigma, sigma_name, radius].
64# opencv's default width is calculated as:
65# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
66# Pulling that in helps a lot with making it faster (less data to read, and less
67# math to do), but if you make it too narrow SIFT quickly freaks out.
68sigmas = [
69 [
70 "1.2262734984654078",
71 "1p2",
72 "9",
73 ],
74 [
75 "1.5450077936447955",
76 "1p5",
77 "11",
78 ],
79 [
80 "1.9465878414647133",
81 "1p9",
82 "13",
83 ],
84 [
85 "2.4525469969308156",
86 "2p4",
87 "15",
88 ],
89 [
90 "3.0900155872895909",
91 "3p1",
92 "19",
93 ],
94 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
95 # all the redundant versions for other sizes, and maybe stop doing the one
96 # we don't actually use.
97 [
Brian Silverman950bffa2020-02-01 16:53:49 -080098 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -080099 "1p24",
100 "11",
101 ],
102 [
103 "1.5198683738708496",
104 "1p52",
105 "15",
106 ],
107]
108
109sizes = [
110 [
111 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -0800112 960,
Brian Silverman3fec6482020-01-19 17:56:20 -0800113 ],
114 [
115 640,
Brian Silverman950bffa2020-02-01 16:53:49 -0800116 480,
Brian Silverman3fec6482020-01-19 17:56:20 -0800117 ],
118 [
119 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800120 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800121 ],
122 [
123 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800124 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800125 ],
126 [
127 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800128 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800129 ],
130]
131
132fast_gaussian(sigmas, sizes)
133
Brian Silvermanf1196122020-01-16 00:41:54 -0800134cc_library(
135 name = "sift971",
136 srcs = [
137 "sift971.cc",
138 ],
139 hdrs = [
140 "sift971.h",
141 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800142 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800143 visibility = ["//visibility:public"],
144 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800145 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800146 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800147 "@com_github_google_glog//:glog",
148 ],
149)
150
151cc_library(
152 name = "fast_gaussian",
153 srcs = [
154 "fast_gaussian.cc",
155 ],
156 hdrs = [
157 "fast_gaussian.h",
158 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800159 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800160 deps = [
161 ":fast_gaussian_all",
162 "//third_party:halide_runtime",
163 "//third_party:opencv",
164 "@com_github_google_glog//:glog",
165 ],
166)
167
Brian Silvermane4664162020-02-15 15:27:46 -0800168cc_test(
169 name = "fast_gaussian_test",
170 srcs = [
171 "fast_gaussian_test.cc",
172 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800173 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800174 deps = [
175 ":fast_gaussian",
176 "//aos/testing:googletest",
177 "//third_party:opencv",
178 ],
179)
180
Brian Silverman3fec6482020-01-19 17:56:20 -0800181cc_binary(
182 name = "testing_sift",
183 srcs = [
184 "testing_sift.cc",
185 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800186 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800187 deps = [
188 ":fast_gaussian",
189 "//aos:init",
190 "//aos/time",
191 "//third_party:opencv",
192 "//y2020/vision/sift:sift971",
193 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800194 ],
195)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800196
197flatbuffer_py_library(
198 name = "sift_fbs_python",
199 srcs = [
200 "sift.fbs",
201 "sift_training.fbs",
202 ],
203 namespace = "frc971.vision.sift",
204 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800205 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800206 "Feature",
207 "Match",
208 "ImageMatch",
209 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800210 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800211 "CameraPose",
212 "ImageMatchResult",
213 "TrainingImage",
214 "TrainingData",
215 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800216 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800217 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800218)
219
220flatbuffer_cc_library(
221 name = "sift_fbs",
222 srcs = ["sift.fbs"],
223 gen_reflections = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800224 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800225 visibility = ["//visibility:public"],
226)
227
Alex Perryd5e13572020-02-22 15:15:08 -0800228flatbuffer_ts_library(
229 name = "sift_ts_fbs",
230 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800231 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800232 visibility = ["//y2020:__subpackages__"],
233)
234
Brian Silvermanfac9b872020-02-05 20:07:38 -0800235flatbuffer_cc_library(
236 name = "sift_training_fbs",
237 srcs = ["sift_training.fbs"],
238 gen_reflections = True,
239 includes = [":sift_fbs_includes"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800240 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800241 visibility = ["//visibility:public"],
242)
Brian Silverman967e5df2020-02-09 16:43:34 -0800243
244py_binary(
245 name = "demo_sift_training",
246 srcs = ["demo_sift_training.py"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800247 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800248 deps = [
249 ":sift_fbs_python",
250 "@opencv_contrib_nonfree_amd64//:python_opencv",
251 ],
252)
253
254genrule(
255 name = "run_demo_sift_training",
256 srcs = [
257 "images/demo/FRC-Image4-cleaned.png",
258 ],
259 outs = [
260 "demo_sift.h",
261 ],
262 cmd = " ".join([
263 "$(location :demo_sift_training)",
264 "$(location images/demo/FRC-Image4-cleaned.png)",
265 "$(location demo_sift.h)",
266 ]),
Philipp Schraderdada1072020-11-24 11:34:46 -0800267 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800268 tools = [
269 ":demo_sift_training",
270 ],
271)
272
273cc_library(
274 name = "demo_sift",
275 hdrs = [
276 "demo_sift.h",
277 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800278 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800279 visibility = ["//visibility:public"],
280)