Ask Your Question

otakbeku's profile - activity

2017-07-30 20:24:54 -0500 commented answer mat type = 15 is not supported

Thank you so much!! It works

2017-07-28 05:06:51 -0500 asked a question mat type = 15 is not supported

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?

2017-07-23 22:48:36 -0500 asked a question Error on VTK; nullptr was not declared

I had an error when build. This is an error:

Scanning dependencies of target opencv_viz_pch_dephelp [ 31%] Building CXX object modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/opencv_viz_pch_dephelp.cxx.o In file included from /usr/local/include/vtk-8.1/vtkGenericDataArray.h:72:0, from /usr/local/include/vtk-8.1/vtkAOSDataArrayTemplate.h:35, from /usr/local/include/vtk-8.1/vtkIntArray.h:33, from /usr/local/include/vtk-8.1/vtkCellTypes.h:42, from /usr/local/include/vtk-8.1/vtkPolyData.h:64, from /usr/local/include/vtk-8.1/vtkPolyDataAlgorithm.h:36, from /usr/local/include/vtk-8.1/vtkAppendPolyData.h:35, from /root/opencv/modules/viz/src/precomp.hpp:56, from /root/opencv/build/modules/viz/opencv_viz_pch_dephelp.cxx:1: /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h:72:5: warning: identifier ‘nullptr’ is a keyword in C++11 [-Wc++0x-compat] : AssociatedArray{nullptr}, SortedArray(nullptr), ^ /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h: In constructor ‘vtkGenericDataArrayLookupHelper<arraytypet>::vtkGenericDataArrayLookupHelper()’: /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h:72:22: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 : AssociatedArray{nullptr}, SortedArray(nullptr), ^ /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h:72:23: error: ‘nullptr’ was not declared in this scope : AssociatedArray{nullptr}, SortedArray(nullptr), ^ /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h:73:15: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 FirstValue{nullptr}, SortedArraySize{0} ^ /usr/local/include/vtk-8.1/vtkGenericDataArrayLookupHelper.h:73:41: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 FirstValue{nullptr}, SortedArraySize{0} ^ modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/build.make:62: recipe for target 'modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/opencv_viz_pch_dephelp.cxx.o' failed make[2]: * [modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/opencv_viz_pch_dephelp.cxx.o] Error 1 CMakeFiles/Makefile2:5698: recipe for target 'modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/all' failed make[1]: [modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/all] Error 2 Makefile:160: recipe for target 'all' failed make: ** [all] Error 2

image description

I had no idea what is wrong. I'm using ubuntu 16.04, VTK 8.0, OpenCV 3.2 (Contrib version too), work on virtualenv