【发布时间】:2020-04-10 02:56:40
【问题描述】:
我正在使用 opencv-python 4.2.0.32 和 Python 3.7.4。
当我在 DTree 模型上调用 train() 时,我的程序因错误而终止:
terminate called after throwing an instance of 'std::length_error'
what(): vector::reserve
Aborted (core dumped)
当我使用 KNearest 模型而不是 DTree 时,该代码有效。 这看起来有点像here 描述的行为,但我使用的是更新版本的 OpenCV,所以可能还有其他事情发生?
重现行为的代码示例:
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)
【问题讨论】: