2016-04-01 47 views
0

私は自分の画像でSVMをトレーニングし、OpenCVのHOGDescriptorにそれを供給しようとしています。 トレーニングはうまくいくように見えますが、setSVMDetector関数を使ってHOGDescriptorにモデルを渡そうとすると失敗します。トレーニングOpenCV 3.1.0アサーションはcv :: HOGDescriptor :: setSVMDetectorのcheckDetectorSizeに失敗しました

Mat trainingImages = new Mat(); 
    Mat trainingLables = new Mat(); 

    String personsPath = "C:\INRIAPerson\\INRIAPerson\\96X160H96\\Train\\pos"; 

    for (File file : new File(personsPath).listFiles()) { 
     if(file.isFile()){ 
      Mat img = Imgcodecs.imread(file.getPath()); 
      Mat newImg = new Mat(); 
      Imgproc.cvtColor(img, newImg, Imgproc.COLOR_BGR2GRAY); 
      newImg = newImg.reshape(1,1); 

      trainingImages.push_back(newImg); 
      trainingLables.push_back(Mat.ones(new Size(1,1), CvType.CV_32SC1)); 
     } 
    } 


    String nonPersonsPath = "C:\\NRIAPerson\\INRIAPerson\\train_64x128_H96\\neg"; 
    for (File file : new File(nonPersonsPath).listFiles()) { 
     if(file.isFile()){ 
      Mat img = Imgcodecs.imread(file.getPath()); 
      Mat newImg = new Mat(); 
      Imgproc.cvtColor(img, newImg, Imgproc.COLOR_BGR2GRAY); 

      Imgproc.resize(newImg, newImg, new Size(160 , 96)); 
      newImg = newImg.reshape(1,1); 

      trainingImages.push_back(newImg); 
      trainingLables.push_back(Mat.zeros(new Size(1,1), CvType.CV_32SC1)); 
     } 
    } 

    trainingImages.convertTo(trainingImages, CvType.CV_32FC1); 

    SVM trainer = SVM.create(); 
    trainer.setKernel(SVM.LINEAR); 
    trainer.train(trainingImages, Ml.ROW_SAMPLE, trainingLables); 

    HOGDescriptor hog = new HOGDescriptor(new Size(160, 96), new Size(8,8), new Size(4,4), new Size(4,4), 9); 
    Mat supportVector = trainer.getSupportVectors(); 
    hog.setSVMDetector(supportVector); 

エラーメッセージ

libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
libpng warning: iCCP: known incorrect sRGB profile 
OpenCV Error: Assertion failed (checkDetectorSize()) in cv::HOGDescriptor::setSVMDetector, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\objdetect\src\hog.cpp, line 117 
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\objdetect\src\hog.cpp:117: error: (-215) checkDetectorSize() in function cv::HOGDescriptor::setSVMDetector 
] 
    at org.opencv.objdetect.HOGDescriptor.setSVMDetector_0(Native Method) 
    at org.opencv.objdetect.HOGDescriptor.setSVMDetector(HOGDescriptor.java:302) 
    at feature.extraction.App.main(App.java:86) 

ため コードのlibpngはのは、それを行うには何も持って警告かどうかは知りません。 誰かがアイデアを持っているのですか?

答えて

1

私はそれを理解しました。私は画像を訓練し、私は最初に私が2d float array作成supportvector

-rhoを追加するのを忘れないfeatures

    1. 間違ったカップルのことをやりました。 HOGDescriptorクラスのcompute関数を使用して、画像の機能を実装しました。配列でSVMを訓練しました。訓練の後、私はgetDecisionFunction関数を使ってrhoを取得し、それをsupportvectorに追加しました。

  • 関連する問題