【问题标题】:How to compress single array using Python OpenCV cv2.PCAProject如何使用 Python OpenCV cv2.PCAProject 压缩单个数组
【发布时间】:2016-05-03 18:15:07
【问题描述】:

背景:假设我已经使用 PCACompute 在 python 中训练了一个 PCA,如下所示:

import numpy as np
import cv2 as cv

# generate some random data
data = np.random.sample(128)
for x in xrange(63): data = np.vstack((data, np.random.sample(128)))
print data.shape # (64, 128) i.e. 64 arrays of 128 dimensions

# train the PCA
mean, eigenvectors = cv.PCACompute(data, maxComponents=32)
print mean.shape # (1, 128)
print eigenvectors.shape # (32, 128)

问题:现在我有一个要使用 PCA 压缩的数组

sample = np.random.sample(128)
print sample.shape # (128,)

compressed_sample = cv.PCAProject(sample, mean, eigenvectors)

OpenCV 错误:断言失败 (mean.data && eigenvectors.data && ((mean.rows == 1 && mean.cols == data.cols) || (mean.cols == 1 && mean.rows == data.rows)))

【问题讨论】:

    标签: python opencv pca


    【解决方案1】:

    解决方案:输入这个我解决了,如果其他人遇到同样的问题,不妨继续发帖。

    sample = sample.reshape((1,128))
    compressed_sample = cv.PCAProject(sample, mean, eigenvectors)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2017-02-22
      相关资源
      最近更新 更多