Skip to content

Commit

Permalink
Second attempt correcting HoC
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguelmelon committed May 25, 2024
1 parent 818b668 commit 3cc06ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions people_tracking_v2/scripts/HoC.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ def segmented_images_callback(self, msg):
rospy.logerr(f"Failed to convert segmented image: {e}")

def compute_hoc(self, segmented_image):
# Convert to HSV
hsv = cv2.cvtColor(segmented_image, cv2.COLOR_BGR2HSV)

# Compute histogram for Hue (180 bins) and Saturation (256 bins)
hist_hue = cv2.calcHist([hsv], [0], None, [180], [0, 180])
hist_sat = cv2.calcHist([hsv], [1], None, [256], [0, 256])
# Create a mask to ignore black pixels
mask = cv2.inRange(hsv, (0, 0, 1), (180, 255, 255))

# Use the same number of bins for Hue and Saturation
bins = 256

# Compute histogram for Hue and Saturation using the mask
hist_hue = cv2.calcHist([hsv], [0], mask, [bins], [0, 180])
hist_sat = cv2.calcHist([hsv], [1], mask, [bins], [0, 256])

cv2.normalize(hist_hue, hist_hue)
cv2.normalize(hist_sat, hist_sat)
Expand Down
4 changes: 2 additions & 2 deletions people_tracking_v2/scripts/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os

# Expand the user directory
hue_file_path = os.path.expanduser('~/hoc_data/hoc_hue_detection_1.npy')
sat_file_path = os.path.expanduser('~/hoc_data/hoc_sat_detection_1.npy')
hue_file_path = os.path.expanduser('~/hoc_data/hoc_hue_detection_8.npy')
sat_file_path = os.path.expanduser('~/hoc_data/hoc_sat_detection_8.npy')

# Load the HoC arrays from the saved files
hoc_hue = np.load(hue_file_path)
Expand Down

0 comments on commit 3cc06ab

Please sign in to comment.