print detection results

This commit is contained in:
Alex Bezdieniezhnykh
2025-02-10 18:02:44 +02:00
parent 0f13ba384e
commit 9973a16ada
5 changed files with 16 additions and 2 deletions
+1
View File
@@ -14,4 +14,5 @@ cdef class Annotation:
cdef format_time(self, ms) cdef format_time(self, ms)
cdef bytes serialize(self) cdef bytes serialize(self)
cdef to_str(self, class_names)
+10
View File
@@ -32,6 +32,16 @@ cdef class Annotation:
d.annotation_name = self.name d.annotation_name = self.name
self.image = b'' self.image = b''
cdef to_str(self, class_names):
if not self.detections:
return f"{self.name}: No detections"
detections_str = ", ".join(
f"{class_names[d.cls]} {d.confidence * 100:.1f}% ({d.x:.2f}, {d.y:.2f})"
for d in self.detections
)
return f"{self.name}: {detections_str}"
cdef format_time(self, ms): cdef format_time(self, ms):
# Calculate hours, minutes, seconds, and hundreds of milliseconds. # Calculate hours, minutes, seconds, and hundreds of milliseconds.
h = ms // 3600000 # Total full hours. h = ms // 3600000 # Total full hours.
+1
View File
@@ -7,6 +7,7 @@ cdef class Inference:
cdef object on_annotation cdef object on_annotation
cdef Annotation _previous_annotation cdef Annotation _previous_annotation
cdef AIRecognitionConfig ai_config cdef AIRecognitionConfig ai_config
cdef object class_names
cdef bint stop_signal cdef bint stop_signal
cdef str model_input cdef str model_input
+3 -2
View File
@@ -26,6 +26,7 @@ cdef class Inference:
print(f'AI detection model input: {self.model_input} ({self.model_width}, {self.model_height})') print(f'AI detection model input: {self.model_input} ({self.model_width}, {self.model_height})')
model_meta = self.session.get_modelmeta() model_meta = self.session.get_modelmeta()
print("Metadata:", model_meta.custom_metadata_map) print("Metadata:", model_meta.custom_metadata_map)
self.class_names = eval(model_meta.custom_metadata_map["names"])
cdef preprocess(self, frames): cdef preprocess(self, frames):
blobs = [cv2.dnn.blobFromImage(frame, blobs = [cv2.dnn.blobFromImage(frame,
@@ -75,11 +76,9 @@ cdef class Inference:
if det1_index in filtered_out_indexes: if det1_index in filtered_out_indexes:
continue continue
det1 = detections[det1_index] det1 = detections[det1_index]
print(f'det1 size: {det1.w}, {det1.h}')
res = det1_index res = det1_index
for det2_index in range(det1_index + 1, len(detections)): for det2_index in range(det1_index + 1, len(detections)):
det2 = detections[det2_index] det2 = detections[det2_index]
print(f'det2 size: {det2.w}, {det2.h}')
if det1.overlaps(det2): if det1.overlaps(det2):
if det1.confidence > det2.confidence or ( if det1.confidence > det2.confidence or (
det1.confidence == det2.confidence and det1.cls < det2.cls): # det1 has higher confidence or lower class_id det1.confidence == det2.confidence and det1.cls < det2.cls): # det1 has higher confidence or lower class_id
@@ -158,6 +157,7 @@ cdef class Inference:
if self.is_valid_annotation(annotation): if self.is_valid_annotation(annotation):
_, image = cv2.imencode('.jpg', frame) _, image = cv2.imencode('.jpg', frame)
annotation.image = image.tobytes() annotation.image = image.tobytes()
print(annotation.to_str(self.class_names))
self.on_annotation(cmd, annotation) self.on_annotation(cmd, annotation)
self._previous_annotation = annotation self._previous_annotation = annotation
@@ -183,6 +183,7 @@ cdef class Inference:
annotation = Annotation(image_paths[i], timestamps[i], detections) annotation = Annotation(image_paths[i], timestamps[i], detections)
_, image = cv2.imencode('.jpg', frames[i]) _, image = cv2.imencode('.jpg', frames[i])
annotation.image = image.tobytes() annotation.image = image.tobytes()
print(annotation.to_str(self.class_names))
self.on_annotation(cmd, annotation) self.on_annotation(cmd, annotation)
+1
View File
@@ -0,0 +1 @@
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI5N2U5MWI2OC1hNmRlLTQ3YTgtOTgzYi0xOTU3YzViNDQ2MTkiLCJ1bmlxdWVfbmFtZSI6ImFkbWluLXJlbW90ZUBhemFpb24uY29tIiwicm9sZSI6IkFwaUFkbWluIiwibmJmIjoxNzM5MTk5MzM1LCJleHAiOjE3MzkyMTM3MzUsImlhdCI6MTczOTE5OTMzNSwiaXNzIjoiQXphaW9uQXBpIiwiYXVkIjoiQW5ub3RhdG9ycy9PcmFuZ2VQaS9BZG1pbnMifQ.HmfaeFn9T_eJuRZSjBV_EhiSB41ippBVPLRggC7gBZk