Ask Your Question
0

mat type = 15 is not supported

asked 2017-07-28 05:06:51 -0600

updated 2017-07-28 05:12:25 -0600

berak gravatar image

I got an error while changing an eigenvector as an image

def getEigenVectorsAndEigenValues(covarianceMatx):
    print("Compute Eigens...")
    logger.info("Compute Eigens...")
    eigenSolution = np.linalg.eig(covarianceMatx)
    # print("len eigenSolution", len(eigenSolution))
    # print("eigenSolution", eigenSolution)
    eigenValues = eigenSolution[0]
    # print("eigenValues", len(eigenValues))
    eigenVectors = eigenSolution[1]
    # print("eigenVectors", type(eigenVectors))
    # print("eigenVectors-1", type(eigenVectors[0]))
    # resized = cv2.resize(eigenVectors[2],(512,512))
    # cv2.imshow("eigen",resized)
    # cv2.waitKey()
    sort = eigenValues.argsort()[::-1]
    eigenValues = eigenValues[sort]
    eigenVectors = eigenVectors[:, sort]
    # Each eigenvector has the same dimensionality(number
    # of components) as the original images, and thus
    # can itself be seen as an image
    logger.info("shape eigenValues" + str(np.asarray(eigenValues).shape))
    logger.info("shape eigenVectors" + str(np.asarray(eigenVectors).shape))
    logger.info("shape eigenVectors[0]" + str(np.asarray(eigenVectors[0]).shape))
    logger.info("shape eigenVectors[0][0]" + str(np.asarray(eigenVectors[0][0]).shape))
    logger.info("value in eigenVectors" + str(eigenValues))

    # for i in range(0, 4095):
    for i in range(0, 361):
        imageFromVector = np.asarray(eigenVectors[i])
        imageFromVector = imageFromVector.reshape((19, 19))
        imageFromVector2 = np.array(np.dstack([imageFromVector.real,imageFromVector.imag])) # What I added
        print("imageFromVector shape", imageFromVector.shape)
        print("imageFromVector type", type(imageFromVector))
        cv2.imshow("imageFromVector", imageFromVector2) # Error in here!

        cv2.waitKey()
        # imageFromVector.reshape((64, 64))
        file = str(i) + ".jpg"
        cv2.imwrite(filename=file, img=imageFromVector)

    # resized = cv2.resize(eigenVectors[0], (512, 512))
    # cv2.imshow("eigen", resized)
    # cv2.waitKey()

    logger.info("Compute Eigens... Done")
    return eigenVectors, eigenValues

before I added imageFromVector2 = np.array(np.dstack([imageFromVector.real,imageFromVector.imag])), show an error like this image description

after I added that code, it shown

File "E:/PROJECT_FOLDER/PYTHON/PKLBPPT/PCA-with-VJ.py", line 169, in getEigenVectorsAndEigenValues
    cv2.imshow("imageFromVector", imageFromVector2)
cv2.error: D:\Build\OpenCV\opencv-3.2.0\modules\imgcodecs\src\utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

Anyone knows what's wrong with this code?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-28 05:25:47 -0600

berak gravatar image
  • cv2.imshow() does not support 2 channel images. you added some weird code there, which probably just should be deleted.

  • cv2.imwrite() does not support float images, you'll have to convert to np.uint8 (and probably scale it)

edit flag offensive delete link more

Comments

1

Just to add that if OP actually wants to actually save the float values, he can use cv2.FileStorage object

Pedro Batista gravatar imagePedro Batista ( 2017-07-28 07:24:08 -0600 )edit

Thank you so much!! It works

otakbeku gravatar imageotakbeku ( 2017-07-30 20:24:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-28 05:06:51 -0600

Seen: 2,176 times

Last updated: Jul 28 '17