Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 1 | load(":fast_gaussian.bzl", "fast_gaussian") |
Alex Perry | d5e1357 | 2020-02-22 15:15:08 -0800 | [diff] [blame] | 2 | load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library", "flatbuffer_ts_library") |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 3 | |
| 4 | cc_binary( |
| 5 | name = "fast_gaussian_generator", |
| 6 | srcs = [ |
| 7 | "fast_gaussian_generator.cc", |
| 8 | ], |
| 9 | restricted_to = [ |
| 10 | "//tools:k8", |
| 11 | "//tools:armhf-debian", |
| 12 | ], |
| 13 | deps = [ |
| 14 | "//third_party:halide", |
| 15 | "//third_party:halide_gengen", |
| 16 | "//third_party:opencv", |
| 17 | "@com_github_google_glog//:glog", |
| 18 | ], |
| 19 | ) |
| 20 | |
| 21 | py_binary( |
| 22 | name = "fast_gaussian_runner", |
| 23 | srcs = [ |
| 24 | "fast_gaussian_runner.py", |
| 25 | ], |
| 26 | data = [ |
| 27 | ":fast_gaussian_generator", |
| 28 | # TODO(Brian): Replace this with something more fine-grained from the |
| 29 | # configuration fragment or something. |
| 30 | "//tools/cpp:toolchain", |
Jim Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 31 | "@amd64_debian_sysroot//:sysroot_files", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 32 | ], |
| 33 | default_python_version = "PY3", |
| 34 | main = "fast_gaussian_runner.py", |
| 35 | restricted_to = [ |
| 36 | "//tools:k8", |
| 37 | "//tools:armhf-debian", |
| 38 | ], |
| 39 | srcs_version = "PY2AND3", |
| 40 | deps = [ |
| 41 | "@bazel_tools//tools/python/runfiles", |
| 42 | ], |
| 43 | ) |
| 44 | |
| 45 | # Each element is [sigma, sigma_name, radius]. |
| 46 | # opencv's default width is calculated as: |
| 47 | # cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1 |
| 48 | # Pulling that in helps a lot with making it faster (less data to read, and less |
| 49 | # math to do), but if you make it too narrow SIFT quickly freaks out. |
| 50 | sigmas = [ |
| 51 | [ |
| 52 | "1.2262734984654078", |
| 53 | "1p2", |
| 54 | "9", |
| 55 | ], |
| 56 | [ |
| 57 | "1.5450077936447955", |
| 58 | "1p5", |
| 59 | "11", |
| 60 | ], |
| 61 | [ |
| 62 | "1.9465878414647133", |
| 63 | "1p9", |
| 64 | "13", |
| 65 | ], |
| 66 | [ |
| 67 | "2.4525469969308156", |
| 68 | "2p4", |
| 69 | "15", |
| 70 | ], |
| 71 | [ |
| 72 | "3.0900155872895909", |
| 73 | "3p1", |
| 74 | "19", |
| 75 | ], |
| 76 | # TODO(Brian): We only need one of these two for 1280x720. Don't generate |
| 77 | # all the redundant versions for other sizes, and maybe stop doing the one |
| 78 | # we don't actually use. |
| 79 | [ |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 80 | "1.2489995956420898", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 81 | "1p24", |
| 82 | "11", |
| 83 | ], |
| 84 | [ |
| 85 | "1.5198683738708496", |
| 86 | "1p52", |
| 87 | "15", |
| 88 | ], |
| 89 | ] |
| 90 | |
| 91 | sizes = [ |
| 92 | [ |
| 93 | 1280, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 94 | 960, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 95 | ], |
| 96 | [ |
| 97 | 640, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 98 | 480, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 99 | ], |
| 100 | [ |
| 101 | 320, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 102 | 240, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 103 | ], |
| 104 | [ |
| 105 | 160, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 106 | 120, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 107 | ], |
| 108 | [ |
| 109 | 80, |
Brian Silverman | 950bffa | 2020-02-01 16:53:49 -0800 | [diff] [blame] | 110 | 60, |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 111 | ], |
| 112 | ] |
| 113 | |
| 114 | fast_gaussian(sigmas, sizes) |
| 115 | |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 116 | cc_library( |
| 117 | name = "sift971", |
| 118 | srcs = [ |
| 119 | "sift971.cc", |
| 120 | ], |
| 121 | hdrs = [ |
| 122 | "sift971.h", |
| 123 | ], |
| 124 | restricted_to = [ |
| 125 | "//tools:k8", |
| 126 | "//tools:armhf-debian", |
| 127 | ], |
| 128 | visibility = ["//visibility:public"], |
| 129 | deps = [ |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 130 | ":fast_gaussian", |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 131 | "//third_party:opencv", |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 132 | "@com_github_google_glog//:glog", |
| 133 | ], |
| 134 | ) |
| 135 | |
| 136 | cc_library( |
| 137 | name = "fast_gaussian", |
| 138 | srcs = [ |
| 139 | "fast_gaussian.cc", |
| 140 | ], |
| 141 | hdrs = [ |
| 142 | "fast_gaussian.h", |
| 143 | ], |
| 144 | restricted_to = [ |
| 145 | "//tools:k8", |
| 146 | "//tools:armhf-debian", |
| 147 | ], |
| 148 | deps = [ |
| 149 | ":fast_gaussian_all", |
| 150 | "//third_party:halide_runtime", |
| 151 | "//third_party:opencv", |
| 152 | "@com_github_google_glog//:glog", |
| 153 | ], |
| 154 | ) |
| 155 | |
Brian Silverman | e466416 | 2020-02-15 15:27:46 -0800 | [diff] [blame] | 156 | cc_test( |
| 157 | name = "fast_gaussian_test", |
| 158 | srcs = [ |
| 159 | "fast_gaussian_test.cc", |
| 160 | ], |
| 161 | restricted_to = [ |
| 162 | "//tools:k8", |
| 163 | "//tools:armhf-debian", |
| 164 | ], |
| 165 | deps = [ |
| 166 | ":fast_gaussian", |
| 167 | "//aos/testing:googletest", |
| 168 | "//third_party:opencv", |
| 169 | ], |
| 170 | ) |
| 171 | |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 172 | cc_binary( |
| 173 | name = "testing_sift", |
| 174 | srcs = [ |
| 175 | "testing_sift.cc", |
| 176 | ], |
| 177 | restricted_to = [ |
| 178 | "//tools:k8", |
| 179 | "//tools:armhf-debian", |
| 180 | ], |
| 181 | deps = [ |
| 182 | ":fast_gaussian", |
| 183 | "//aos:init", |
| 184 | "//aos/time", |
| 185 | "//third_party:opencv", |
| 186 | "//y2020/vision/sift:sift971", |
| 187 | "@com_github_google_glog//:glog", |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 188 | ], |
| 189 | ) |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 190 | |
| 191 | flatbuffer_py_library( |
| 192 | name = "sift_fbs_python", |
| 193 | srcs = [ |
| 194 | "sift.fbs", |
| 195 | "sift_training.fbs", |
| 196 | ], |
| 197 | namespace = "frc971.vision.sift", |
| 198 | tables = [ |
Jim Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 199 | "KeypointFieldLocation", |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 200 | "Feature", |
| 201 | "Match", |
| 202 | "ImageMatch", |
| 203 | "TransformationMatrix", |
Jim Ostrowski | 38bb70b | 2020-02-21 20:46:10 -0800 | [diff] [blame] | 204 | "CameraCalibration", |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 205 | "CameraPose", |
| 206 | "ImageMatchResult", |
| 207 | "TrainingImage", |
| 208 | "TrainingData", |
| 209 | ], |
Jim Ostrowski | fe70d3b | 2020-02-15 22:15:07 -0800 | [diff] [blame] | 210 | visibility = ["//visibility:public"], |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 211 | ) |
| 212 | |
| 213 | flatbuffer_cc_library( |
| 214 | name = "sift_fbs", |
| 215 | srcs = ["sift.fbs"], |
| 216 | gen_reflections = True, |
| 217 | visibility = ["//visibility:public"], |
| 218 | ) |
| 219 | |
Alex Perry | d5e1357 | 2020-02-22 15:15:08 -0800 | [diff] [blame] | 220 | flatbuffer_ts_library( |
| 221 | name = "sift_ts_fbs", |
| 222 | srcs = ["sift.fbs"], |
| 223 | visibility = ["//y2020:__subpackages__"], |
| 224 | ) |
| 225 | |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 226 | flatbuffer_cc_library( |
| 227 | name = "sift_training_fbs", |
| 228 | srcs = ["sift_training.fbs"], |
| 229 | gen_reflections = True, |
| 230 | includes = [":sift_fbs_includes"], |
| 231 | visibility = ["//visibility:public"], |
| 232 | ) |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 233 | |
| 234 | py_binary( |
| 235 | name = "demo_sift_training", |
| 236 | srcs = ["demo_sift_training.py"], |
| 237 | default_python_version = "PY3", |
| 238 | srcs_version = "PY2AND3", |
| 239 | deps = [ |
| 240 | ":sift_fbs_python", |
| 241 | "@opencv_contrib_nonfree_amd64//:python_opencv", |
| 242 | ], |
| 243 | ) |
| 244 | |
| 245 | genrule( |
| 246 | name = "run_demo_sift_training", |
| 247 | srcs = [ |
| 248 | "images/demo/FRC-Image4-cleaned.png", |
| 249 | ], |
| 250 | outs = [ |
| 251 | "demo_sift.h", |
| 252 | ], |
| 253 | cmd = " ".join([ |
| 254 | "$(location :demo_sift_training)", |
| 255 | "$(location images/demo/FRC-Image4-cleaned.png)", |
| 256 | "$(location demo_sift.h)", |
| 257 | ]), |
| 258 | tools = [ |
| 259 | ":demo_sift_training", |
| 260 | ], |
| 261 | ) |
| 262 | |
| 263 | cc_library( |
| 264 | name = "demo_sift", |
| 265 | hdrs = [ |
| 266 | "demo_sift.h", |
| 267 | ], |
| 268 | visibility = ["//visibility:public"], |
| 269 | ) |