blob: feecb62cad25e5bd47c5660eec4b6383942e9b38 [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 Silvermanc0309a02022-01-01 23:57:03 -08004# Note that this file is also used directly by :fast_gaussian_halide_generator,
5# without any dependencies added here.
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08006cc_library(
7 name = "get_gaussian_kernel",
8 hdrs = [
9 "get_gaussian_kernel.h",
10 ],
11)
12
13cc_test(
14 name = "get_gaussian_kernel_test",
15 srcs = [
16 "get_gaussian_kernel_test.cc",
17 ],
18 deps = [
19 ":get_gaussian_kernel",
20 "//aos/testing:googletest",
21 "//third_party:opencv",
22 "@com_github_google_glog//:glog",
23 ],
24)
25
Brian Silvermanc0309a02022-01-01 23:57:03 -080026sh_binary(
27 name = "fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080028 srcs = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080029 "fast_gaussian_halide_generator.sh",
30 ],
31 data = [
Brian Silverman3fec6482020-01-19 17:56:20 -080032 "fast_gaussian_generator.cc",
Brian Silvermanc0309a02022-01-01 23:57:03 -080033 "get_gaussian_kernel.h",
34 "@amd64_debian_sysroot//:sysroot_files",
Tyler Chatow6eda82c2022-03-27 22:37:38 -070035 "@deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo//file",
Brian Silvermanc0309a02022-01-01 23:57:03 -080036 "@halide_k8//:build_files",
37 "@llvm_toolchain//:all-components-x86_64-linux",
Brian Silverman3fec6482020-01-19 17:56:20 -080038 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080039 deps = [
Brian Silvermanc0309a02022-01-01 23:57:03 -080040 "@bazel_tools//tools/bash/runfiles",
41 ],
42)
43
44genrule(
45 name = "run_fast_gaussian_halide_generator",
46 outs = [
47 "fast_gaussian_generator",
48 ],
49 cmd = "$(location :fast_gaussian_halide_generator) $@",
50 tools = [
51 ":fast_gaussian_halide_generator",
Brian Silverman3fec6482020-01-19 17:56:20 -080052 ],
53)
54
55py_binary(
56 name = "fast_gaussian_runner",
57 srcs = [
58 "fast_gaussian_runner.py",
59 ],
60 data = [
61 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080062 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080063 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080064 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080065 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080066 toolchains = [
67 "@bazel_tools//tools/cpp:current_cc_toolchain",
68 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080069 deps = [
70 "@bazel_tools//tools/python/runfiles",
71 ],
72)
73
74# Each element is [sigma, sigma_name, radius].
75# opencv's default width is calculated as:
76# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
77# Pulling that in helps a lot with making it faster (less data to read, and less
78# math to do), but if you make it too narrow SIFT quickly freaks out.
79sigmas = [
80 [
81 "1.2262734984654078",
82 "1p2",
83 "9",
84 ],
85 [
86 "1.5450077936447955",
87 "1p5",
88 "11",
89 ],
90 [
91 "1.9465878414647133",
92 "1p9",
93 "13",
94 ],
95 [
96 "2.4525469969308156",
97 "2p4",
98 "15",
99 ],
100 [
101 "3.0900155872895909",
102 "3p1",
103 "19",
104 ],
105 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
106 # all the redundant versions for other sizes, and maybe stop doing the one
107 # we don't actually use.
108 [
Brian Silverman950bffa2020-02-01 16:53:49 -0800109 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -0800110 "1p24",
111 "11",
112 ],
113 [
114 "1.5198683738708496",
115 "1p52",
116 "15",
117 ],
118]
119
120sizes = [
121 [
122 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -0800123 960,
Brian Silverman3fec6482020-01-19 17:56:20 -0800124 ],
125 [
126 640,
Brian Silverman950bffa2020-02-01 16:53:49 -0800127 480,
Brian Silverman3fec6482020-01-19 17:56:20 -0800128 ],
129 [
130 320,
Brian Silverman950bffa2020-02-01 16:53:49 -0800131 240,
Brian Silverman3fec6482020-01-19 17:56:20 -0800132 ],
133 [
134 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800135 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800136 ],
137 [
138 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800139 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800140 ],
141]
142
143fast_gaussian(sigmas, sizes)
144
Brian Silvermanf1196122020-01-16 00:41:54 -0800145cc_library(
146 name = "sift971",
147 srcs = [
148 "sift971.cc",
149 ],
150 hdrs = [
151 "sift971.h",
152 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800153 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800154 visibility = ["//visibility:public"],
155 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800156 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800157 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800158 "@com_github_google_glog//:glog",
159 ],
160)
161
162cc_library(
163 name = "fast_gaussian",
164 srcs = [
165 "fast_gaussian.cc",
166 ],
167 hdrs = [
168 "fast_gaussian.h",
169 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800170 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800171 deps = [
172 ":fast_gaussian_all",
173 "//third_party:halide_runtime",
174 "//third_party:opencv",
175 "@com_github_google_glog//:glog",
176 ],
177)
178
Brian Silvermane4664162020-02-15 15:27:46 -0800179cc_test(
180 name = "fast_gaussian_test",
181 srcs = [
182 "fast_gaussian_test.cc",
183 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800184 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800185 deps = [
186 ":fast_gaussian",
187 "//aos/testing:googletest",
188 "//third_party:opencv",
189 ],
190)
191
Brian Silverman3fec6482020-01-19 17:56:20 -0800192cc_binary(
193 name = "testing_sift",
194 srcs = [
195 "testing_sift.cc",
196 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800197 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800198 deps = [
199 ":fast_gaussian",
200 "//aos:init",
201 "//aos/time",
202 "//third_party:opencv",
203 "//y2020/vision/sift:sift971",
204 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800205 ],
206)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800207
208flatbuffer_py_library(
209 name = "sift_fbs_python",
210 srcs = [
211 "sift.fbs",
212 "sift_training.fbs",
213 ],
214 namespace = "frc971.vision.sift",
215 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800216 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800217 "Feature",
218 "Match",
219 "ImageMatch",
220 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800221 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800222 "CameraPose",
223 "ImageMatchResult",
224 "TrainingImage",
225 "TrainingData",
226 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800227 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800228 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800229)
230
231flatbuffer_cc_library(
232 name = "sift_fbs",
233 srcs = ["sift.fbs"],
234 gen_reflections = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800235 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800236 visibility = ["//visibility:public"],
237)
238
Alex Perryd5e13572020-02-22 15:15:08 -0800239flatbuffer_ts_library(
240 name = "sift_ts_fbs",
241 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800242 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800243 visibility = ["//y2020:__subpackages__"],
244)
245
Brian Silvermanfac9b872020-02-05 20:07:38 -0800246flatbuffer_cc_library(
247 name = "sift_training_fbs",
248 srcs = ["sift_training.fbs"],
249 gen_reflections = True,
250 includes = [":sift_fbs_includes"],
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"],
253)
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",
261 "@opencv_contrib_nonfree_amd64//:python_opencv",
262 ],
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)