Spaces:
Running
on
Zero
Running
on
Zero
Update imcui/ui/app_class.py
Browse files- imcui/ui/app_class.py +824 -817
imcui/ui/app_class.py
CHANGED
|
@@ -1,817 +1,824 @@
|
|
| 1 |
-
from pathlib import Path
|
| 2 |
-
from typing import Any, Dict, Optional, Tuple
|
| 3 |
-
import spaces
|
| 4 |
-
import gradio as gr
|
| 5 |
-
import numpy as np
|
| 6 |
-
from easydict import EasyDict as edict
|
| 7 |
-
from omegaconf import OmegaConf
|
| 8 |
-
|
| 9 |
-
from .sfm import SfmEngine
|
| 10 |
-
from .utils import (
|
| 11 |
-
GRADIO_VERSION,
|
| 12 |
-
gen_examples,
|
| 13 |
-
generate_warp_images,
|
| 14 |
-
get_matcher_zoo,
|
| 15 |
-
load_config,
|
| 16 |
-
ransac_zoo,
|
| 17 |
-
run_matching,
|
| 18 |
-
run_ransac,
|
| 19 |
-
send_to_match,
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
DESCRIPTION = """
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
self.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
label="
|
| 91 |
-
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
value=
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
with gr.Accordion(
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
with gr.Accordion(
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
)
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
fn=
|
| 372 |
-
inputs=
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
)
|
| 394 |
-
|
| 395 |
-
#
|
| 396 |
-
|
| 397 |
-
fn=
|
| 398 |
-
inputs=[
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
sfm_ui
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
Dict[str, Any],
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
def
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
def
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
value=
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
self.inputs.
|
| 691 |
-
label="
|
| 692 |
-
minimum=
|
| 693 |
-
maximum=
|
| 694 |
-
value=
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
self.inputs.
|
| 698 |
-
label="
|
| 699 |
-
minimum=0
|
| 700 |
-
maximum=
|
| 701 |
-
value=0.
|
| 702 |
-
)
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
)
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
)
|
| 772 |
-
self.inputs.
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
self.inputs.
|
| 807 |
-
self.inputs.
|
| 808 |
-
self.inputs.
|
| 809 |
-
self.inputs.
|
| 810 |
-
self.inputs.
|
| 811 |
-
self.inputs.
|
| 812 |
-
self.inputs.
|
| 813 |
-
self.inputs.
|
| 814 |
-
self.inputs.
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from typing import Any, Dict, Optional, Tuple
|
| 3 |
+
import spaces
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
from easydict import EasyDict as edict
|
| 7 |
+
from omegaconf import OmegaConf
|
| 8 |
+
|
| 9 |
+
from .sfm import SfmEngine
|
| 10 |
+
from .utils import (
|
| 11 |
+
GRADIO_VERSION,
|
| 12 |
+
gen_examples,
|
| 13 |
+
generate_warp_images,
|
| 14 |
+
get_matcher_zoo,
|
| 15 |
+
load_config,
|
| 16 |
+
ransac_zoo,
|
| 17 |
+
run_matching,
|
| 18 |
+
run_ransac,
|
| 19 |
+
send_to_match,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
DESCRIPTION = """
|
| 23 |
+
<div style="text-align: left;">
|
| 24 |
+
<h1 style="font-size: 2rem; font-weight: bold; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 1rem;">
|
| 25 |
+
Image Matching WebUI
|
| 26 |
+
</h1>
|
| 27 |
+
</div>
|
| 28 |
+
|
| 29 |
+
This Space demonstrates [Image Matching WebUI](https://github.com/Vincentqyw/image-matching-webui) by vincent qin. Feel free to play with it, or duplicate to run image matching without a queue!
|
| 30 |
+
<br/>
|
| 31 |
+
π **Now GPU-accelerated!** Thanks to HuggingFace's community grant, all algorithms run on GPU for fast, responsive inference.
|
| 32 |
+
|
| 33 |
+
π For more details about supported local features and matchers, please refer to https://github.com/Vincentqyw/image-matching-webui
|
| 34 |
+
|
| 35 |
+
π Your feedback is valuable to me. Please do not hesitate to report any bugs [here](https://github.com/Vincentqyw/image-matching-webui/issues).
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
CSS = """
|
| 39 |
+
#warning {background-color: #FFCCCB}
|
| 40 |
+
.logs_class textarea {font-size: 10px !important}
|
| 41 |
+
|
| 42 |
+
.gradio-container {
|
| 43 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ImageMatchingApp:
|
| 50 |
+
def __init__(self, server_name="0.0.0.0", server_port=7860, **kwargs):
|
| 51 |
+
self.server_name = server_name
|
| 52 |
+
self.server_port = server_port
|
| 53 |
+
self.config_path = kwargs.get("config", Path(__file__).parent / "config.yaml")
|
| 54 |
+
self.cfg = load_config(self.config_path)
|
| 55 |
+
self.matcher_zoo = get_matcher_zoo(self.cfg["matcher_zoo"])
|
| 56 |
+
self.app = None
|
| 57 |
+
self.example_data_root = kwargs.get(
|
| 58 |
+
"example_data_root", Path(__file__).parents[1] / "datasets"
|
| 59 |
+
)
|
| 60 |
+
# final step
|
| 61 |
+
self.init_interface()
|
| 62 |
+
|
| 63 |
+
def init_matcher_dropdown(self):
|
| 64 |
+
algos = []
|
| 65 |
+
for k, v in self.cfg["matcher_zoo"].items():
|
| 66 |
+
if v.get("enable", True):
|
| 67 |
+
algos.append(k)
|
| 68 |
+
return algos
|
| 69 |
+
|
| 70 |
+
def init_interface(self):
|
| 71 |
+
with gr.Blocks(css=CSS) as self.app:
|
| 72 |
+
with gr.Tab("Image Matching"):
|
| 73 |
+
with gr.Row():
|
| 74 |
+
with gr.Column(scale=1):
|
| 75 |
+
gr.Image(
|
| 76 |
+
str(Path(__file__).parent.parent / "assets/logo.webp"),
|
| 77 |
+
elem_id="logo-img",
|
| 78 |
+
show_label=False,
|
| 79 |
+
show_share_button=False,
|
| 80 |
+
show_download_button=False,
|
| 81 |
+
)
|
| 82 |
+
with gr.Column(scale=3):
|
| 83 |
+
gr.Markdown(DESCRIPTION)
|
| 84 |
+
with gr.Row(equal_height=False):
|
| 85 |
+
with gr.Column():
|
| 86 |
+
with gr.Row():
|
| 87 |
+
matcher_list = gr.Dropdown(
|
| 88 |
+
choices=self.init_matcher_dropdown(),
|
| 89 |
+
value="disk+lightglue",
|
| 90 |
+
label="Matching Model",
|
| 91 |
+
interactive=True,
|
| 92 |
+
)
|
| 93 |
+
match_image_src = gr.Radio(
|
| 94 |
+
(
|
| 95 |
+
["upload", "webcam", "clipboard"]
|
| 96 |
+
if GRADIO_VERSION > "3"
|
| 97 |
+
else ["upload", "webcam", "canvas"]
|
| 98 |
+
),
|
| 99 |
+
label="Image Source",
|
| 100 |
+
value="upload",
|
| 101 |
+
)
|
| 102 |
+
with gr.Row():
|
| 103 |
+
input_image0 = gr.Image(
|
| 104 |
+
label="Image 0",
|
| 105 |
+
type="numpy",
|
| 106 |
+
image_mode="RGB",
|
| 107 |
+
height=300 if GRADIO_VERSION > "3" else None,
|
| 108 |
+
interactive=True,
|
| 109 |
+
)
|
| 110 |
+
input_image1 = gr.Image(
|
| 111 |
+
label="Image 1",
|
| 112 |
+
type="numpy",
|
| 113 |
+
image_mode="RGB",
|
| 114 |
+
height=300 if GRADIO_VERSION > "3" else None,
|
| 115 |
+
interactive=True,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
with gr.Row():
|
| 119 |
+
button_reset = gr.Button(value="Reset")
|
| 120 |
+
button_run = gr.Button(value="Run Match", variant="primary")
|
| 121 |
+
with gr.Row():
|
| 122 |
+
button_stop = gr.Button(value="Force Stop", variant="stop")
|
| 123 |
+
|
| 124 |
+
with gr.Accordion("Advanced Setting", open=False):
|
| 125 |
+
with gr.Tab("Matching Setting"):
|
| 126 |
+
with gr.Row():
|
| 127 |
+
match_setting_threshold = gr.Slider(
|
| 128 |
+
minimum=0.0,
|
| 129 |
+
maximum=1,
|
| 130 |
+
step=0.001,
|
| 131 |
+
label="Match threshold",
|
| 132 |
+
value=0.1,
|
| 133 |
+
)
|
| 134 |
+
match_setting_max_keypoints = gr.Slider(
|
| 135 |
+
minimum=10,
|
| 136 |
+
maximum=10000,
|
| 137 |
+
step=10,
|
| 138 |
+
label="Max features",
|
| 139 |
+
value=1000,
|
| 140 |
+
)
|
| 141 |
+
# TODO: add line settings
|
| 142 |
+
with gr.Row():
|
| 143 |
+
detect_keypoints_threshold = gr.Slider(
|
| 144 |
+
minimum=0,
|
| 145 |
+
maximum=1,
|
| 146 |
+
step=0.001,
|
| 147 |
+
label="Keypoint threshold",
|
| 148 |
+
value=0.015,
|
| 149 |
+
)
|
| 150 |
+
detect_line_threshold = gr.Slider( # noqa: F841
|
| 151 |
+
minimum=0.1,
|
| 152 |
+
maximum=1,
|
| 153 |
+
step=0.01,
|
| 154 |
+
label="Line threshold",
|
| 155 |
+
value=0.2,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
with gr.Tab("RANSAC Setting"):
|
| 159 |
+
with gr.Row(equal_height=False):
|
| 160 |
+
ransac_method = gr.Dropdown(
|
| 161 |
+
choices=ransac_zoo.keys(),
|
| 162 |
+
value=self.cfg["defaults"]["ransac_method"],
|
| 163 |
+
label="RANSAC Method",
|
| 164 |
+
interactive=True,
|
| 165 |
+
)
|
| 166 |
+
ransac_reproj_threshold = gr.Slider(
|
| 167 |
+
minimum=0.0,
|
| 168 |
+
maximum=12,
|
| 169 |
+
step=0.01,
|
| 170 |
+
label="Ransac Reproj threshold",
|
| 171 |
+
value=8.0,
|
| 172 |
+
)
|
| 173 |
+
ransac_confidence = gr.Slider(
|
| 174 |
+
minimum=0.0,
|
| 175 |
+
maximum=1,
|
| 176 |
+
step=0.00001,
|
| 177 |
+
label="Ransac Confidence",
|
| 178 |
+
value=self.cfg["defaults"]["ransac_confidence"],
|
| 179 |
+
)
|
| 180 |
+
ransac_max_iter = gr.Slider(
|
| 181 |
+
minimum=0.0,
|
| 182 |
+
maximum=100000,
|
| 183 |
+
step=100,
|
| 184 |
+
label="Ransac Iterations",
|
| 185 |
+
value=self.cfg["defaults"]["ransac_max_iter"],
|
| 186 |
+
)
|
| 187 |
+
button_ransac = gr.Button(
|
| 188 |
+
value="Rerun RANSAC", variant="primary"
|
| 189 |
+
)
|
| 190 |
+
with gr.Tab("Geometry Setting"):
|
| 191 |
+
with gr.Row(equal_height=False):
|
| 192 |
+
choice_geometry_type = gr.Radio(
|
| 193 |
+
["Fundamental", "Homography"],
|
| 194 |
+
label="Reconstruct Geometry",
|
| 195 |
+
value=self.cfg["defaults"]["setting_geometry"],
|
| 196 |
+
)
|
| 197 |
+
with gr.Tab("Image Setting"):
|
| 198 |
+
with gr.Row():
|
| 199 |
+
image_force_resize_cb = gr.Checkbox(
|
| 200 |
+
label="Force Resize",
|
| 201 |
+
value=False,
|
| 202 |
+
interactive=True,
|
| 203 |
+
)
|
| 204 |
+
image_setting_height = gr.Slider(
|
| 205 |
+
minimum=48,
|
| 206 |
+
maximum=2048,
|
| 207 |
+
step=16,
|
| 208 |
+
label="Image Height",
|
| 209 |
+
value=480,
|
| 210 |
+
visible=False,
|
| 211 |
+
)
|
| 212 |
+
image_setting_width = gr.Slider(
|
| 213 |
+
minimum=64,
|
| 214 |
+
maximum=2048,
|
| 215 |
+
step=16,
|
| 216 |
+
label="Image Width",
|
| 217 |
+
value=640,
|
| 218 |
+
visible=False,
|
| 219 |
+
)
|
| 220 |
+
# image resize
|
| 221 |
+
image_force_resize_cb.select(
|
| 222 |
+
fn=self._on_select_force_resize,
|
| 223 |
+
inputs=image_force_resize_cb,
|
| 224 |
+
outputs=[image_setting_width, image_setting_height],
|
| 225 |
+
)
|
| 226 |
+
# collect inputs
|
| 227 |
+
state_cache = gr.State({})
|
| 228 |
+
inputs = [
|
| 229 |
+
input_image0,
|
| 230 |
+
input_image1,
|
| 231 |
+
match_setting_threshold,
|
| 232 |
+
match_setting_max_keypoints,
|
| 233 |
+
detect_keypoints_threshold,
|
| 234 |
+
matcher_list,
|
| 235 |
+
ransac_method,
|
| 236 |
+
ransac_reproj_threshold,
|
| 237 |
+
ransac_confidence,
|
| 238 |
+
ransac_max_iter,
|
| 239 |
+
choice_geometry_type,
|
| 240 |
+
gr.State(self.matcher_zoo),
|
| 241 |
+
image_force_resize_cb,
|
| 242 |
+
image_setting_width,
|
| 243 |
+
image_setting_height,
|
| 244 |
+
]
|
| 245 |
+
|
| 246 |
+
# Add some examples
|
| 247 |
+
with gr.Row():
|
| 248 |
+
# Example inputs
|
| 249 |
+
with gr.Accordion("Open for More: Examples", open=True):
|
| 250 |
+
gr.Examples(
|
| 251 |
+
examples=gen_examples(self.example_data_root),
|
| 252 |
+
inputs=inputs,
|
| 253 |
+
outputs=[],
|
| 254 |
+
fn=run_matching,
|
| 255 |
+
cache_examples=False,
|
| 256 |
+
label=(
|
| 257 |
+
"Examples (click one of the images below to Run"
|
| 258 |
+
" Match). Thx: WxBS"
|
| 259 |
+
),
|
| 260 |
+
)
|
| 261 |
+
with gr.Accordion("Supported Algorithms", open=False):
|
| 262 |
+
# add a table of supported algorithms
|
| 263 |
+
self.display_supported_algorithms()
|
| 264 |
+
|
| 265 |
+
with gr.Column():
|
| 266 |
+
with gr.Accordion("Open for More: Keypoints", open=True):
|
| 267 |
+
output_keypoints = gr.Image(label="Keypoints", type="numpy")
|
| 268 |
+
with gr.Accordion(
|
| 269 |
+
(
|
| 270 |
+
"Open for More: Raw Matches"
|
| 271 |
+
" (Green for good matches, Red for bad)"
|
| 272 |
+
),
|
| 273 |
+
open=False,
|
| 274 |
+
):
|
| 275 |
+
output_matches_raw = gr.Image(
|
| 276 |
+
label="Raw Matches",
|
| 277 |
+
type="numpy",
|
| 278 |
+
)
|
| 279 |
+
with gr.Accordion(
|
| 280 |
+
(
|
| 281 |
+
"Open for More: Ransac Matches"
|
| 282 |
+
" (Green for good matches, Red for bad)"
|
| 283 |
+
),
|
| 284 |
+
open=True,
|
| 285 |
+
):
|
| 286 |
+
output_matches_ransac = gr.Image(
|
| 287 |
+
label="Ransac Matches", type="numpy"
|
| 288 |
+
)
|
| 289 |
+
with gr.Accordion(
|
| 290 |
+
"Open for More: Matches Statistics", open=False
|
| 291 |
+
):
|
| 292 |
+
output_pred = gr.File(label="Outputs", elem_id="download")
|
| 293 |
+
matches_result_info = gr.JSON(label="Matches Statistics")
|
| 294 |
+
matcher_info = gr.JSON(label="Match info")
|
| 295 |
+
|
| 296 |
+
with gr.Accordion("Open for More: Warped Image", open=True):
|
| 297 |
+
output_wrapped = gr.Image(
|
| 298 |
+
label="Wrapped Pair", type="numpy"
|
| 299 |
+
)
|
| 300 |
+
# send to input
|
| 301 |
+
button_rerun = gr.Button(
|
| 302 |
+
value="Send to Input Match Pair",
|
| 303 |
+
variant="primary",
|
| 304 |
+
)
|
| 305 |
+
with gr.Accordion(
|
| 306 |
+
"Open for More: Geometry info", open=False
|
| 307 |
+
):
|
| 308 |
+
geometry_result = gr.JSON(
|
| 309 |
+
label="Reconstructed Geometry"
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
# callbacks
|
| 313 |
+
match_image_src.change(
|
| 314 |
+
fn=self.ui_change_imagebox,
|
| 315 |
+
inputs=match_image_src,
|
| 316 |
+
outputs=input_image0,
|
| 317 |
+
)
|
| 318 |
+
match_image_src.change(
|
| 319 |
+
fn=self.ui_change_imagebox,
|
| 320 |
+
inputs=match_image_src,
|
| 321 |
+
outputs=input_image1,
|
| 322 |
+
)
|
| 323 |
+
# collect outputs
|
| 324 |
+
outputs = [
|
| 325 |
+
output_keypoints,
|
| 326 |
+
output_matches_raw,
|
| 327 |
+
output_matches_ransac,
|
| 328 |
+
matches_result_info,
|
| 329 |
+
matcher_info,
|
| 330 |
+
geometry_result,
|
| 331 |
+
output_wrapped,
|
| 332 |
+
state_cache,
|
| 333 |
+
output_pred,
|
| 334 |
+
]
|
| 335 |
+
# button callbacks
|
| 336 |
+
click_event = button_run.click(
|
| 337 |
+
fn=run_matching, inputs=inputs, outputs=outputs
|
| 338 |
+
)
|
| 339 |
+
# stop button
|
| 340 |
+
button_stop.click(
|
| 341 |
+
fn=None, inputs=None, outputs=None, cancels=[click_event]
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
# Reset images
|
| 345 |
+
reset_outputs = [
|
| 346 |
+
input_image0,
|
| 347 |
+
input_image1,
|
| 348 |
+
match_setting_threshold,
|
| 349 |
+
match_setting_max_keypoints,
|
| 350 |
+
detect_keypoints_threshold,
|
| 351 |
+
matcher_list,
|
| 352 |
+
input_image0,
|
| 353 |
+
input_image1,
|
| 354 |
+
match_image_src,
|
| 355 |
+
output_keypoints,
|
| 356 |
+
output_matches_raw,
|
| 357 |
+
output_matches_ransac,
|
| 358 |
+
matches_result_info,
|
| 359 |
+
matcher_info,
|
| 360 |
+
output_wrapped,
|
| 361 |
+
geometry_result,
|
| 362 |
+
ransac_method,
|
| 363 |
+
ransac_reproj_threshold,
|
| 364 |
+
ransac_confidence,
|
| 365 |
+
ransac_max_iter,
|
| 366 |
+
choice_geometry_type,
|
| 367 |
+
output_pred,
|
| 368 |
+
image_force_resize_cb,
|
| 369 |
+
]
|
| 370 |
+
button_reset.click(
|
| 371 |
+
fn=self.ui_reset_state,
|
| 372 |
+
inputs=None,
|
| 373 |
+
outputs=reset_outputs,
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
# run ransac button action
|
| 377 |
+
button_ransac.click(
|
| 378 |
+
fn=run_ransac,
|
| 379 |
+
inputs=[
|
| 380 |
+
state_cache,
|
| 381 |
+
choice_geometry_type,
|
| 382 |
+
ransac_method,
|
| 383 |
+
ransac_reproj_threshold,
|
| 384 |
+
ransac_confidence,
|
| 385 |
+
ransac_max_iter,
|
| 386 |
+
],
|
| 387 |
+
outputs=[
|
| 388 |
+
output_matches_ransac,
|
| 389 |
+
matches_result_info,
|
| 390 |
+
output_wrapped,
|
| 391 |
+
output_pred,
|
| 392 |
+
],
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# send warped image to match
|
| 396 |
+
button_rerun.click(
|
| 397 |
+
fn=send_to_match,
|
| 398 |
+
inputs=[state_cache],
|
| 399 |
+
outputs=[input_image0, input_image1],
|
| 400 |
+
)
|
| 401 |
+
|
| 402 |
+
# estimate geo
|
| 403 |
+
choice_geometry_type.change(
|
| 404 |
+
fn=generate_warp_images,
|
| 405 |
+
inputs=[
|
| 406 |
+
input_image0,
|
| 407 |
+
input_image1,
|
| 408 |
+
geometry_result,
|
| 409 |
+
choice_geometry_type,
|
| 410 |
+
],
|
| 411 |
+
outputs=[output_wrapped, geometry_result],
|
| 412 |
+
)
|
| 413 |
+
with gr.Tab("Structure from Motion(under-dev)"):
|
| 414 |
+
sfm_ui = AppSfmUI( # noqa: F841
|
| 415 |
+
{
|
| 416 |
+
**self.cfg,
|
| 417 |
+
"matcher_zoo": self.matcher_zoo,
|
| 418 |
+
"outputs": "experiments/sfm",
|
| 419 |
+
}
|
| 420 |
+
)
|
| 421 |
+
sfm_ui.call_empty()
|
| 422 |
+
|
| 423 |
+
def run(self):
|
| 424 |
+
self.app.queue().launch(
|
| 425 |
+
server_name=self.server_name,
|
| 426 |
+
server_port=self.server_port,
|
| 427 |
+
share=False,
|
| 428 |
+
allowed_paths=[
|
| 429 |
+
str(Path(__file__).parents[0]),
|
| 430 |
+
str(Path(__file__).parents[1]),
|
| 431 |
+
],
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
def ui_change_imagebox(self, choice):
|
| 435 |
+
"""
|
| 436 |
+
Updates the image box with the given choice.
|
| 437 |
+
|
| 438 |
+
Args:
|
| 439 |
+
choice (list): The list of image sources to be displayed in the image box.
|
| 440 |
+
|
| 441 |
+
Returns:
|
| 442 |
+
dict: A dictionary containing the updated value, sources, and type for the image box.
|
| 443 |
+
"""
|
| 444 |
+
ret_dict = {
|
| 445 |
+
"value": None, # The updated value of the image box
|
| 446 |
+
"__type__": "update", # The type of update for the image box
|
| 447 |
+
}
|
| 448 |
+
if GRADIO_VERSION > "3":
|
| 449 |
+
return {
|
| 450 |
+
**ret_dict,
|
| 451 |
+
"sources": choice, # The list of image sources to be displayed
|
| 452 |
+
}
|
| 453 |
+
else:
|
| 454 |
+
return {
|
| 455 |
+
**ret_dict,
|
| 456 |
+
"source": choice, # The list of image sources to be displayed
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
def _on_select_force_resize(self, visible: bool = False):
|
| 460 |
+
return gr.update(visible=visible), gr.update(visible=visible)
|
| 461 |
+
|
| 462 |
+
def ui_reset_state(
|
| 463 |
+
self,
|
| 464 |
+
*args: Any,
|
| 465 |
+
) -> Tuple[
|
| 466 |
+
Optional[np.ndarray],
|
| 467 |
+
Optional[np.ndarray],
|
| 468 |
+
float,
|
| 469 |
+
int,
|
| 470 |
+
float,
|
| 471 |
+
str,
|
| 472 |
+
Dict[str, Any],
|
| 473 |
+
Dict[str, Any],
|
| 474 |
+
str,
|
| 475 |
+
Optional[np.ndarray],
|
| 476 |
+
Optional[np.ndarray],
|
| 477 |
+
Optional[np.ndarray],
|
| 478 |
+
Dict[str, Any],
|
| 479 |
+
Dict[str, Any],
|
| 480 |
+
Optional[np.ndarray],
|
| 481 |
+
Dict[str, Any],
|
| 482 |
+
str,
|
| 483 |
+
int,
|
| 484 |
+
float,
|
| 485 |
+
int,
|
| 486 |
+
bool,
|
| 487 |
+
]:
|
| 488 |
+
"""
|
| 489 |
+
Reset the state of the UI.
|
| 490 |
+
|
| 491 |
+
Returns:
|
| 492 |
+
tuple: A tuple containing the initial values for the UI state.
|
| 493 |
+
"""
|
| 494 |
+
key: str = list(self.matcher_zoo.keys())[
|
| 495 |
+
0
|
| 496 |
+
] # Get the first key from matcher_zoo
|
| 497 |
+
# flush_logs()
|
| 498 |
+
return (
|
| 499 |
+
None, # image0: Optional[np.ndarray]
|
| 500 |
+
None, # image1: Optional[np.ndarray]
|
| 501 |
+
self.cfg["defaults"]["match_threshold"], # matching_threshold: float
|
| 502 |
+
self.cfg["defaults"]["max_keypoints"], # max_keypoints: int
|
| 503 |
+
self.cfg["defaults"]["keypoint_threshold"], # keypoint_threshold: float
|
| 504 |
+
key, # matcher: str
|
| 505 |
+
self.ui_change_imagebox("upload"), # input image0: Dict[str, Any]
|
| 506 |
+
self.ui_change_imagebox("upload"), # input image1: Dict[str, Any]
|
| 507 |
+
"upload", # match_image_src: str
|
| 508 |
+
None, # keypoints: Optional[np.ndarray]
|
| 509 |
+
None, # raw matches: Optional[np.ndarray]
|
| 510 |
+
None, # ransac matches: Optional[np.ndarray]
|
| 511 |
+
{}, # matches result info: Dict[str, Any]
|
| 512 |
+
{}, # matcher config: Dict[str, Any]
|
| 513 |
+
None, # warped image: Optional[np.ndarray]
|
| 514 |
+
{}, # geometry result: Dict[str, Any]
|
| 515 |
+
self.cfg["defaults"]["ransac_method"], # ransac_method: str
|
| 516 |
+
self.cfg["defaults"][
|
| 517 |
+
"ransac_reproj_threshold"
|
| 518 |
+
], # ransac_reproj_threshold: float
|
| 519 |
+
self.cfg["defaults"]["ransac_confidence"], # ransac_confidence: float
|
| 520 |
+
self.cfg["defaults"]["ransac_max_iter"], # ransac_max_iter: int
|
| 521 |
+
self.cfg["defaults"]["setting_geometry"], # geometry: str
|
| 522 |
+
None, # predictions
|
| 523 |
+
False,
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
def display_supported_algorithms(self, style="tab"):
|
| 527 |
+
def get_link(link, tag="Link"):
|
| 528 |
+
return "[{}]({})".format(tag, link) if link is not None else "None"
|
| 529 |
+
|
| 530 |
+
data = []
|
| 531 |
+
cfg = self.cfg["matcher_zoo"]
|
| 532 |
+
if style == "md":
|
| 533 |
+
markdown_table = "| Algo. | Conference | Code | Project | Paper |\n"
|
| 534 |
+
markdown_table += "| ----- | ---------- | ---- | ------- | ----- |\n"
|
| 535 |
+
|
| 536 |
+
for _, v in cfg.items():
|
| 537 |
+
if not v["info"].get("display", True):
|
| 538 |
+
continue
|
| 539 |
+
github_link = get_link(v["info"].get("github", ""))
|
| 540 |
+
project_link = get_link(v["info"].get("project", ""))
|
| 541 |
+
paper_link = get_link(
|
| 542 |
+
v["info"]["paper"],
|
| 543 |
+
(
|
| 544 |
+
Path(v["info"]["paper"]).name[-10:]
|
| 545 |
+
if v["info"]["paper"] is not None
|
| 546 |
+
else "Link"
|
| 547 |
+
),
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
markdown_table += "{}|{}|{}|{}|{}\n".format(
|
| 551 |
+
v["info"].get("name", ""),
|
| 552 |
+
v["info"].get("source", ""),
|
| 553 |
+
github_link,
|
| 554 |
+
project_link,
|
| 555 |
+
paper_link,
|
| 556 |
+
)
|
| 557 |
+
return gr.Markdown(markdown_table)
|
| 558 |
+
elif style == "tab":
|
| 559 |
+
for k, v in cfg.items():
|
| 560 |
+
if not v["info"].get("display", True):
|
| 561 |
+
continue
|
| 562 |
+
data.append(
|
| 563 |
+
[
|
| 564 |
+
v["info"].get("name", ""),
|
| 565 |
+
v["info"].get("source", ""),
|
| 566 |
+
v["info"].get("github", ""),
|
| 567 |
+
v["info"].get("paper", ""),
|
| 568 |
+
v["info"].get("project", ""),
|
| 569 |
+
]
|
| 570 |
+
)
|
| 571 |
+
tab = gr.Dataframe(
|
| 572 |
+
headers=["Algo.", "Conference", "Code", "Paper", "Project"],
|
| 573 |
+
datatype=["str", "str", "str", "str", "str"],
|
| 574 |
+
col_count=(5, "fixed"),
|
| 575 |
+
value=data,
|
| 576 |
+
# wrap=True,
|
| 577 |
+
# min_width = 1000,
|
| 578 |
+
# height=1000,
|
| 579 |
+
)
|
| 580 |
+
return tab
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
class AppBaseUI:
|
| 584 |
+
def __init__(self, cfg: Dict[str, Any] = {}):
|
| 585 |
+
self.cfg = OmegaConf.create(cfg)
|
| 586 |
+
self.inputs = edict({})
|
| 587 |
+
self.outputs = edict({})
|
| 588 |
+
self.ui = edict({})
|
| 589 |
+
|
| 590 |
+
def _init_ui(self):
|
| 591 |
+
NotImplemented
|
| 592 |
+
|
| 593 |
+
def call(self, **kwargs):
|
| 594 |
+
NotImplemented
|
| 595 |
+
|
| 596 |
+
def info(self):
|
| 597 |
+
gr.Info("SFM is under construction.")
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
class AppSfmUI(AppBaseUI):
|
| 601 |
+
def __init__(self, cfg: Dict[str, Any] = None):
|
| 602 |
+
super().__init__(cfg)
|
| 603 |
+
assert "matcher_zoo" in self.cfg
|
| 604 |
+
self.matcher_zoo = self.cfg["matcher_zoo"]
|
| 605 |
+
self.sfm_engine = SfmEngine(cfg)
|
| 606 |
+
self._init_ui()
|
| 607 |
+
|
| 608 |
+
def init_retrieval_dropdown(self):
|
| 609 |
+
algos = []
|
| 610 |
+
for k, v in self.cfg["retrieval_zoo"].items():
|
| 611 |
+
if v.get("enable", True):
|
| 612 |
+
algos.append(k)
|
| 613 |
+
return algos
|
| 614 |
+
|
| 615 |
+
def _update_options(self, option):
|
| 616 |
+
if option == "sparse":
|
| 617 |
+
return gr.Textbox("sparse", visible=True)
|
| 618 |
+
elif option == "dense":
|
| 619 |
+
return gr.Textbox("dense", visible=True)
|
| 620 |
+
else:
|
| 621 |
+
return gr.Textbox("not set", visible=True)
|
| 622 |
+
|
| 623 |
+
def _on_select_custom_params(self, value: bool = False):
|
| 624 |
+
return gr.update(visible=value)
|
| 625 |
+
|
| 626 |
+
def _init_ui(self):
|
| 627 |
+
with gr.Row():
|
| 628 |
+
# data settting and camera settings
|
| 629 |
+
with gr.Column():
|
| 630 |
+
self.inputs.input_images = gr.File(
|
| 631 |
+
label="SfM",
|
| 632 |
+
interactive=True,
|
| 633 |
+
file_count="multiple",
|
| 634 |
+
min_width=300,
|
| 635 |
+
)
|
| 636 |
+
# camera setting
|
| 637 |
+
with gr.Accordion("Camera Settings", open=True):
|
| 638 |
+
with gr.Column():
|
| 639 |
+
with gr.Row():
|
| 640 |
+
with gr.Column():
|
| 641 |
+
self.inputs.camera_model = gr.Dropdown(
|
| 642 |
+
choices=[
|
| 643 |
+
"PINHOLE",
|
| 644 |
+
"SIMPLE_RADIAL",
|
| 645 |
+
"OPENCV",
|
| 646 |
+
],
|
| 647 |
+
value="PINHOLE",
|
| 648 |
+
label="Camera Model",
|
| 649 |
+
interactive=True,
|
| 650 |
+
)
|
| 651 |
+
with gr.Column():
|
| 652 |
+
gr.Checkbox(
|
| 653 |
+
label="Shared Params",
|
| 654 |
+
value=True,
|
| 655 |
+
interactive=True,
|
| 656 |
+
)
|
| 657 |
+
camera_custom_params_cb = gr.Checkbox(
|
| 658 |
+
label="Custom Params",
|
| 659 |
+
value=False,
|
| 660 |
+
interactive=True,
|
| 661 |
+
)
|
| 662 |
+
with gr.Row():
|
| 663 |
+
self.inputs.camera_params = gr.Textbox(
|
| 664 |
+
label="Camera Params",
|
| 665 |
+
value="0,0,0,0",
|
| 666 |
+
interactive=False,
|
| 667 |
+
visible=False,
|
| 668 |
+
)
|
| 669 |
+
camera_custom_params_cb.select(
|
| 670 |
+
fn=self._on_select_custom_params,
|
| 671 |
+
inputs=camera_custom_params_cb,
|
| 672 |
+
outputs=self.inputs.camera_params,
|
| 673 |
+
)
|
| 674 |
+
|
| 675 |
+
with gr.Accordion("Matching Settings", open=True):
|
| 676 |
+
# feature extraction and matching setting
|
| 677 |
+
with gr.Row():
|
| 678 |
+
# matcher setting
|
| 679 |
+
self.inputs.matcher_key = gr.Dropdown(
|
| 680 |
+
choices=self.matcher_zoo.keys(),
|
| 681 |
+
value="disk+lightglue",
|
| 682 |
+
label="Matching Model",
|
| 683 |
+
interactive=True,
|
| 684 |
+
)
|
| 685 |
+
with gr.Row():
|
| 686 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 687 |
+
with gr.Column():
|
| 688 |
+
with gr.Row():
|
| 689 |
+
# matching setting
|
| 690 |
+
self.inputs.max_keypoints = gr.Slider(
|
| 691 |
+
label="Max Keypoints",
|
| 692 |
+
minimum=100,
|
| 693 |
+
maximum=10000,
|
| 694 |
+
value=1000,
|
| 695 |
+
interactive=True,
|
| 696 |
+
)
|
| 697 |
+
self.inputs.keypoint_threshold = gr.Slider(
|
| 698 |
+
label="Keypoint Threshold",
|
| 699 |
+
minimum=0,
|
| 700 |
+
maximum=1,
|
| 701 |
+
value=0.01,
|
| 702 |
+
)
|
| 703 |
+
with gr.Row():
|
| 704 |
+
self.inputs.match_threshold = gr.Slider(
|
| 705 |
+
label="Match Threshold",
|
| 706 |
+
minimum=0.01,
|
| 707 |
+
maximum=12.0,
|
| 708 |
+
value=0.2,
|
| 709 |
+
)
|
| 710 |
+
self.inputs.ransac_threshold = gr.Slider(
|
| 711 |
+
label="Ransac Threshold",
|
| 712 |
+
minimum=0.01,
|
| 713 |
+
maximum=12.0,
|
| 714 |
+
value=4.0,
|
| 715 |
+
step=0.01,
|
| 716 |
+
interactive=True,
|
| 717 |
+
)
|
| 718 |
+
|
| 719 |
+
with gr.Row():
|
| 720 |
+
self.inputs.ransac_confidence = gr.Slider(
|
| 721 |
+
label="Ransac Confidence",
|
| 722 |
+
minimum=0.01,
|
| 723 |
+
maximum=1.0,
|
| 724 |
+
value=0.9999,
|
| 725 |
+
step=0.0001,
|
| 726 |
+
interactive=True,
|
| 727 |
+
)
|
| 728 |
+
self.inputs.ransac_max_iter = gr.Slider(
|
| 729 |
+
label="Ransac Max Iter",
|
| 730 |
+
minimum=1,
|
| 731 |
+
maximum=100,
|
| 732 |
+
value=100,
|
| 733 |
+
step=1,
|
| 734 |
+
interactive=True,
|
| 735 |
+
)
|
| 736 |
+
with gr.Accordion("Scene Graph Settings", open=True):
|
| 737 |
+
# mapping setting
|
| 738 |
+
self.inputs.scene_graph = gr.Dropdown(
|
| 739 |
+
choices=["all", "swin", "oneref"],
|
| 740 |
+
value="all",
|
| 741 |
+
label="Scene Graph",
|
| 742 |
+
interactive=True,
|
| 743 |
+
)
|
| 744 |
+
|
| 745 |
+
# global feature setting
|
| 746 |
+
self.inputs.global_feature = gr.Dropdown(
|
| 747 |
+
choices=self.init_retrieval_dropdown(),
|
| 748 |
+
value="netvlad",
|
| 749 |
+
label="Global features",
|
| 750 |
+
interactive=True,
|
| 751 |
+
)
|
| 752 |
+
self.inputs.top_k = gr.Slider(
|
| 753 |
+
label="Number of Images per Image to Match",
|
| 754 |
+
minimum=1,
|
| 755 |
+
maximum=100,
|
| 756 |
+
value=10,
|
| 757 |
+
step=1,
|
| 758 |
+
)
|
| 759 |
+
# button_match = gr.Button("Run Matching", variant="primary")
|
| 760 |
+
|
| 761 |
+
# mapping setting
|
| 762 |
+
with gr.Column():
|
| 763 |
+
with gr.Accordion("Mapping Settings", open=True):
|
| 764 |
+
with gr.Row():
|
| 765 |
+
with gr.Accordion("Buddle Settings", open=True):
|
| 766 |
+
with gr.Row():
|
| 767 |
+
self.inputs.mapper_refine_focal_length = gr.Checkbox(
|
| 768 |
+
label="Refine Focal Length",
|
| 769 |
+
value=False,
|
| 770 |
+
interactive=True,
|
| 771 |
+
)
|
| 772 |
+
self.inputs.mapper_refine_principle_points = (
|
| 773 |
+
gr.Checkbox(
|
| 774 |
+
label="Refine Principle Points",
|
| 775 |
+
value=False,
|
| 776 |
+
interactive=True,
|
| 777 |
+
)
|
| 778 |
+
)
|
| 779 |
+
self.inputs.mapper_refine_extra_params = gr.Checkbox(
|
| 780 |
+
label="Refine Extra Params",
|
| 781 |
+
value=False,
|
| 782 |
+
interactive=True,
|
| 783 |
+
)
|
| 784 |
+
with gr.Accordion("Retriangluation Settings", open=True):
|
| 785 |
+
gr.Textbox(
|
| 786 |
+
label="Retriangluation Details",
|
| 787 |
+
)
|
| 788 |
+
self.ui.button_sfm = gr.Button("Run SFM", variant="primary")
|
| 789 |
+
self.outputs.model_3d = gr.Model3D(
|
| 790 |
+
interactive=True,
|
| 791 |
+
)
|
| 792 |
+
self.outputs.output_image = gr.Image(
|
| 793 |
+
label="SFM Visualize",
|
| 794 |
+
type="numpy",
|
| 795 |
+
image_mode="RGB",
|
| 796 |
+
interactive=False,
|
| 797 |
+
)
|
| 798 |
+
|
| 799 |
+
def call_empty(self):
|
| 800 |
+
self.ui.button_sfm.click(fn=self.info, inputs=[], outputs=[])
|
| 801 |
+
|
| 802 |
+
def call(self):
|
| 803 |
+
self.ui.button_sfm.click(
|
| 804 |
+
fn=self.sfm_engine.call,
|
| 805 |
+
inputs=[
|
| 806 |
+
self.inputs.matcher_key,
|
| 807 |
+
self.inputs.input_images, # images
|
| 808 |
+
self.inputs.camera_model,
|
| 809 |
+
self.inputs.camera_params,
|
| 810 |
+
self.inputs.max_keypoints,
|
| 811 |
+
self.inputs.keypoint_threshold,
|
| 812 |
+
self.inputs.match_threshold,
|
| 813 |
+
self.inputs.ransac_threshold,
|
| 814 |
+
self.inputs.ransac_confidence,
|
| 815 |
+
self.inputs.ransac_max_iter,
|
| 816 |
+
self.inputs.scene_graph,
|
| 817 |
+
self.inputs.global_feature,
|
| 818 |
+
self.inputs.top_k,
|
| 819 |
+
self.inputs.mapper_refine_focal_length,
|
| 820 |
+
self.inputs.mapper_refine_principle_points,
|
| 821 |
+
self.inputs.mapper_refine_extra_params,
|
| 822 |
+
],
|
| 823 |
+
outputs=[self.outputs.model_3d, self.outputs.output_image],
|
| 824 |
+
)
|