James Kuszmaul | f01da39 | 2023-12-14 11:22:14 -0800 | [diff] [blame^] | 1 | load("//aos/flatbuffers:generate.bzl", "static_flatbuffer") |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 2 | load(":fast_gaussian.bzl", "fast_gaussian") |
James Kuszmaul | f01da39 | 2023-12-14 11:22:14 -0800 | [diff] [blame^] | 3 | load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_py_library") |
Austin Schuh | a1d006e | 2022-09-14 21:50:42 -0700 | [diff] [blame] | 4 | load("@com_github_google_flatbuffers//:typescript.bzl", "flatbuffer_ts_library") |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 5 | |
Brian Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 6 | # Note that this file is also used directly by :fast_gaussian_halide_generator, |
| 7 | # without any dependencies added here. |
Brian Silverman | 4b0bcaf | 2022-01-01 22:48:55 -0800 | [diff] [blame] | 8 | cc_library( |
| 9 | name = "get_gaussian_kernel", |
| 10 | hdrs = [ |
| 11 | "get_gaussian_kernel.h", |
| 12 | ], |
| 13 | ) |
| 14 | |
| 15 | cc_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 Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 28 | sh_binary( |
| 29 | name = "fast_gaussian_halide_generator", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 30 | srcs = [ |
Brian Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 31 | "fast_gaussian_halide_generator.sh", |
| 32 | ], |
| 33 | data = [ |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 34 | "fast_gaussian_generator.cc", |
Brian Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 35 | "get_gaussian_kernel.h", |
| 36 | "@amd64_debian_sysroot//:sysroot_files", |
Tyler Chatow | 6eda82c | 2022-03-27 22:37:38 -0700 | [diff] [blame] | 37 | "@deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo//file", |
Brian Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 38 | "@halide_k8//:build_files", |
| 39 | "@llvm_toolchain//:all-components-x86_64-linux", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 40 | ], |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 41 | deps = [ |
Brian Silverman | c0309a0 | 2022-01-01 23:57:03 -0800 | [diff] [blame] | 42 | "@bazel_tools//tools/bash/runfiles", |
| 43 | ], |
| 44 | ) |
| 45 | |
| 46 | genrule( |
| 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 Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 54 | ], |
| 55 | ) |
| 56 | |
| 57 | py_binary( |
| 58 | name = "fast_gaussian_runner", |
| 59 | srcs = [ |
| 60 | "fast_gaussian_runner.py", |
| 61 | ], |
| 62 | data = [ |
| 63 | ":fast_gaussian_generator", |
Jim Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 64 | "@amd64_debian_sysroot//:sysroot_files", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 65 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 66 | main = "fast_gaussian_runner.py", |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 67 | target_compatible_with = ["@platforms//os:linux"], |
Austin Schuh | a2503a7 | 2020-12-15 20:57:57 -0800 | [diff] [blame] | 68 | toolchains = [ |
| 69 | "@bazel_tools//tools/cpp:current_cc_toolchain", |
| 70 | ], |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 71 | 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. |
| 81 | sigmas = [ |
| 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 Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 111 | "1.2489995956420898", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 112 | "1p24", |
| 113 | "11", |
| 114 | ], |
| 115 | [ |
| 116 | "1.5198683738708496", |
| 117 | "1p52", |
| 118 | "15", |
| 119 | ], |
| 120 | ] |
| 121 | |
| 122 | sizes = [ |
| 123 | [ |
| 124 | 1280, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 125 | 960, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 126 | ], |
| 127 | [ |
| 128 | 640, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 129 | 480, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 130 | ], |
| 131 | [ |
| 132 | 320, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 133 | 240, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 134 | ], |
| 135 | [ |
| 136 | 160, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 137 | 120, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 138 | ], |
| 139 | [ |
| 140 | 80, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 141 | 60, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 142 | ], |
| 143 | ] |
| 144 | |
| 145 | fast_gaussian(sigmas, sizes) |
| 146 | |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 147 | cc_library( |
| 148 | name = "sift971", |
| 149 | srcs = [ |
| 150 | "sift971.cc", |
| 151 | ], |
| 152 | hdrs = [ |
| 153 | "sift971.h", |
| 154 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 155 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 156 | visibility = ["//visibility:public"], |
| 157 | deps = [ |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 158 | ":fast_gaussian", |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 159 | "//third_party:opencv", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 160 | "@com_github_google_glog//:glog", |
| 161 | ], |
| 162 | ) |
| 163 | |
| 164 | cc_library( |
| 165 | name = "fast_gaussian", |
| 166 | srcs = [ |
| 167 | "fast_gaussian.cc", |
| 168 | ], |
| 169 | hdrs = [ |
| 170 | "fast_gaussian.h", |
| 171 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 172 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 173 | deps = [ |
| 174 | ":fast_gaussian_all", |
| 175 | "//third_party:halide_runtime", |
| 176 | "//third_party:opencv", |
| 177 | "@com_github_google_glog//:glog", |
| 178 | ], |
| 179 | ) |
| 180 | |
Brian Silverman | e466416 | 2020-02-15 15:27:46 -0800 | [diff] [blame] | 181 | cc_test( |
| 182 | name = "fast_gaussian_test", |
| 183 | srcs = [ |
| 184 | "fast_gaussian_test.cc", |
| 185 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 186 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | e466416 | 2020-02-15 15:27:46 -0800 | [diff] [blame] | 187 | deps = [ |
| 188 | ":fast_gaussian", |
| 189 | "//aos/testing:googletest", |
| 190 | "//third_party:opencv", |
| 191 | ], |
| 192 | ) |
| 193 | |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 194 | cc_binary( |
| 195 | name = "testing_sift", |
| 196 | srcs = [ |
| 197 | "testing_sift.cc", |
| 198 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 199 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 200 | 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 Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 207 | ], |
| 208 | ) |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 209 | |
| 210 | flatbuffer_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 Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 218 | "KeypointFieldLocation", |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 219 | "Feature", |
| 220 | "Match", |
| 221 | "ImageMatch", |
| 222 | "TransformationMatrix", |
Jim Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 223 | "CameraCalibration", |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 224 | "CameraPose", |
| 225 | "ImageMatchResult", |
| 226 | "TrainingImage", |
| 227 | "TrainingData", |
| 228 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 229 | target_compatible_with = ["@platforms//os:linux"], |
Jim Ostrowski | fe70d3b | 2020-02-15 22:15:07 -0800 | [diff] [blame] | 230 | visibility = ["//visibility:public"], |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 231 | ) |
| 232 | |
James Kuszmaul | f01da39 | 2023-12-14 11:22:14 -0800 | [diff] [blame^] | 233 | static_flatbuffer( |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 234 | name = "sift_fbs", |
| 235 | srcs = ["sift.fbs"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 236 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 237 | visibility = ["//visibility:public"], |
| 238 | ) |
| 239 | |
Alex Perry | d5e1357 | 2020-02-22 15:15:08 -0800 | [diff] [blame] | 240 | flatbuffer_ts_library( |
| 241 | name = "sift_ts_fbs", |
| 242 | srcs = ["sift.fbs"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 243 | target_compatible_with = ["@platforms//os:linux"], |
Alex Perry | d5e1357 | 2020-02-22 15:15:08 -0800 | [diff] [blame] | 244 | visibility = ["//y2020:__subpackages__"], |
| 245 | ) |
| 246 | |
James Kuszmaul | f01da39 | 2023-12-14 11:22:14 -0800 | [diff] [blame^] | 247 | static_flatbuffer( |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 248 | name = "sift_training_fbs", |
| 249 | srcs = ["sift_training.fbs"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 250 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 251 | visibility = ["//visibility:public"], |
James Kuszmaul | f01da39 | 2023-12-14 11:22:14 -0800 | [diff] [blame^] | 252 | deps = [":sift_fbs"], |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 253 | ) |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 254 | |
| 255 | py_binary( |
| 256 | name = "demo_sift_training", |
| 257 | srcs = ["demo_sift_training.py"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 258 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 259 | deps = [ |
| 260 | ":sift_fbs_python", |
Philipp Schrader | ebb658f | 2022-09-17 17:31:09 -0700 | [diff] [blame] | 261 | "@pip//opencv_python", |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 262 | ], |
| 263 | ) |
| 264 | |
| 265 | genrule( |
| 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 Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 278 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 279 | tools = [ |
| 280 | ":demo_sift_training", |
| 281 | ], |
| 282 | ) |
| 283 | |
| 284 | cc_library( |
| 285 | name = "demo_sift", |
| 286 | hdrs = [ |
| 287 | "demo_sift.h", |
| 288 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 289 | target_compatible_with = ["@platforms//os:linux"], |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 290 | visibility = ["//visibility:public"], |
| 291 | ) |