zoneminder icon indicating copy to clipboard operation
zoneminder copied to clipboard

Integrate OpenCV's image detection into zm_monitor.cpp as an alternate option

Open pliablepixels opened this issue 6 years ago • 18 comments

OpenCV offers some "reasonable" methods to detect people. They are not as accurate as CNNs and use HOGs but are of orders of magnitude faster. The code is straight forward, for example, this. OpenCV code is very portable, and in C++, and therefore integration into ZM is not hard. (I don't feel like investigating - someone who knows zm_monitor.cpp and how ZM handles image buffers should be able to do it much faster than me)

There are multiple profiles to choose from (different XML files)

The request: a) Integrate OpenCV with ZM b) Select "Person Detection" as a scheme as a detection algorithm as an alternate to "Pixels/Filter/Blob" and basically replicate the functionality provided in the link above. c) Ability to specify a "frame interval" -> which will basically decide how often this logic will be used. In other words, even if I select the monitor FPS as say 5, I should be able to select "2" here, which will mean detection to be applied on the 1st, 3rd, 5th frames - for more speed control without affecting live fps d) Draw a bounding box around the person detected in frame (Again, already part of the sample code)

3rd party work a) This company did some early work here in 2011, if it helps. Licensed under GPL.

Future Enhancement Not a necessary condition for the bounty: a) Ability to make item b) above in request section more flexible. Let me select any XML profile in OpenCV so I can tweak my model.

I'll be putting in a $100 bounty for this.

pliablepixels avatar Jul 02 '18 15:07 pliablepixels

bounty added

pliablepixels avatar Jul 02 '18 15:07 pliablepixels

So I have merge the CVisionLabs work into my opencv branch. However the plugin code is for an ancient version of opencv.... so I think I'll be updating that to version 3.

connortechnology avatar Aug 11 '18 15:08 connortechnology

do you have a branch I can track/test?

pliablepixels avatar Aug 11 '18 16:08 pliablepixels

my opencv branch

connortechnology avatar Aug 11 '18 17:08 connortechnology

Since version 3.4.2 of OpenCV, it looks like it now supports the YOLOv3 DNN detector as well. Below link has some C++ and python examples. https://www.learnopencv.com/deep-learning-based-object-detection-using-yolov3-with-opencv-python-c/

TheSwert avatar Aug 25 '18 16:08 TheSwert

I'm going to revise some of the asks based on integrating both OpenCV approaches in the ZM event notification server:

I originally said:

b) Select "Person Detection" as a scheme as a detection algorithm as an alternate to "Pixels/Filter/Blob" and basically replicate the functionality provided in the link above. c) Ability to specify a "frame interval" -> which will basically decide how often this logic will be used. In other words, even if I select the monitor FPS as say 5, I should be able to select "2" here, which will mean detection to be applied on the 1st, 3rd, 5th frames - for more speed control without affecting live fps

Based on my experience actually trying to get it working:

  • Many (if not most) users of ZM are not running a GPU
  • OpenCV SVM HOG is very fast but not quite accurate. It keeps identifying my water heater as a "person" (On an Intel Xeon 3.16GHz 4Core machine with no GPU HOG takes 0.25s)
  • OpenCV DNN with Yolov3 (80 labels) but with Tiny-Yolo weight/config is much more accurate and takes almost the same time as HOG (On an Intel Xeon 3.16GHz 4Core machine with no GPU this takes 0.34s)
  • OpenCV DNN with Yolov3 (80 labels) and yolov3 config /weight files is most accurate but without a GPU takes 10x the time as HOG (On an Intel Xeon 3.16GHz 4Core machine with no GPU YoloV3 takes 2.4s)

To make this practically useful, I'd like to suggest that "Person detection" is implemented as 2 options:

a) As a replacement for "motion" - that way people don't have to worry about defining zones and configuring its accuracy b) As a "after motion" analysis so that people can configure some basic but very lenient motion system and only trigger person detect if motion occurred first

pliablepixels avatar Oct 08 '18 19:10 pliablepixels

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 09 '18 20:12 stale[bot]

anyone know if these if going to do ?

3lk0k0 avatar Dec 24 '18 17:12 3lk0k0

I started on it... but there is lots more to do.

connortechnology avatar Dec 24 '18 17:12 connortechnology

There is also some work done in this project for face recognition https://github.com/goruck/smart-zoneminder by goruck

jysaloma avatar Feb 10 '19 17:02 jysaloma

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 11 '19 18:04 stale[bot]

Is this still in progress?

cleverinx avatar Dec 01 '19 12:12 cleverinx

bountysource will take this money on July 1st. Either contact bountysource to redirect your funds, or alternatively, I can close this out, collect the bounty, and I will hold the money until this issue is properly closed.

connortechnology avatar Jun 17 '20 15:06 connortechnology

I’d prefer you just collect for the money I added.

pliablepixels avatar Jun 17 '20 20:06 pliablepixels

@connortechnology Is implementing OpenCV into Zoneminder still on the list of things to do?

Rayn0r avatar Nov 10 '20 05:11 Rayn0r

Yes

connortechnology avatar Nov 10 '20 14:11 connortechnology

@connortechnology Hi is this still open please?

dirkarnez avatar Sep 04 '23 14:09 dirkarnez

Yes it's still open. I'm not sure it's a good idea, as I think AI should be happening in it's own process.

connortechnology avatar Sep 05 '23 20:09 connortechnology