blob: 93e28581645c1a5f11fd3c240d750673d7f40d30 [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 main = "fast_gaussian_runner.py",
Philipp Schraderdada1072020-11-24 11:34:46 -080028 target_compatible_with = ["@platforms//os:linux"],
Austin Schuha2503a72020-12-15 20:57:57 -080029 toolchains = [
30 "@bazel_tools//tools/cpp:current_cc_toolchain",
31 ],
Brian Silverman3fec6482020-01-19 17:56:20 -080032 deps = [
33 "@bazel_tools//tools/python/runfiles",
34 ],
35)
36
37# Each element is [sigma, sigma_name, radius].
38# opencv's default width is calculated as:
39# cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1
40# Pulling that in helps a lot with making it faster (less data to read, and less
41# math to do), but if you make it too narrow SIFT quickly freaks out.
42sigmas = [
43 [
44 "1.2262734984654078",
45 "1p2",
46 "9",
47 ],
48 [
49 "1.5450077936447955",
50 "1p5",
51 "11",
52 ],
53 [
54 "1.9465878414647133",
55 "1p9",
56 "13",
57 ],
58 [
59 "2.4525469969308156",
60 "2p4",
61 "15",
62 ],
63 [
64 "3.0900155872895909",
65 "3p1",
66 "19",
67 ],
68 # TODO(Brian): We only need one of these two for 1280x720. Don't generate
69 # all the redundant versions for other sizes, and maybe stop doing the one
70 # we don't actually use.
71 [
Brian Silverman950bffa2020-02-01 16:53:49 -080072 "1.2489995956420898",
Brian Silverman3fec6482020-01-19 17:56:20 -080073 "1p24",
74 "11",
75 ],
76 [
77 "1.5198683738708496",
78 "1p52",
79 "15",
80 ],
81]
82
83sizes = [
84 [
85 1280,
Brian Silverman950bffa2020-02-01 16:53:49 -080086 960,
Brian Silverman3fec6482020-01-19 17:56:20 -080087 ],
88 [
89 640,
Brian Silverman950bffa2020-02-01 16:53:49 -080090 480,
Brian Silverman3fec6482020-01-19 17:56:20 -080091 ],
92 [
93 320,
Brian Silverman950bffa2020-02-01 16:53:49 -080094 240,
Brian Silverman3fec6482020-01-19 17:56:20 -080095 ],
96 [
97 160,
Brian Silverman950bffa2020-02-01 16:53:49 -080098 120,
Brian Silverman3fec6482020-01-19 17:56:20 -080099 ],
100 [
101 80,
Brian Silverman950bffa2020-02-01 16:53:49 -0800102 60,
Brian Silverman3fec6482020-01-19 17:56:20 -0800103 ],
104]
105
106fast_gaussian(sigmas, sizes)
107
Brian Silvermanf1196122020-01-16 00:41:54 -0800108cc_library(
109 name = "sift971",
110 srcs = [
111 "sift971.cc",
112 ],
113 hdrs = [
114 "sift971.h",
115 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800116 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanf1196122020-01-16 00:41:54 -0800117 visibility = ["//visibility:public"],
118 deps = [
Brian Silverman3fec6482020-01-19 17:56:20 -0800119 ":fast_gaussian",
Brian Silvermanf1196122020-01-16 00:41:54 -0800120 "//third_party:opencv",
Brian Silverman3fec6482020-01-19 17:56:20 -0800121 "@com_github_google_glog//:glog",
122 ],
123)
124
125cc_library(
126 name = "fast_gaussian",
127 srcs = [
128 "fast_gaussian.cc",
129 ],
130 hdrs = [
131 "fast_gaussian.h",
132 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800133 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800134 deps = [
135 ":fast_gaussian_all",
136 "//third_party:halide_runtime",
137 "//third_party:opencv",
138 "@com_github_google_glog//:glog",
139 ],
140)
141
Brian Silvermane4664162020-02-15 15:27:46 -0800142cc_test(
143 name = "fast_gaussian_test",
144 srcs = [
145 "fast_gaussian_test.cc",
146 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800147 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermane4664162020-02-15 15:27:46 -0800148 deps = [
149 ":fast_gaussian",
150 "//aos/testing:googletest",
151 "//third_party:opencv",
152 ],
153)
154
Brian Silverman3fec6482020-01-19 17:56:20 -0800155cc_binary(
156 name = "testing_sift",
157 srcs = [
158 "testing_sift.cc",
159 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800160 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman3fec6482020-01-19 17:56:20 -0800161 deps = [
162 ":fast_gaussian",
163 "//aos:init",
164 "//aos/time",
165 "//third_party:opencv",
166 "//y2020/vision/sift:sift971",
167 "@com_github_google_glog//:glog",
Brian Silvermanf1196122020-01-16 00:41:54 -0800168 ],
169)
Brian Silvermanfac9b872020-02-05 20:07:38 -0800170
171flatbuffer_py_library(
172 name = "sift_fbs_python",
173 srcs = [
174 "sift.fbs",
175 "sift_training.fbs",
176 ],
177 namespace = "frc971.vision.sift",
178 tables = [
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800179 "KeypointFieldLocation",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800180 "Feature",
181 "Match",
182 "ImageMatch",
183 "TransformationMatrix",
Jim Ostrowski38bb70b2020-02-21 20:46:10 -0800184 "CameraCalibration",
Brian Silvermanfac9b872020-02-05 20:07:38 -0800185 "CameraPose",
186 "ImageMatchResult",
187 "TrainingImage",
188 "TrainingData",
189 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800190 target_compatible_with = ["@platforms//os:linux"],
Jim Ostrowskife70d3b2020-02-15 22:15:07 -0800191 visibility = ["//visibility:public"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800192)
193
194flatbuffer_cc_library(
195 name = "sift_fbs",
196 srcs = ["sift.fbs"],
197 gen_reflections = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800198 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800199 visibility = ["//visibility:public"],
200)
201
Alex Perryd5e13572020-02-22 15:15:08 -0800202flatbuffer_ts_library(
203 name = "sift_ts_fbs",
204 srcs = ["sift.fbs"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800205 target_compatible_with = ["@platforms//os:linux"],
Alex Perryd5e13572020-02-22 15:15:08 -0800206 visibility = ["//y2020:__subpackages__"],
207)
208
Brian Silvermanfac9b872020-02-05 20:07:38 -0800209flatbuffer_cc_library(
210 name = "sift_training_fbs",
211 srcs = ["sift_training.fbs"],
212 gen_reflections = True,
213 includes = [":sift_fbs_includes"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800214 target_compatible_with = ["@platforms//os:linux"],
Brian Silvermanfac9b872020-02-05 20:07:38 -0800215 visibility = ["//visibility:public"],
216)
Brian Silverman967e5df2020-02-09 16:43:34 -0800217
218py_binary(
219 name = "demo_sift_training",
220 srcs = ["demo_sift_training.py"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800221 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800222 deps = [
223 ":sift_fbs_python",
224 "@opencv_contrib_nonfree_amd64//:python_opencv",
225 ],
226)
227
228genrule(
229 name = "run_demo_sift_training",
230 srcs = [
231 "images/demo/FRC-Image4-cleaned.png",
232 ],
233 outs = [
234 "demo_sift.h",
235 ],
236 cmd = " ".join([
237 "$(location :demo_sift_training)",
238 "$(location images/demo/FRC-Image4-cleaned.png)",
239 "$(location demo_sift.h)",
240 ]),
Philipp Schraderdada1072020-11-24 11:34:46 -0800241 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800242 tools = [
243 ":demo_sift_training",
244 ],
245)
246
247cc_library(
248 name = "demo_sift",
249 hdrs = [
250 "demo_sift.h",
251 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800252 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman967e5df2020-02-09 16:43:34 -0800253 visibility = ["//visibility:public"],
254)