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