agentmorris / MegaDetector

MegaDetector is an AI model that helps conservation folks spend less time doing boring things with camera trap images.
MIT License
117 stars 26 forks source link

Video processing: add frame number information to frame detections #133

Closed PetervanLunteren closed 5 months ago

PetervanLunteren commented 5 months ago

With these minor changes, the frame number on which the detection is based will be saved.

This enables more options for postprocessing, such as exporting and visualising the frame with the highest confidence. That way users will not have to watch the entire video, but just look at that one frame.

I've tested it in combination with EcoAssist and it works. I haven't tested it with every different combination of arguments, but I don't expect there to be any errors, as you're just adding a key:value pair that no existing code relies on.

Before:

  {
   "file": "video.mp4",
   "detections": [
    {
     "category": "1",
     "conf": 0.974,
     "bbox": [
      0.2937,
      0.5083,
      0.5859,
      0.4388
     ]
    }
   ]
  }

After:

  {
   "file": "video.mp4",
   "detections": [
    {
     "category": "1",
     "conf": 0.974,
     "bbox": [
      0.2937,
      0.5083,
      0.5859,
      0.4388
     ],
     "frame_number": "156"
    }
   ]
  }
agentmorris commented 5 months ago

Thanks for this, @PetervanLunteren!

Merged with minor modifications in [#134]. As I mentioned in email, my changes don't impact the output, other than using an int rather than a string for the frame number, which is probably a no-op for you, since you likely immediately convert it to an int anyway.