I'm using opencv-python 4.2.0.32 and Python 3.7.4.
When I call train() on a DTree model, my program terminates with an error:
terminate called after throwing an instance of 'std::length_error'
what(): vector::reserve
Aborted (core dumped)
The code works when I use a KNearest model instead of DTree. This looks a bit like the behaviour described here but I use a more recent version of OpenCV so maybe there's something else going on?
Code sample to reproduce behaviour:
import numpy as np
import cv2
samples = np.ndarray((5, 2), np.float32)
labels = np.zeros((5, 1), dtype=np.float32)
# This works
model_knn = cv2.ml.KNearest_create()
model_knn.train(samples=samples, layout=cv2.ml.ROW_SAMPLE, responses=labels)
# This terminates with an error
model_dtree = cv2.ml.DTrees_create()
model_dtree.train(samples=samples, layout=cv2.ml.ROW_SAMPLE, responses=labels)