OpenCV 3.0 Python SVM示例

OpenCV 3.0 Python SVM示例,python,opencv,machine-learning,svm,opencv3.0,Python,Opencv,Machine Learning,Svm,Opencv3.0,是opencv python 3.0中的SVM示例。请任何人解释一下循环中的process_hog()函数的内部操作。提前感谢 def preprocess_hog(digits): samples = [] for img in digits: gx = cv2.Sobel(img, cv2.CV_32F, 1, 0) gy = cv2.Sobel(img, cv2.CV_32F, 0, 1) mag, ang = cv2.car

是opencv python 3.0中的SVM示例。请任何人解释一下循环中的process_hog()函数的内部操作。提前感谢

def preprocess_hog(digits):
    samples = []
    for img in digits:
        gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
        gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
        mag, ang = cv2.cartToPolar(gx, gy)
        bin_n = 16
        bin = np.int32(bin_n*ang/(2*np.pi))
        bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
        mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
        hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
        hist = np.hstack(hists)

        # transform to Hellinger kernel
        eps = 1e-7
        hist /= hist.sum() + eps
        hist = np.sqrt(hist)
        hist /= norm(hist) + eps

        samples.append(hist)
    return np.float32(samples)
编辑 如果我用hog.compute()代替

它给出了这个错误

Traceback (most recent call last):
  File "handGT.py", line 125, in <module>
    samples = preprocess_hog(digits)
  File "handGT.py", line 110, in preprocess_hog
    return np.float32(samples)
ValueError: setting an array element with a sequence.
回溯(最近一次呼叫最后一次):
文件“handGT.py”,第125行,在
样本=预处理(数字)
文件“handGT.py”,第110行,在预处理中
返回np.32(样本)
ValueError:使用序列设置数组元素。

我要说的是:它计算每个数字的(单块)特征:我明白了。。但是为什么不只计算hog.compute()?我认为这是因为它只计算单个块hog,而不是全功能的hog描述符(有很多带插值的重叠块)。好吧,如果我想为大于10x10的任何对象提取hog特征??那不合适。你能给我推荐一些我能找到她所做的所有步骤细节的文档吗?事实上我不知道。对于任何更大的数字,你都可以使用hog.compute()我将使用它:它计算每个数字的(单个块)特性:我明白了。。但是为什么不只计算hog.compute()?我认为这是因为它只计算单个块hog,而不是全功能的hog描述符(有很多带插值的重叠块)。好吧,如果我想为大于10x10的任何对象提取hog特征??那不合适。你能给我推荐一些我能找到她所做的所有步骤细节的文档吗?事实上我不知道。对于任何更大的问题,都可以使用hog.compute()
Traceback (most recent call last):
  File "handGT.py", line 125, in <module>
    samples = preprocess_hog(digits)
  File "handGT.py", line 110, in preprocess_hog
    return np.float32(samples)
ValueError: setting an array element with a sequence.