blob: 1920cce371e5e230c3c773a914aea8aed903af21 [file] [log] [blame]
Brian Silverman3fec6482020-01-19 17:56:20 -08001load(":fast_gaussian.bzl", "fast_gaussian")
Austin Schuha1d006e2022-09-14 21:50:42 -07002load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library")
3load("@com_github_google_flatbuffers//:typescript.bzl", "flatbuffer_ts_library")
Brian Silverman3fec6482020-01-19 17:56:20 -08004
Brian Silvermanc0309a02022-01-01 23:57:03 -08005# Note that this file is also used directly by :fast_gaussian_halide_generator,
6# without any dependencies added here.
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08007cc_library(
8 name = "get_gaussian_kernel",
9 hdrs = [
10 "get_gaussian_kernel.h",
11 ],
12)
13
14cc_test(
15 name = "get_gaussian_kernel_test",
16 srcs = [
17 "get_gaussian_kernel_test.cc",
18 ],
19 deps = [
20 ":get_gaussian_kernel",
21 "//aos/testing:googletest",
22 "//third_party:opencv",
23 "@com_github_google_glog//:glog",
24 ],
25)
26
Brian Silvermanc0309a02022-01-01 23:57:03 -080027sh_binary(
28 name = "fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080029 srcs = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080030 "fast_gaussian_halide_generator.sh",
31 ],
32 data = [
Brian Silverman3fec6482020-01-19 17:56:20 -080033 "fast_gaussian_generator.cc",
Brian Silvermanc0309a02022-01-01 23:57:03 -080034 "get_gaussian_kernel.h",
35 "@amd64_debian_sysroot//:sysroot_files",
Tyler Chatow6eda82c2022-03-27 22:37:38 -070036 "@deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo//file",
Brian Silvermanc0309a02022-01-01 23:57:03 -080037 "@halide_k8//:build_files",
38 "@llvm_toolchain//:all-components-x86_64-linux",
Brian Silverman3fec6482020-01-19 17:56:20 -080039 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080040 deps = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080041 "@bazel_tools//tools/bash/runfiles",
42 ],
43)
44
45genrule(
46 name = "run_fast_gaussian_halide_generator",
47 outs = [
48 "fast_gaussian_generator",
49 ],
50 cmd = "$(location :fast_gaussian_halide_generator) $@",
51 tools = [
52 ":fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080053 ],
54)
55
56py_binary(
57 name = "fast_gaussian_runner",
58 srcs = [
59 "fast_gaussian_runner.py",
60 ],
61 data = [
62 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080063 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080064 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080065 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080066 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080067 toolchains = [
68 "@bazel_tools//tools/cpp:current_cc_toolchain",
69 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080070 deps = [
71 "@bazel_tools//tools/python/runfiles",
72 ],
73)
74
75# Each element is [sigma, sigma_name, radius].
76# opencv's default width is calculated as:
77# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
78# Pulling that in helps a lot with making it faster (less data to read, and less
79# math to do), but if you make it too narrow SIFT quickly freaks out.
80sigmas = [
81 [
82 "1.2262734984654078",
83 "1p2",
84 "9",
85 ],
86 [
87 "1.5450077936447955",
88 "1p5",
89 "11",
90 ],
91 [
92 "1.9465878414647133",
93 "1p9",
94 "13",
95 ],
96 [
97 "2.4525469969308156",
98 "2p4",
99 "15",
100 ],
101 [
102 "3.0900155872895909",
103 "3p1",
104 "19",
105 ],
106 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
107 # all the redundant versions for other sizes, and maybe stop doing the one
108 # we don't actually use.
109 [
Brian Silverman950bffa2020-02-01 16:53:49 -0800110 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -0800111 "1p24",
112 "11",
113 ],
114 [
115 "1.5198683738708496",
116 "1p52",
117 "15",
118 ],
119]
120
121sizes = [
122 [
123 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -0800124 960,
Brian Silverman3fec6482020-01-19 17:56:20 -0800125 ],
126 [
127 640,
Brian Silverman950bffa2020-02-01 16:53:49 -0800128 480,
Brian Silverman3fec6482020-01-19 17:56:20 -0800129 ],
130 [
131 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800132 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800133 ],
134 [
135 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800136 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800137 ],
138 [
139 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800140 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800141 ],
142]
143
144fast_gaussian(sigmas, sizes)
145
Brian Silvermanf1196122020-01-16 00:41:54 -0800146cc_library(
147 name = "sift971",
148 srcs = [
149 "sift971.cc",
150 ],
151 hdrs = [
152 "sift971.h",
153 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800154 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800155 visibility = ["//visibility:public"],
156 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800157 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800158 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800159 "@com_github_google_glog//:glog",
160 ],
161)
162
163cc_library(
164 name = "fast_gaussian",
165 srcs = [
166 "fast_gaussian.cc",
167 ],
168 hdrs = [
169 "fast_gaussian.h",
170 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800171 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800172 deps = [
173 ":fast_gaussian_all",
174 "//third_party:halide_runtime",
175 "//third_party:opencv",
176 "@com_github_google_glog//:glog",
177 ],
178)
179
Brian Silvermane4664162020-02-15 15:27:46 -0800180cc_test(
181 name = "fast_gaussian_test",
182 srcs = [
183 "fast_gaussian_test.cc",
184 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800185 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800186 deps = [
187 ":fast_gaussian",
188 "//aos/testing:googletest",
189 "//third_party:opencv",
190 ],
191)
192
Brian Silverman3fec6482020-01-19 17:56:20 -0800193cc_binary(
194 name = "testing_sift",
195 srcs = [
196 "testing_sift.cc",
197 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800198 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800199 deps = [
200 ":fast_gaussian",
201 "//aos:init",
202 "//aos/time",
203 "//third_party:opencv",
204 "//y2020/vision/sift:sift971",
205 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800206 ],
207)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800208
209flatbuffer_py_library(
210 name = "sift_fbs_python",
211 srcs = [
212 "sift.fbs",
213 "sift_training.fbs",
214 ],
215 namespace = "frc971.vision.sift",
216 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800217 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800218 "Feature",
219 "Match",
220 "ImageMatch",
221 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800222 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800223 "CameraPose",
224 "ImageMatchResult",
225 "TrainingImage",
226 "TrainingData",
227 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800228 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800229 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800230)
231
232flatbuffer_cc_library(
233 name = "sift_fbs",
234 srcs = ["sift.fbs"],
235 gen_reflections = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800236 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800237 visibility = ["//visibility:public"],
238)
239
Alex Perryd5e13572020-02-22 15:15:08 -0800240flatbuffer_ts_library(
241 name = "sift_ts_fbs",
242 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800243 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800244 visibility = ["//y2020:__subpackages__"],
245)
246
Brian Silvermanfac9b872020-02-05 20:07:38 -0800247flatbuffer_cc_library(
248 name = "sift_training_fbs",
249 srcs = ["sift_training.fbs"],
250 gen_reflections = True,
251 includes = [":sift_fbs_includes"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800252 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800253 visibility = ["//visibility:public"],
254)
Brian Silverman967e5df2020-02-09 16:43:34 -0800255
256py_binary(
257 name = "demo_sift_training",
258 srcs = ["demo_sift_training.py"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800259 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800260 deps = [
261 ":sift_fbs_python",
Philipp Schraderebb658f2022-09-17 17:31:09 -0700262 "@pip//opencv_python",
Brian Silverman967e5df2020-02-09 16:43:34 -0800263 ],
264)
265
266genrule(
267 name = "run_demo_sift_training",
268 srcs = [
269 "images/demo/FRC-Image4-cleaned.png",
270 ],
271 outs = [
272 "demo_sift.h",
273 ],
274 cmd = " ".join([
275 "$(location :demo_sift_training)",
276 "$(location images/demo/FRC-Image4-cleaned.png)",
277 "$(location demo_sift.h)",
278 ]),
Philipp Schraderdada1072020-11-24 11:34:46 -0800279 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800280 tools = [
281 ":demo_sift_training",
282 ],
283)
284
285cc_library(
286 name = "demo_sift",
287 hdrs = [
288 "demo_sift.h",
289 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800290 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800291 visibility = ["//visibility:public"],
292)