blob: 8b420ea92c36496fbe001e684c7004819e799f68 [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",
Austin Schuh94dbdf32024-04-11 22:51:09 -070037 "@clang_amd64_deps//:all",
Tyler Chatow6eda82c2022-03-27 22:37:38 -070038 "@deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo//file",
Brian Silvermanc0309a02022-01-01 23:57:03 -080039 "@halide_k8//:build_files",
40 "@llvm_toolchain//:all-components-x86_64-linux",
Brian Silverman3fec6482020-01-19 17:56:20 -080041 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080042 deps = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080043 "@bazel_tools//tools/bash/runfiles",
44 ],
45)
46
47genrule(
48 name = "run_fast_gaussian_halide_generator",
49 outs = [
50 "fast_gaussian_generator",
51 ],
52 cmd = "$(location :fast_gaussian_halide_generator) $@",
53 tools = [
54 ":fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080055 ],
56)
57
58py_binary(
59 name = "fast_gaussian_runner",
60 srcs = [
61 "fast_gaussian_runner.py",
62 ],
63 data = [
64 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080065 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080066 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080067 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080068 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080069 toolchains = [
70 "@bazel_tools//tools/cpp:current_cc_toolchain",
71 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080072 deps = [
73 "@bazel_tools//tools/python/runfiles",
74 ],
75)
76
77# Each element is [sigma, sigma_name, radius].
78# opencv's default width is calculated as:
79# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
80# Pulling that in helps a lot with making it faster (less data to read, and less
81# math to do), but if you make it too narrow SIFT quickly freaks out.
82sigmas = [
83 [
84 "1.2262734984654078",
85 "1p2",
86 "9",
87 ],
88 [
89 "1.5450077936447955",
90 "1p5",
91 "11",
92 ],
93 [
94 "1.9465878414647133",
95 "1p9",
96 "13",
97 ],
98 [
99 "2.4525469969308156",
100 "2p4",
101 "15",
102 ],
103 [
104 "3.0900155872895909",
105 "3p1",
106 "19",
107 ],
108 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
109 # all the redundant versions for other sizes, and maybe stop doing the one
110 # we don't actually use.
111 [
Brian Silverman950bffa2020-02-01 16:53:49 -0800112 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -0800113 "1p24",
114 "11",
115 ],
116 [
117 "1.5198683738708496",
118 "1p52",
119 "15",
120 ],
121]
122
123sizes = [
124 [
125 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -0800126 960,
Brian Silverman3fec6482020-01-19 17:56:20 -0800127 ],
128 [
129 640,
Brian Silverman950bffa2020-02-01 16:53:49 -0800130 480,
Brian Silverman3fec6482020-01-19 17:56:20 -0800131 ],
132 [
133 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800134 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800135 ],
136 [
137 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800138 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800139 ],
140 [
141 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800142 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800143 ],
144]
145
146fast_gaussian(sigmas, sizes)
147
Brian Silvermanf1196122020-01-16 00:41:54 -0800148cc_library(
149 name = "sift971",
150 srcs = [
151 "sift971.cc",
152 ],
153 hdrs = [
154 "sift971.h",
155 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800156 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800157 visibility = ["//visibility:public"],
158 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800159 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800160 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800161 "@com_github_google_glog//:glog",
162 ],
163)
164
165cc_library(
166 name = "fast_gaussian",
167 srcs = [
168 "fast_gaussian.cc",
169 ],
170 hdrs = [
171 "fast_gaussian.h",
172 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800173 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800174 deps = [
175 ":fast_gaussian_all",
176 "//third_party:halide_runtime",
177 "//third_party:opencv",
178 "@com_github_google_glog//:glog",
179 ],
180)
181
Brian Silvermane4664162020-02-15 15:27:46 -0800182cc_test(
183 name = "fast_gaussian_test",
184 srcs = [
185 "fast_gaussian_test.cc",
186 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800187 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800188 deps = [
189 ":fast_gaussian",
190 "//aos/testing:googletest",
191 "//third_party:opencv",
192 ],
193)
194
Brian Silverman3fec6482020-01-19 17:56:20 -0800195cc_binary(
196 name = "testing_sift",
197 srcs = [
198 "testing_sift.cc",
199 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800200 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800201 deps = [
202 ":fast_gaussian",
203 "//aos:init",
204 "//aos/time",
205 "//third_party:opencv",
206 "//y2020/vision/sift:sift971",
207 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800208 ],
209)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800210
211flatbuffer_py_library(
212 name = "sift_fbs_python",
213 srcs = [
214 "sift.fbs",
215 "sift_training.fbs",
216 ],
217 namespace = "frc971.vision.sift",
218 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800219 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800220 "Feature",
221 "Match",
222 "ImageMatch",
223 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800224 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800225 "CameraPose",
226 "ImageMatchResult",
227 "TrainingImage",
228 "TrainingData",
229 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800230 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800231 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800232)
233
James Kuszmaulf01da392023-12-14 11:22:14 -0800234static_flatbuffer(
Brian Silvermanfac9b872020-02-05 20:07:38 -0800235 name = "sift_fbs",
236 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800237 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800238 visibility = ["//visibility:public"],
239)
240
Alex Perryd5e13572020-02-22 15:15:08 -0800241flatbuffer_ts_library(
242 name = "sift_ts_fbs",
243 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800244 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800245 visibility = ["//y2020:__subpackages__"],
246)
247
James Kuszmaulf01da392023-12-14 11:22:14 -0800248static_flatbuffer(
Brian Silvermanfac9b872020-02-05 20:07:38 -0800249 name = "sift_training_fbs",
250 srcs = ["sift_training.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800251 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800252 visibility = ["//visibility:public"],
James Kuszmaulf01da392023-12-14 11:22:14 -0800253 deps = [":sift_fbs"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800254)
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)