Python:sklearn PCA意味着转换为opencv2 RGB图像

时间:2015-12-02 22:07:22

标签: python opencv scikit-learn pca

Iam尝试将PCA转换为RGB,但我收到错误:cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp:3642: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor此错误是由行mean = cv2.cvtColor(mean, cv2.COLOR_RGB2BGR)

引起的

我的代码:

def featureExtract(self, images, dim, k = 4):
    faces_rowvecs = []
    nDim = None
    for image in images:
        image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
        nDim = image.shape 
        faces_rowvecs.append(image.flatten("C").copy())
    faceData = np.vstack(faces_rowvecs)
    pca = PCA(n_components=k)
    pca.fit(faceData)

    mean = pca.mean_
    mean = mean.reshape(nDim[0],nDim[1], nDim[2])
    mean = cv2.normalize(mean, dim, norm_type=cv2.NORM_MINMAX)
    mean= cv2.cvtColor(mean, cv2.COLOR_RGB2BGR)

0 个答案:

没有答案