0

これは、たとえば車両のデータセットをトレーニングするための私のコードです。完全にトレーニングすると、ビデオ (.avi) からデータ (車両) を予測しhow to predict trained data from video and how to add that part in it ?たいです。 1 としてカウントし、オブジェクトが検出されたことをカウントし、2 番目の車両が来ると、カウントを 2 としてインクリメントします。

    IplImage *img2;
    cout<<"Vector quantization..."<<endl;
    collectclasscentroids();
    vector<Mat> descriptors = bowTrainer.getDescriptors();
    int count=0;
    for(vector<Mat>::iterator iter=descriptors.begin();iter!=descriptors.end();iter++)
    {
       count += iter->rows;
    }
    cout<<"Clustering "<<count<<" features"<<endl;
    //choosing cluster's centroids as dictionary's words
    Mat dictionary = bowTrainer.cluster();
    bowDE.setVocabulary(dictionary);
    cout<<"extracting histograms in the form of BOW for each image "<<endl;
    Mat labels(0, 1, CV_32FC1);
    Mat trainingData(0, dictionarySize, CV_32FC1);
    int k = 0;
    vector<KeyPoint> keypoint1;
    Mat bowDescriptor1;
    //extracting histogram in the form of bow for each image 
   for(j = 1; j <= 4; j++)
    for(i = 1; i <= 60; i++)
            {
              sprintf( ch,"%s%d%s%d%s","train/",j," (",i,").jpg");
              const char* imageName = ch;
              img2 = cvLoadImage(imageName, 0); 
              detector.detect(img2, keypoint1);
              bowDE.compute(img2, keypoint1, bowDescriptor1);
              trainingData.push_back(bowDescriptor1);
              labels.push_back((float) j);
             }
    //Setting up SVM parameters
    CvSVMParams params;
    params.kernel_type = CvSVM::RBF;
    params.svm_type = CvSVM::C_SVC;
    params.gamma = 0.50625000000000009;
    params.C = 312.50000000000000;
    params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 0.000001);
    CvSVM svm;



    printf("%s\n", "Training SVM classifier");

    bool res = svm.train(trainingData, labels, cv::Mat(), cv::Mat(), params);

    cout<<"Processing evaluation data..."<<endl;


    Mat groundTruth(0, 1, CV_32FC1);
    Mat evalData(0, dictionarySize, CV_32FC1);
    k = 0;
    vector<KeyPoint> keypoint2;
    Mat bowDescriptor2;


    Mat results(0, 1, CV_32FC1);;
    for(j = 1; j <= 4; j++)
      for(i = 1; i <= 60; i++)
         {
           sprintf( ch, "%s%d%s%d%s", "eval/", j, " (",i,").jpg");
           const char* imageName = ch;
           img2 = cvLoadImage(imageName,0);
           detector.detect(img2, keypoint2);
           bowDE.compute(img2, keypoint2, bowDescriptor2);
           evalData.push_back(bowDescriptor2);
           groundTruth.push_back((float) j);
           float response = svm.predict(bowDescriptor2);
           results.push_back(response);
         }



    //calculate the number of unmatched classes 
    double errorRate = (double) countNonZero(groundTruth- results) / evalData.rows;

The question isこのコードはビデオから予測していません。ビデオから予測する方法を知りたいです。つまり、映画から車両を検出したいということです。映画から車両が見つかったときに 1 が表示されるはずです。

質問を理解していない人のために:

上記のコードでムービーを再生したい

VideoCapture cap("movie.avi"); //movie.avi is with deleted background

vehicle を含むトレーニング済みデータがあり、「movie.avi」に 5 つの vehicle が含まれているとします。したがって、movie.avi からその車両を検出し、5出力として提供する必要があります。

上記のコードでこの部分を行う方法

4

4 に答える 4

0

画像を使用するためのコードは OpenCV の C インターフェイスで記述されているため、C++ ビデオ インターフェイスを使用するよりも、それに固執する方がおそらく簡単です。

その場合、これらの行に沿った何かが機能するはずです:

CvCapture *capture = cvCaptureFromFile("movie.avi");

IplImage *img = 0;
while(img = cvQueryFrame(capture))
{
       // Process image
       ...
}
于 2013-08-16T01:24:14.400 に答える
0

スライディング ウィンドウ アプローチを実装する必要があります。各ウィンドウで、SVM を適用して候補を取得する必要があります。次に、画像全体に対してそれを行ったら、候補をマージする必要があります(オブジェクトを検出した場合、数ピクセルのシフトで再び検出する可能性が非常に高くなります-それが候補の意味です) .

openCV の V&J コードまたは潜在 SVM コード (パーツによる検出) を見て、そこでどのように行われているかを確認してください。

ちなみに、車の検出にはLatentSVMコード(部品による検出)を使用します。自動車とバスのモデルをトレーニングしました。

幸運を。

于 2013-08-16T10:35:52.400 に答える