2
I’m trying to use Python with Opencv to then make a classification. However, at the time I will make popular the object, I have the following error:
Valueerror: cannot reshape array of size 72000 into Shape (1,24000)
I understand it is an array size error, but what I am doing wrong when creating the array?
Follow the full code:
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
Play the whole error message, so it is easier to try to help. Detail: you are mixing camelCase with snake_case, the convention in pyhthon is lower_snake_case. :-)
– Sidon