ljmerza / frigate_plate_recognizer

Identify license plates via Plate Recognizer and add them as sublabels to Frigate
128 stars 17 forks source link

Use hi-res stream for plate recognition. #36

Open RutgerDiehard opened 9 months ago

RutgerDiehard commented 9 months ago

I have a 4K camera that's used to capture person and car objects on my drive. Object detection is fairly reliable using the low-res stream from the camera fed to Frigate. However, plate recognition is very unreliable due to the low-res snapshot.jpg from Frigate. Other Frigate integrations (such as Double-Take for face recognition) allows high-res jpg captures directly from a camera for the highest quality processing once a Frigate snapshot.jpg event is received.

Is this something that is available for plate-recongnizer?

kyle4269 commented 9 months ago

Sounds to me like you need to use the main stream in frigate config.

RutgerDiehard commented 9 months ago

Running detection on the main stream in Frigate is enormously CPU intensive. Even though I have tuned the installation as per Frigate documentation, using this just for plate recognizer when object detection itself is working fine on the low-res stream is a massive waste of resources.

Double-take listens for events from Frigate using the low-res stream and when it receives one, accesses the camera direct for a high-res snapshot which it uses for face recognition - discussion here.

This would be a great addition to plate-recognizer and I'm sure a lot of people would use it.

atv2016 commented 8 months ago

I agree with @RutgerDiehard, rather then using the snapshot it would be better to use the /clips/camera-eventid-clean.png, this is the full resolution image and also without any bounding box. I would say there is a much better chance of getting a plate on that then those grainy snapshots.

kyle4269 commented 8 months ago

I agree with @RutgerDiehard, rather then using the snapshot it would be better to use the /clips/camera-eventid-clean.png, this is the full resolution image and also without any bounding box. I would say there is a much better chance of getting a plate on that then those grainy snapshots.

I think the problem with that option is, the clean png isn't available until the event has ended. I guess we could use it if it's available and if not use the snapshot..

atv2016 commented 8 months ago

Hmm that's a good point. When does the event end, is it when a car becomes stationary or out of the picture? Maybe we can use snapshots for cars in motion and the full resolution image for cars that are stationary.

kyle4269 commented 8 months ago

"The event ends if the tracked object goes missing for more frames than the configured max_disappeared value." That was from Blake a while ago

atv2016 commented 8 months ago

Cool. Trying to play around with the snapshot and removing the bounding box, but I still see a object bounding box even if I do : http://192.168.50.34:5000/api/events/1710236252.067698-5mdny9/snapshot.jpg?bbox=0

kyle4269 commented 8 months ago

Cool.

Trying to play around with the snapshot and removing the bounding box, but I still see a object bounding box even if I do :

http://192.168.50.34:5000/api/events/1710236252.067698-5mdny9/snapshot.jpg?bbox=0

That'll only work while the event is in progress unfortunately.

atv2016 commented 8 months ago

Ah ok - yeah I figured out as much. Guess I'll have to disable bounding box in snapshots per camera feed.

Cheers.

kyle4269 commented 8 months ago

That's what I do. I also run my LPR camera on the main stream to get the best quality image for processing.

atv2016 commented 8 months ago

What LPR camera are you using ?

kyle4269 commented 8 months ago

What LPR camera are you using ?

https://empiretech01.com/products/empiretech-2mp-wdr-ir-bullet-ai-network-bullet-camera-ipc-hfw5241e-z12e?variant=46858538909981

atv2016 commented 8 months ago

Very nice, that's the exact one I was looking at as well. 60mm varifocal I believe ? And not un-affordable either. How is it working for you ?

I think the biggest issue with these is getting the angle right, but maybe not so much a problem with these.

kyle4269 commented 8 months ago

Once I got all the camera settings dialed in for my environment, it's been an amazing camera for LPR. You can't go wrong with it especially if you're willing to play around with the settings to get it correct. See the below link for discussions about it.

https://ipcamtalk.com/threads/mini-review-5241-z12e-s2-replacement-for-the-5241-z12e.71898/

chrisborell commented 4 months ago

Hi! Couldn't we implement the

  events:
    front_gate:
      # mqtt disabled
      mqtt: false
      # picture to be used
      image:
        width: 1280
        height: 720
        latest: http://192.168.1.174:1984/api/frame.jpeg?src=front_gate

like doubletake has - to enable high-res snapshots from an external snapshot URL? This way the mainstream doesn't need to be used?

https://github.com/jakowenko/double-take/issues/102

RutgerDiehard commented 3 months ago

As an update to this, I've managed to work around the low resolution of the Reolink substream (and poor plate recognition success) by using ffmpeg to re-encode the main 4k stream into a lower resolution detect stream (1280x720) - but still higher resolution than the substream from the camera - that plate recognition is much, much happier with. I do this in the go2rtc section of the Frigate config:

go2rtc:
  streams:
    Front_Door:
      - ffmpeg:rtsp://USER:PASSWORD@CAMERA-IP:554/h265Preview_01_main#video=copy#audio=copy#audio=aac
    Front_Door_Sub:
      - ffmpeg:Front_Door#video=h264#width=1280#height=720#raw=-fpsmax 10#hardware=vaapi

By using hardware=vaapi (for Intel GPUs), I can get the GPU to do the encoding so the CPU is unaffected.

The camera section in Frigate config then looks like this:

cameras:
  Front_Door:
    ffmpeg:
      hwaccel_args: preset-vaapi
      output_args:
        record: preset-record-generic-audio-aac
      inputs:
        - path: rtsp://127.0.0.1:8554/Front_Door
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/Front_Door_Sub
          input_args: preset-rtsp-restream
          roles:
            - detect