Python to Java: KNearest training / numpy.loadtxt()

asked 2019-08-05 21:08:46 -0600

Hi, I am currently converting an character recognition script from python to java. In Python I used

classifications = numpy.loadtxt("classifications.txt", numpy.float32)
flattenedImages = numpy.loadtxt("flattened_images.txt", numpy.float32)     

classifications = classifications.reshape((classifications.size, 1))

kNearest = cv2.ml.KNearest_create()   
kNearest.train(fattenedImages, cv2.ml.ROW_SAMPLE, classifications)

to load my training data from file. My "classifications.txt" looks like this:

8.500000000000000000e+01
8.500000000000000000e+01
8.500000000000000000e+01
...

An my "flattenedImages.txt" like this:

2.550000000000000000e+02 2.550000000000000000e+02 2.550000000000000000e+02 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 ...

Does anyone got an idea how to do the same thing in java?

edit retag flag offensive close merge delete