Skip to content

Commit

Permalink
Increased number of hard detections
Browse files Browse the repository at this point in the history
  • Loading branch information
mcampestri committed Mar 28, 2020
1 parent 9c01ce5 commit 1b701ef
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 284 deletions.
2 changes: 1 addition & 1 deletion src/feature_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def find_matches(des1, des2):
# Keep only good matches
good_matches = []
for match1, match2 in matches:
if match1.distance < 0.7 * match2.distance:
if match1.distance < 0.8 * match2.distance:
good_matches.append(match1)

return good_matches
Expand Down
2 changes: 1 addition & 1 deletion src/hard_pipeline/feature_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def find_matches(des1, des2):
# Keep only good matches
good_matches = []
for match1, match2 in matches:
if match1.distance < 0.8 * match2.distance:
if match1.distance < 0.7 * match2.distance:
good_matches.append(match1)

return good_matches
Expand Down
6 changes: 3 additions & 3 deletions src/hard_pipeline/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def preprocess_box_hard(b):
pr_box = b.copy()
pr_box = image_processing.convert_grayscale(pr_box)
pr_box = image_processing.equalize_histogram(pr_box)
#if pr_box.shape[1] >= 200:
#pr_box = image_processing.resize_img(pr_box, 0.5)
if pr_box.shape[1] >= 200:
pr_box = image_processing.blur_image(pr_box)

return pr_box

Expand All @@ -43,7 +43,7 @@ def preprocess_box_hard(b):

for scene in scenes:
visualization_scene = scene.copy()
visualization_scene = image_processing.resize_img(visualization_scene, 2)
visualization_scene = image_processing.resize_img(visualization_scene, 3)

sub_scenes = parallel_hough.split_shelves(scene)

Expand Down
10 changes: 6 additions & 4 deletions src/hard_pipeline/object_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def compute_rectangularity(bounds):


def check_rectangularity(bounds):
return compute_rectangularity(bounds) > 0.3
return compute_rectangularity(bounds) > 0.7


def is_contained(bounds_outer, bounds_inner):
Expand Down Expand Up @@ -129,10 +129,10 @@ def validate_color(box, scene, used_box_pts, used_scene_pts, match_bounds, homog
t = box_masked_area[box_masked_area > 0]
area_ratio = t.shape[0] / (masked_box.shape[0] * masked_box.shape[1])

if area_ratio < 0.20:
if area_ratio < 0.05:
return False

return compare_hue(masked_box, masked_scene, homography, match_bounds)
return compare_hue(box_val, scene_val, homography, match_bounds)


# Compares the colors of the template with the instance found in the scene, to test the compatibility of the match. This
Expand All @@ -142,6 +142,8 @@ def validate_color(box, scene, used_box_pts, used_scene_pts, match_bounds, homog
# discarded.
def compare_hue(box, scene, homography, match_bounds):
transformed_box, test_scene = image_processing.transform_box_in_scene(box, scene, homography)
#visualization.display_img(transformed_box)
#visualization.display_img(test_scene)

left = max(0, np.min([match_bounds[0][0], match_bounds[1][0], match_bounds[2][0], match_bounds[3][0]]))
right = min(transformed_box.shape[1], np.max([match_bounds[0][0], match_bounds[1][0], match_bounds[2][0], match_bounds[3][0]]))
Expand Down Expand Up @@ -209,4 +211,4 @@ def compare_hue(box, scene, homography, match_bounds):
if np.isin(peak, peaks1):
common_peaks = common_peaks + 1

return common_peaks >= 2 and hue_comparison > 0.8
return common_peaks >= 2 and hue_comparison > 0.6
9 changes: 4 additions & 5 deletions src/hard_pipeline/parallel_hough.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import feature_detection
import image_processing
import object_validation
import prove
import visualization
from hard_pipeline import object_validation

low_H = 90
low_S = 8
Expand Down Expand Up @@ -91,7 +91,6 @@ def preprocess_sub_scene(s):
pr_scene = s.copy()
pr_scene = image_processing.convert_grayscale(pr_scene)
pr_scene = image_processing.equalize_histogram(pr_scene)
pr_scene = image_processing.sharpen_img(pr_scene)

return pr_scene

Expand All @@ -112,9 +111,9 @@ def erase_bar(matches_mask, bounds):

def compute_sub_image(dict_box_features, sub_image):
sub_scene, y = sub_image
sub_scene = image_processing.resize_img(sub_scene, 2)
sub_scene = image_processing.resize_img(sub_scene, 3)
proc_scene = preprocess_sub_scene(sub_scene)
y *= 2
y *= 3
test_scene = image_processing.resize_img_dim(sub_scene, proc_scene.shape[1], proc_scene.shape[0])

s = time.time()
Expand Down Expand Up @@ -171,7 +170,7 @@ def compute_sub_image(dict_box_features, sub_image):
bounds_dict[gray_index] = bar_intersecting
if result == -1: # c'è intersezione ma i box non sono completamente uno dentro l'altro, effettuo ulteriore controllo con compare_detections_hard
#print('Calling compare_detections_hard')
result = object_validation.compare_detections_hard(bar_intersected, bar_intersecting, 1.5)
result = object_validation.compare_detections_hard(bar_intersected, bar_intersecting, 2)
#print('Result of compare_detections_hard = ', result)
# if result == 1 allora c'è troppa sovrapposizione tra i box e l'intersecato è migliore dell'intersecante, non faccio nulla
if result == 0: # c'è troppa sovrapposizione tra i box e l'intersecante è migliore dell'intersecato, sostituisco
Expand Down
Loading

0 comments on commit 1b701ef

Please sign in to comment.