Ask Your Question

How to load CV2.ml_Knearest pre-trained classifier back into Python memory?

asked 2019-08-01 05:15:55 -0600

Andrew.K gravatar image

Hello! I encountered with the problem with loading pre-trained 'cv2.ml_KNearest' classifier into Python 3.6. I trained and saved 'cv2.ml_KNearest' classifier to the HDD using the following code:

kNearest =
kNearest.train(img_array_train,, img_classes_labels)'KNN_Trained_Model.xml')

but I can't find anywhere the command or approach to get it back from ''KNN_Trained_Model.xml'' file to python memory as "" classifier object. I know that fore some reasons method "" has not been implemented in python OpenCV libraries for Python 3.x. I would appreciate any help with this.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-08-01 05:53:38 -0600

LBerger gravatar image

updated 2019-08-01 05:54:05 -0600

You must use opencv 4.1.1

edit flag offensive delete link more


Thank you! I also found this method before, however the most recent version that available in the OpenCV repository is just

Andrew.K gravatar imageAndrew.K ( 2019-08-01 06:19:43 -0600 )edit

sorry I push in april 17 and lastest version april 11 Wait for next release

LBerger gravatar imageLBerger ( 2019-08-01 06:28:13 -0600 )edit

Thank you very much! Next release totally suits me.

Andrew.K gravatar imageAndrew.K ( 2019-08-01 07:47:51 -0600 )edit

Question Tools

1 follower


Asked: 2019-08-01 04:53:56 -0600

Seen: 1,183 times

Last updated: Aug 01 '19