blob: 1d4083e3efb5ae400108f9ed108105440cd5ab35 [file] [log] [blame]
James Kuszmaulf01da392023-12-14 11:22:14 -08001load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
Brian Silverman3fec6482020-01-19 17:56:20 -08002load(":fast_gaussian.bzl", "fast_gaussian")
James Kuszmaulf01da392023-12-14 11:22:14 -08003load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_py_library")
Austin Schuha1d006e2022-09-14 21:50:42 -07004load("@com_github_google_flatbuffers//:typescript.bzl", "flatbuffer_ts_library")
Brian Silverman3fec6482020-01-19 17:56:20 -08005
Brian Silvermanc0309a02022-01-01 23:57:03 -08006# Note that this file is also used directly by :fast_gaussian_halide_generator,
7# without any dependencies added here.
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08008cc_library(
9 name = "get_gaussian_kernel",
10 hdrs = [
11 "get_gaussian_kernel.h",
12 ],
13)
14
15cc_test(
16 name = "get_gaussian_kernel_test",
17 srcs = [
18 "get_gaussian_kernel_test.cc",
19 ],
20 deps = [
21 ":get_gaussian_kernel",
22 "//aos/testing:googletest",
23 "//third_party:opencv",
24 "@com_github_google_glog//:glog",
25 ],
26)
27
Brian Silvermanc0309a02022-01-01 23:57:03 -080028sh_binary(
29 name = "fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080030 srcs = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080031 "fast_gaussian_halide_generator.sh",
32 ],
33 data = [
Brian Silverman3fec6482020-01-19 17:56:20 -080034 "fast_gaussian_generator.cc",
Brian Silvermanc0309a02022-01-01 23:57:03 -080035 "get_gaussian_kernel.h",
36 "@amd64_debian_sysroot//:sysroot_files",
Tyler Chatow6eda82c2022-03-27 22:37:38 -070037 "@deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo//file",
Brian Silvermanc0309a02022-01-01 23:57:03 -080038 "@halide_k8//:build_files",
39 "@llvm_toolchain//:all-components-x86_64-linux",
Brian Silverman3fec6482020-01-19 17:56:20 -080040 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080041 deps = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080042 "@bazel_tools//tools/bash/runfiles",
43 ],
44)
45
46genrule(
47 name = "run_fast_gaussian_halide_generator",
48 outs = [
49 "fast_gaussian_generator",
50 ],
51 cmd = "$(location :fast_gaussian_halide_generator) $@",
52 tools = [
53 ":fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080054 ],
55)
56
57py_binary(
58 name = "fast_gaussian_runner",
59 srcs = [
60 "fast_gaussian_runner.py",
61 ],
62 data = [
63 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080064 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080065 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080066 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080067 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080068 toolchains = [
69 "@bazel_tools//tools/cpp:current_cc_toolchain",
70 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080071 deps = [
72 "@bazel_tools//tools/python/runfiles",
73 ],
74)
75
76# Each element is [sigma, sigma_name, radius].
77# opencv's default width is calculated as:
78# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
79# Pulling that in helps a lot with making it faster (less data to read, and less
80# math to do), but if you make it too narrow SIFT quickly freaks out.
81sigmas = [
82 [
83 "1.2262734984654078",
84 "1p2",
85 "9",
86 ],
87 [
88 "1.5450077936447955",
89 "1p5",
90 "11",
91 ],
92 [
93 "1.9465878414647133",
94 "1p9",
95 "13",
96 ],
97 [
98 "2.4525469969308156",
99 "2p4",
100 "15",
101 ],
102 [
103 "3.0900155872895909",
104 "3p1",
105 "19",
106 ],
107 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
108 # all the redundant versions for other sizes, and maybe stop doing the one
109 # we don't actually use.
110 [
Brian Silverman950bffa2020-02-01 16:53:49 -0800111 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -0800112 "1p24",
113 "11",
114 ],
115 [
116 "1.5198683738708496",
117 "1p52",
118 "15",
119 ],
120]
121
122sizes = [
123 [
124 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -0800125 960,
Brian Silverman3fec6482020-01-19 17:56:20 -0800126 ],
127 [
128 640,
Brian Silverman950bffa2020-02-01 16:53:49 -0800129 480,
Brian Silverman3fec6482020-01-19 17:56:20 -0800130 ],
131 [
132 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800133 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800134 ],
135 [
136 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800137 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800138 ],
139 [
140 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800141 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800142 ],
143]
144
145fast_gaussian(sigmas, sizes)
146
Brian Silvermanf1196122020-01-16 00:41:54 -0800147cc_library(
148 name = "sift971",
149 srcs = [
150 "sift971.cc",
151 ],
152 hdrs = [
153 "sift971.h",
154 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800155 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800156 visibility = ["//visibility:public"],
157 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800158 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800159 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800160 "@com_github_google_glog//:glog",
161 ],
162)
163
164cc_library(
165 name = "fast_gaussian",
166 srcs = [
167 "fast_gaussian.cc",
168 ],
169 hdrs = [
170 "fast_gaussian.h",
171 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800172 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800173 deps = [
174 ":fast_gaussian_all",
175 "//third_party:halide_runtime",
176 "//third_party:opencv",
177 "@com_github_google_glog//:glog",
178 ],
179)
180
Brian Silvermane4664162020-02-15 15:27:46 -0800181cc_test(
182 name = "fast_gaussian_test",
183 srcs = [
184 "fast_gaussian_test.cc",
185 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800186 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800187 deps = [
188 ":fast_gaussian",
189 "//aos/testing:googletest",
190 "//third_party:opencv",
191 ],
192)
193
Brian Silverman3fec6482020-01-19 17:56:20 -0800194cc_binary(
195 name = "testing_sift",
196 srcs = [
197 "testing_sift.cc",
198 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800199 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800200 deps = [
201 ":fast_gaussian",
202 "//aos:init",
203 "//aos/time",
204 "//third_party:opencv",
205 "//y2020/vision/sift:sift971",
206 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800207 ],
208)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800209
210flatbuffer_py_library(
211 name = "sift_fbs_python",
212 srcs = [
213 "sift.fbs",
214 "sift_training.fbs",
215 ],
216 namespace = "frc971.vision.sift",
217 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800218 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800219 "Feature",
220 "Match",
221 "ImageMatch",
222 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800223 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800224 "CameraPose",
225 "ImageMatchResult",
226 "TrainingImage",
227 "TrainingData",
228 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800229 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800230 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800231)
232
James Kuszmaulf01da392023-12-14 11:22:14 -0800233static_flatbuffer(
Brian Silvermanfac9b872020-02-05 20:07:38 -0800234 name = "sift_fbs",
235 srcs = ["sift.fbs"],
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
James Kuszmaulf01da392023-12-14 11:22:14 -0800247static_flatbuffer(
Brian Silvermanfac9b872020-02-05 20:07:38 -0800248 name = "sift_training_fbs",
249 srcs = ["sift_training.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800250 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800251 visibility = ["//visibility:public"],
James Kuszmaulf01da392023-12-14 11:22:14 -0800252 deps = [":sift_fbs"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800253)
Brian Silverman967e5df2020-02-09 16:43:34 -0800254
255py_binary(
256 name = "demo_sift_training",
257 srcs = ["demo_sift_training.py"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800258 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800259 deps = [
260 ":sift_fbs_python",
Philipp Schraderebb658f2022-09-17 17:31:09 -0700261 "@pip//opencv_python",
Brian Silverman967e5df2020-02-09 16:43:34 -0800262 ],
263)
264
265genrule(
266 name = "run_demo_sift_training",
267 srcs = [
268 "images/demo/FRC-Image4-cleaned.png",
269 ],
270 outs = [
271 "demo_sift.h",
272 ],
273 cmd = " ".join([
274 "$(location :demo_sift_training)",
275 "$(location images/demo/FRC-Image4-cleaned.png)",
276 "$(location 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 tools = [
280 ":demo_sift_training",
281 ],
282)
283
284cc_library(
285 name = "demo_sift",
286 hdrs = [
287 "demo_sift.h",
288 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800289 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800290 visibility = ["//visibility:public"],
291)