Is there a recommended framework for conducting evaluation/test and parameter tuning in OpenCV similar to other frameworks such as scikit-learn?
I’m building an object detection framework that may involve some tracking of multiple objects in order to reduce false positive detections (ie. ignore it unless it is present in multiple frames, ignore it unless it is growing in foreground, etc.). Am testing multiple background subtraction methods.
Would like to loop through multiple parameter inputs and also background subtractors which use different parameters in order to produce a final score which is likely a precision metric. Something like this pseudocode using sklearn techniques and methods?
import cv2 as cv
from sklearn.metrics import precision_score
from sklearn.model_selection import ParameterGrid
#frame by frame labeled ground truth on presence or absence of detected object
y_true = [True, False, True, False, ..... etc.]
def detect_something(gray, **kwargs):
## background subtraction evolution, find contours, draw boxes, etc
pass
parameters = dict(
param1 = (1,2, 5),
param2 = (500, 700, 900)
param3 = (400, 500, 600)
)
scores = []
for param in ParameterGrid(parameters):
cap = cv.VideoCapture('vtest.avi')
# maybe initialize something like background subtractor
y_pred = []
while cap.isOpened():
ret, frame = cap.read()
pred = False
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
ret, img = detect_something(gray, **param)
if ret:
pred=True
y_pred.append(pred)
cv.imshow('frame', img)
if cv.waitKey(1) == ord('q'):
break
score = precision_score(y_true, y_pred)
scores.append(score)
cap.release()
cv.destroyAllWindows()