Page 1 of 1

Object recognition

Posted: Wed Nov 24, 2021 12:03 pm
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!

Re: Object recognition

Posted: Thu Nov 25, 2021 12:03 pm
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.