blob: 4a0dcfbd29765a4a628c8c4cbb16993aeda2d0d0 [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
4cc_binary(
5 name = "fast_gaussian_generator",
6 srcs = [
7 "fast_gaussian_generator.cc",
8 ],
Philipp Schraderdada1072020-11-24 11:34:46 -08009 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -080010 deps = [
11 "//third_party:halide",
12 "//third_party:halide_gengen",
13 "//third_party:opencv",
14 "@com_github_google_glog//:glog",
15 ],
16)
17
18py_binary(
19 name = "fast_gaussian_runner",
20 srcs = [
21 "fast_gaussian_runner.py",
22 ],
23 data = [
24 ":fast_gaussian_generator",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -080025 "@amd64_debian_sysroot//:sysroot_files",
Brian Silverman3fec6482020-01-19 17:56:20 -080026 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080027 toolchains = [
28 "@bazel_tools//tools/cpp:current_cc_toolchain",
Brian Silverman3fec6482020-01-19 17:56:20 -080029 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080030 main = "fast_gaussian_runner.py",
31 python_version = "PY3",
Brian Silverman3fec6482020-01-19 17:56:20 -080032 srcs_version = "PY2AND3",
Philipp Schraderdada1072020-11-24 11:34:46 -080033 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -080034 deps = [
35 "@bazel_tools//tools/python/runfiles",
36 ],
37)
38
39# Each element is [sigma, sigma_name, radius].
40# opencv's default width is calculated as:
41# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
42# Pulling that in helps a lot with making it faster (less data to read, and less
43# math to do), but if you make it too narrow SIFT quickly freaks out.
44sigmas = [
45 [
46 "1.2262734984654078",
47 "1p2",
48 "9",
49 ],
50 [
51 "1.5450077936447955",
52 "1p5",
53 "11",
54 ],
55 [
56 "1.9465878414647133",
57 "1p9",
58 "13",
59 ],
60 [
61 "2.4525469969308156",
62 "2p4",
63 "15",
64 ],
65 [
66 "3.0900155872895909",
67 "3p1",
68 "19",
69 ],
70 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
71 # all the redundant versions for other sizes, and maybe stop doing the one
72 # we don't actually use.
73 [
Brian Silverman950bffa2020-02-01 16:53:49 -080074 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -080075 "1p24",
76 "11",
77 ],
78 [
79 "1.5198683738708496",
80 "1p52",
81 "15",
82 ],
83]
84
85sizes = [
86 [
87 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -080088 960,
Brian Silverman3fec6482020-01-19 17:56:20 -080089 ],
90 [
91 640,
Brian Silverman950bffa2020-02-01 16:53:49 -080092 480,
Brian Silverman3fec6482020-01-19 17:56:20 -080093 ],
94 [
95 320,
Brian Silverman950bffa2020-02-01 16:53:49 -080096 240,
Brian Silverman3fec6482020-01-19 17:56:20 -080097 ],
98 [
99 160,
Brian Silverman950bffa2020-02-01 16:53:49 -0800100 120,
Brian Silverman3fec6482020-01-19 17:56:20 -0800101 ],
102 [
103 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800104 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800105 ],
106]
107
108fast_gaussian(sigmas, sizes)
109
Brian Silvermanf1196122020-01-16 00:41:54 -0800110cc_library(
111 name = "sift971",
112 srcs = [
113 "sift971.cc",
114 ],
115 hdrs = [
116 "sift971.h",
117 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800118 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800119 visibility = ["//visibility:public"],
120 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800121 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800122 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800123 "@com_github_google_glog//:glog",
124 ],
125)
126
127cc_library(
128 name = "fast_gaussian",
129 srcs = [
130 "fast_gaussian.cc",
131 ],
132 hdrs = [
133 "fast_gaussian.h",
134 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800135 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800136 deps = [
137 ":fast_gaussian_all",
138 "//third_party:halide_runtime",
139 "//third_party:opencv",
140 "@com_github_google_glog//:glog",
141 ],
142)
143
Brian Silvermane4664162020-02-15 15:27:46 -0800144cc_test(
145 name = "fast_gaussian_test",
146 srcs = [
147 "fast_gaussian_test.cc",
148 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800149 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800150 deps = [
151 ":fast_gaussian",
152 "//aos/testing:googletest",
153 "//third_party:opencv",
154 ],
155)
156
Brian Silverman3fec6482020-01-19 17:56:20 -0800157cc_binary(
158 name = "testing_sift",
159 srcs = [
160 "testing_sift.cc",
161 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800162 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800163 deps = [
164 ":fast_gaussian",
165 "//aos:init",
166 "//aos/time",
167 "//third_party:opencv",
168 "//y2020/vision/sift:sift971",
169 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800170 ],
171)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800172
173flatbuffer_py_library(
174 name = "sift_fbs_python",
175 srcs = [
176 "sift.fbs",
177 "sift_training.fbs",
178 ],
179 namespace = "frc971.vision.sift",
180 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800181 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800182 "Feature",
183 "Match",
184 "ImageMatch",
185 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800186 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800187 "CameraPose",
188 "ImageMatchResult",
189 "TrainingImage",
190 "TrainingData",
191 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800192 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800193 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800194)
195
196flatbuffer_cc_library(
197 name = "sift_fbs",
198 srcs = ["sift.fbs"],
199 gen_reflections = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800200 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800201 visibility = ["//visibility:public"],
202)
203
Alex Perryd5e13572020-02-22 15:15:08 -0800204flatbuffer_ts_library(
205 name = "sift_ts_fbs",
206 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800207 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800208 visibility = ["//y2020:__subpackages__"],
209)
210
Brian Silvermanfac9b872020-02-05 20:07:38 -0800211flatbuffer_cc_library(
212 name = "sift_training_fbs",
213 srcs = ["sift_training.fbs"],
214 gen_reflections = True,
215 includes = [":sift_fbs_includes"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800216 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800217 visibility = ["//visibility:public"],
218)
Brian Silverman967e5df2020-02-09 16:43:34 -0800219
220py_binary(
221 name = "demo_sift_training",
222 srcs = ["demo_sift_training.py"],
Austin Schuhda9d0602019-09-15 17:29:38 -0700223 python_version = "PY3",
Brian Silverman967e5df2020-02-09 16:43:34 -0800224 srcs_version = "PY2AND3",
Philipp Schraderdada1072020-11-24 11:34:46 -0800225 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800226 deps = [
227 ":sift_fbs_python",
228 "@opencv_contrib_nonfree_amd64//:python_opencv",
229 ],
230)
231
232genrule(
233 name = "run_demo_sift_training",
234 srcs = [
235 "images/demo/FRC-Image4-cleaned.png",
236 ],
237 outs = [
238 "demo_sift.h",
239 ],
240 cmd = " ".join([
241 "$(location :demo_sift_training)",
242 "$(location images/demo/FRC-Image4-cleaned.png)",
243 "$(location demo_sift.h)",
244 ]),
Philipp Schraderdada1072020-11-24 11:34:46 -0800245 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800246 tools = [
247 ":demo_sift_training",
248 ],
249)
250
251cc_library(
252 name = "demo_sift",
253 hdrs = [
254 "demo_sift.h",
255 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800256 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800257 visibility = ["//visibility:public"],
258)