Object recognition

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Object recognition

Post by hahobson »

Hello, I have installed ZM and the Event Server. How would I add a simple HAAR Cascade application? This is what I have working:

Code: Select all

import numpy as np
import cv2
dog_cascade = cv2.CascadeClassifier("cascade.xml")
cap = cv2.VideoCapture("rtsp://192.168.0.51:8080/h264_ulaw.sdp")

while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    dog = dog_cascade.detectMultiScale(gray, 1.05, 11)

    for (x,y,w,h) in dog:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]

    cv2.imshow('img',img)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()
I have looked at the objectconfig.ini file, but not sure how to add code to Zoneminder. Thank you!
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Object recognition

Post by asker »

This is not something you can turn on via a config - will require code level integration.
Here is the high level flow to get you started:

1. You will need to make these changes in pyzm
2. pyzm/ml/object.py is the wrapper for all things object detection related (person is an object in this context)
3. You will need to add a new 'object_framework' type called, say, 'hog' and invoke your class there (in object.py)
4. Write your hog class similar to other classes
5. Make sure it is installed as part of setup.py

To make this more concrete, take a look at this pull request, where a contributor added AWS rekognition support.

Note that at one point, I had hog support built in, but removed it. You'll see hog.py inside pyzm/ml which you can modify.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Post Reply