Skip to content

Commit

Permalink
add: [core] Adding a distance only algorithm, using already present f…
Browse files Browse the repository at this point in the history
…eatures. COMMIT EXAMPLE OF HOW TO DO IT ! Very useful ! Algorithm : RANSAC + ORB + Geometrical verifications
  • Loading branch information
Vincent-CIRCL committed Aug 9, 2019
1 parent 6037a51 commit 3648989
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 8 deletions.
12 changes: 11 additions & 1 deletion carlhauser_server/Configuration/distance_engine_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class BOW_CMP_HIST(JSON_parsable_Enum, Enum):
BHATTACHARYYA = auto()



class RANSAC_METHOD(JSON_parsable_Enum, Enum):
CORREL = auto() # Standard
BHATTACHARYYA = auto()


class Default_distance_engine_conf(JSON_parsable_Dict):
def __init__(self):
# Inputs
Expand All @@ -23,9 +29,13 @@ def __init__(self):
# ORB PARAMETERS
self.CROSSCHECK: bool = True

# Bow_ORB PARAMETERS
# BOW_ORB PARAMETERS
self.BOW_CMP_HIST = BOW_CMP_HIST.CORREL.name

# RANSAC_ORB
self.MATCHES_THRESHOLD_TO_ACCELERATE = 0.65
self.MIN_NB_MATCHES_TO_FIND_HOMOGRAPHY = 10


def parse_from_dict(conf):
tmp_conf = Default_distance_engine_conf()
Expand Down
15 changes: 9 additions & 6 deletions carlhauser_server/Configuration/feature_extractor_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,30 @@ def __init__(self):

# HASH parameters
self.A_HASH: Algo_conf = Algo_conf("A_HASH", False, 0.02, 0.08, distance_weight=1)
self.P_HASH: Algo_conf = Algo_conf("P_HASH", True, 0.08, 0.08, distance_weight=1) # True
self.P_HASH: Algo_conf = Algo_conf("P_HASH", False, 0.08, 0.08, distance_weight=1) # True
self.P_HASH_SIMPLE: Algo_conf = Algo_conf("P_HASH_SIMPLE", False, 0.04, 0.06, distance_weight=1)
self.D_HASH: Algo_conf = Algo_conf("D_HASH", True, 0.04, 0.08, distance_weight=1) # True
self.D_HASH: Algo_conf = Algo_conf("D_HASH", False, 0.04, 0.08, distance_weight=1) # True
self.D_HASH_VERTICAL: Algo_conf = Algo_conf("D_HASH_VERTICAL", False, 0.04, 0.04, distance_weight=1)
self.W_HASH: Algo_conf = Algo_conf("W_HASH", False, 0.06, 0.08, distance_weight=1)
self.TLSH: Algo_conf = Algo_conf("TLSH", True, 0.16, 0.18, distance_weight=1) # True
self.TLSH: Algo_conf = Algo_conf("TLSH", False, 0.16, 0.18, distance_weight=1) # True

# Visual Descriptors parameters
self.ORB: Algo_conf = Algo_conf("ORB", False, 0.0, 0.2, distance_weight=5) # True
self.ORB: Algo_conf = Algo_conf("ORB", False, 0.0, 0.2, distance_weight=5) # False
self.ORB_KEYPOINTS_NB: int = 500

self.BOW_ORB: Algo_conf = Algo_conf("BOW_ORB", True, 0.08, 0.32, distance_weight=5) # True
self.BOW_ORB: Algo_conf = Algo_conf("BOW_ORB", False, 0.08, 0.32, distance_weight=5) # True
self.BOW_VOCAB_PATH: pathlib.Path = get_homedir() / "vocab.npy"

self.RANSAC_ORB: Algo_conf = Algo_conf("RANSAC_ORB", True, 0.08, 0.32, distance_weight=10) # False

# Algo list # /! IMPORTANT !\ BE-AWARE THAT /! IMPORTANT !\
# IF YOU MODIFY PROGRAMMATICALLY ONE ELEMENT LATER, YOU NEED TO CHANGE IT IN THIS LIST TOO !
self.list_algos: List[Algo_conf] = [self.A_HASH, self.P_HASH, self.P_HASH_SIMPLE,
self.D_HASH, self.D_HASH_VERTICAL, self.W_HASH,
self.TLSH,
self.ORB,
self.BOW_ORB]
self.BOW_ORB,
self.RANSAC_ORB]

# Merging method
self.DISTANCE_MERGING_METHOD: Distance_MergingMethod = Distance_MergingMethod.WEIGHTED_MEAN.name
Expand Down
12 changes: 12 additions & 0 deletions carlhauser_server/DistanceEngine/distance_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import carlhauser_server.DistanceEngine.distance_hash as distance_hash
import carlhauser_server.DistanceEngine.distance_orb as distance_orb
import carlhauser_server.DistanceEngine.distance_bow_orb as distance_bow_orb
import carlhauser_server.DistanceEngine.distance_ransac_orb as distance_ransac_orb
import carlhauser_server.DistanceEngine.merging_engine as merging_engine
import carlhauser_server.DistanceEngine.scoring_datastrutures as scoring_datastrutures
from common.CustomException import AlgoFeatureNotPresentError
Expand Down Expand Up @@ -43,6 +44,9 @@ def __init__(self, parent: database_worker, db_conf: database_conf.Default_datab
self.distance_hash = distance_hash.Distance_Hash(db_conf, dist_conf, fe_conf)
self.distance_orb = distance_orb.Distance_ORB(db_conf, dist_conf, fe_conf)
self.distance_bow_orb = distance_bow_orb.Distance_BoW_ORB(db_conf, dist_conf, fe_conf)
self.distance_ransac_orb = distance_ransac_orb.Distance_RANSAC_ORB(db_conf, dist_conf, fe_conf)

# Create merging engine
self.merging_engine = merging_engine.Merging_Engine(db_conf, dist_conf, fe_conf)

# ==================== ------ INTER ALGO DISTANCE ------- ====================
Expand Down Expand Up @@ -80,6 +84,14 @@ def get_dist_and_decision_algos_to_algos(self, pic_package_from: Dict, pic_packa
except AlgoFeatureNotPresentError as e:
self.logger.warning(f"No feature present for bow-orbing algorithms.Normal if BOW-ORB is not activated in configuration. Error : {e}")

# Get RANSAC-ORB distances
try:
ransac_orb_dict = self.distance_ransac_orb.ransac_orb_distance(pic_package_from, pic_package_to)
self.logger.debug(f"Computed RANSAC-orb distance : {ransac_orb_dict}")
merged_dict.update(ransac_orb_dict)
except AlgoFeatureNotPresentError as e:
self.logger.warning(f"No feature present for RANSAC-orbing algorithms. Normal if RANSAC-ORB is not activated in configuration. Error : {e}")

self.logger.debug(f"Distance dict : {merged_dict}")
return merged_dict

Expand Down
Loading

0 comments on commit 3648989

Please sign in to comment.