Estou tentando utilizar Python com OpenCV para depois fazer uma classificação. Porém, na hora que vou fazer popular o objeto, tenho o seguinte erro:
ValueError: cannot reshape array of size 72000 into shape (1,24000)
Entendo que é um erro do tamanho do array, mas o que estou fazendo de errado na hora de criar o array?
Segue o código completo:
import sys
import numpy as np
import cv2
import os
MIN_CONTOUR_AREA = 100
RESIZED_IMAGE_WIDTH = 200
RESIZED_IMAGE_HEIGHT = 120
def main():
npaFlattenedImages = np.empty((0, RESIZED_IMAGE_WIDTH * RESIZED_IMAGE_HEIGHT))
intValidChars = [0,1,2,3]
for npaContour in intValidChars:
name = "characters/MANDATOR-42-"+str(npaContour)+".png";
print(name)
imgTrainingNumbers = cv2.imread(name)
imgROIResized = cv2.resize(imgTrainingNumbers, (RESIZED_IMAGE_WIDTH, RESIZED_IMAGE_HEIGHT))
x,y,z = imgTrainingNumbers.shape
print("Shape: " + str(x) +"|"+ str(y) + "|" + str(z))
if(imgTrainingNumbers is None):
print("Not Found")
cv2.imshow("Imagem", imgROIResized)
intChar = cv2.waitKey(0)
intClassifications = []
intClassifications.append(int(chr(intChar)))
npaFlattenedImage = imgROIResized.reshape((1,RESIZED_IMAGE_WIDTH * RESIZED_IMAGE_HEIGHT))
npaFlattenedImages = np.append(npaFlattenedImages, npaFlattenedImage, 0)
# end for
fltClassifications = np.array(intClassifications, np.float32)
npaClassifications = fltClassifications.reshape((fltClassifications.size, 1))
print ("training complete")
np.savetxt("classifications__.txt", npaClassifications)
np.savetxt("flattened_images__.txt", npaFlattenedImages)
cv2.destroyAllWindows()
return
###################################################################################################
if __name__ == "__main__":
main()
# end if