ZoneMinder / pyzm

Python API, Log, Event Server and Memory wrapper for ZoneMinder
GNU General Public License v2.0
31 stars 20 forks source link

take into account confidences when selecting final match for most* strategy #36

Open hqhoang opened 2 years ago

hqhoang commented 2 years ago

For frame_strategy of "most", "most_models", and "most_unique", since we have to loop through all the matches anyway, might as well take into consideration the confidences to pick out the best. For example, if three matches all have 1 detected object, the match with the highest confidence should be selected instead of the first one.

It's obviously more complicated when there are multiple detected objects, perhaps compare the sum of the confidences as a simple criteria. Something like this?

for idx,item in enumerate(all_matches):
  if  ((frame_strategy == 'first') or
  ((frame_strategy == 'most') and (len(item['labels']) > len(matched_l))) or
  ((frame_strategy == 'most') and (len(item['labels']) == len(matched_l)) and (sum(matched_c) < sum(item['confidences']))) or
  ((frame_strategy == 'most_models') and (len(item['detection_types']) > len(matched_detection_types))) or
  ((frame_strategy == 'most_models') and (len(item['detection_types']) == len(matched_detection_types)) and (sum(matched_c) < sum(item['confidences']))) or
  ((frame_strategy == 'most_unique') and (len(set(item['labels'])) > len(set(matched_l)))) or
  ((frame_strategy == 'most_unique') and (len(set(item['labels'])) == len(set(matched_l))) and (sum(matched_c) < sum(item['confidences'])))):

I've been testing the above mod in my local installation and it seems to work well in picking out the best detected frame for better accuracy.

baudneo commented 2 years ago

I will add this to pyzm and test. I don't know if my code will replace the current libs or if it will be a diff branch but pyzm, ZMES and MLAPI will be receiving a fairly robust makeover shortly.

Any other observations or improvements you would like to see?

hqhoang commented 2 years ago

I have a few ideas from my setup but I don't know much about Perl. I'm learning Python slowly so if the new codes will be in Python, I probably can contribute a bit, especially front-end responsive design. Submitting another issue/request for "park_zone" shortly.

baudneo commented 2 years ago

For the time being the object detection logic is all in python. The websocket server, "event SHM scraper" and the daemon are in the Perl code.

I will implement some of these ideas after testing. I just need to setup a camera to monitor vehicles to create a situation where I can use match_past_detections and test it properly.