Hello everyone. I am currently working on a project for people detection and counting using hailo. I am using the detections.py code example from hailorpi-exaple-codes. But my issue is that it detects all objects and not just people. So is there a workaround for this?
@omria Any suggestions?
Hey @prajwalshenoy,
You can achieve this in different ways:
-
Modify the callback function to only display detections if they are of a person:
detection_count = 0 for detection in detections: label = detection.get_label() bbox = detection.get_bbox() confidence = detection.get_confidence() if label == "person": string_to_print += f"Detection: {label} {confidence:.2f}\n" detection_count += 1 # Add the detection to the frame only here, not after
-
Use the Labels JSON with only the ‘person’ label set for the app.
-
Modify the
hailofilter
element in the pipeline string by adding afilter-labels
parameter to thehailofilter
element in theget_pipeline_string
method:f"hailofilter so-path={self.default_postprocess_so} {self.labels_config} filter-labels=person qos=false ! "
Also when i change the hailofilter this is what i get
gst_parse_error: no property “filter-labels” in element “hailofilter” (2)
@omria Any suggestions?
labels_json = os.path.join(self.current_path, ' ../resources/barcode-labels.json')
#self.labels_config = os.path.join(self.current_path, '../resources/barcode-labels.json')
if os.path.exists(labels_json):
self.labels_config = os.path.join(self.current_path, '../resources/barcode-labels.json')
else:
self.labels_config = os.path.join(self.current_path, '/resources/barcode-labels.json')
Can you please tell me where i am going wrong with this
Hi @prajwalshenoy,
The most efficient way to solve this issue is by re-training the model with only the ‘person’ label. That’s because the fewer labels, the fewer computations will be necessary and the model will run faster. However, this can be a lot of work, especially if you haven’t retrained a model before.
An easier solution for the detection.py example is to only draw the detections when the label is person. You can do that, for example, by indenting line 71 to line 80 of the example. That would work because on line 68 there’s already a check for if the label is person. The code would look like this:
for detection in detections:
label = detection.get_label()
bbox = detection.get_bbox()
confidence = detection.get_confidence()
if label == "person":
string_to_print += f"Detection: {label} {confidence:.2f}\n"
detection_count += 1
if user_data.use_frame:
# Note: using imshow will not work here, as the callback function is not running in the main thread
# Let's print the detection count to the frame
cv2.putText(frame, f"Detections: {detection_count}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Example of how to use the new_variable and new_function from the user_data
# Let's print the new_variable and the result of the new_function to the frame
cv2.putText(frame, f"{user_data.new_function()} {user_data.new_variable}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Convert the frame to BGR
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
user_data.set_frame(frame)