Ask Your Question
0

knn train erro

asked 2017-05-23 18:26:26 -0600

Ronei gravatar image
Mat m = Mt.converterParaMat(Mt.imagemFinal);
    m.convertTo(m, CvType.CV_32F);
    Imgproc.resize(m, m, tamanho);//tamanho 120x120
    m = m.reshape(1,200); //tamanho 200x216
    trainDados.push_back(m);
    trainLabs.add(1);

Mat xx = new Mat();
    xx = Converters.vector_int_to_Mat(trainLabs);
    xx.convertTo(xx, CvType.CV_32F);
    Imgproc.resize(xx, xx, tamanho); //tamanho 120x120
    xx.reshape(1,200); //tamanho 120x120 - não altera para 200x216?
    kn.train(trainDados, Ml.ROW_SAMPLE , xx);

retorna o erro

OpenCV Error: Assertion failed ((layout == ROW_SAMPLE && responses.rows == nsamples) || (layout == COL_SAMPLE && responses.cols == nsamples)) in cv::ml::TrainDataImpl::setData, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\ml\src\data.cpp, line 290 Exception in thread "AWT-EventQueue-0" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\ml\src\data.cpp:290: error: (-215) (layout == ROW_SAMPLE && responses.rows == nsamples) || (layout == COL_SAMPLE && responses.cols == nsamples) in function cv::ml::TrainDataImpl::setData ] at org.opencv.ml.StatModel.train_0(Native Method) at org.opencv.ml.StatModel.train(StatModel.java:74)

java 8, opencv 3.2, windows 10

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2017-05-23 23:50:13 -0600

berak gravatar image

updated 2017-05-24 00:36:01 -0600

here's the problem:

 m = m.reshape(1,200); // 200 rows

this makes a "vertical" vector, if you wanted Ml.ROW_SAMPLE you need a "horizontal" one:

 m = m.reshape(1,1); // 1 row

it also needs:

xx = xx.reshape(1,1);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-23 18:26:26 -0600

Seen: 1,851 times

Last updated: May 24 '17