Realcat commited on
Commit
d21720c
1 Parent(s): 5808772

update: run ransac

Browse files
Files changed (2) hide show
  1. common/app_class.py +1 -1
  2. common/utils.py +25 -3
common/app_class.py CHANGED
@@ -299,11 +299,11 @@ class ImageMatchingApp:
299
  button_ransac.click(
300
  fn=run_ransac,
301
  inputs=[
 
302
  ransac_method,
303
  ransac_reproj_threshold,
304
  ransac_confidence,
305
  ransac_max_iter,
306
- state_cache,
307
  ],
308
  outputs=[
309
  output_matches_ransac,
 
299
  button_ransac.click(
300
  fn=run_ransac,
301
  inputs=[
302
+ state_cache,
303
  ransac_method,
304
  ransac_reproj_threshold,
305
  ransac_confidence,
306
  ransac_max_iter,
 
307
  ],
308
  outputs=[
309
  output_matches_ransac,
common/utils.py CHANGED
@@ -442,12 +442,29 @@ def generate_warp_images(
442
 
443
 
444
  def run_ransac(
 
445
  ransac_method: str = DEFAULT_RANSAC_METHOD,
446
  ransac_reproj_threshold: int = DEFAULT_RANSAC_REPROJ_THRESHOLD,
447
  ransac_confidence: float = DEFAULT_RANSAC_CONFIDENCE,
448
  ransac_max_iter: int = DEFAULT_RANSAC_MAX_ITER,
449
- state_cache: Dict[str, Any] = None,
450
- ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  t1 = time.time()
452
  logger.info(
453
  f"Run RANSAC matches using: {ransac_method} with threshold: {ransac_reproj_threshold}"
@@ -532,7 +549,12 @@ def run_matching(
532
  """
533
  # image0 and image1 is RGB mode
534
  if image0 is None or image1 is None:
535
- raise gr.Error("Error: No images found! Please upload two images.")
 
 
 
 
 
536
  # init output
537
  output_keypoints = None
538
  output_matches_raw = None
 
442
 
443
 
444
  def run_ransac(
445
+ state_cache: Dict[str, Any],
446
  ransac_method: str = DEFAULT_RANSAC_METHOD,
447
  ransac_reproj_threshold: int = DEFAULT_RANSAC_REPROJ_THRESHOLD,
448
  ransac_confidence: float = DEFAULT_RANSAC_CONFIDENCE,
449
  ransac_max_iter: int = DEFAULT_RANSAC_MAX_ITER,
450
+ ) -> Tuple[Optional[np.ndarray], Optional[Dict[str, int]]]:
451
+ """
452
+ Run RANSAC matches and return the output images and the number of matches.
453
+
454
+ Args:
455
+ state_cache (Dict[str, Any]): Current state of the app, including the matches.
456
+ ransac_method (str, optional): RANSAC method. Defaults to DEFAULT_RANSAC_METHOD.
457
+ ransac_reproj_threshold (int, optional): RANSAC reprojection threshold. Defaults to DEFAULT_RANSAC_REPROJ_THRESHOLD.
458
+ ransac_confidence (float, optional): RANSAC confidence. Defaults to DEFAULT_RANSAC_CONFIDENCE.
459
+ ransac_max_iter (int, optional): RANSAC maximum iterations. Defaults to DEFAULT_RANSAC_MAX_ITER.
460
+
461
+ Returns:
462
+ Tuple[Optional[np.ndarray], Optional[Dict[str, int]]]: Tuple containing the output images and the number of matches.
463
+ """
464
+ if not state_cache:
465
+ logger.info("Run Match first before Rerun RANSAC")
466
+ gr.Warning("Run Match first before Rerun RANSAC")
467
+ return None, None
468
  t1 = time.time()
469
  logger.info(
470
  f"Run RANSAC matches using: {ransac_method} with threshold: {ransac_reproj_threshold}"
 
549
  """
550
  # image0 and image1 is RGB mode
551
  if image0 is None or image1 is None:
552
+ logger.error(
553
+ "Error: No images found! Please upload two images or select an example."
554
+ )
555
+ raise gr.Error(
556
+ "Error: No images found! Please upload two images or select an example."
557
+ )
558
  # init output
559
  output_keypoints = None
560
  output_matches_raw = None