2016-05-05 9 views
1

私は、ハミング距離の助けを借りてビデオの2つのイメージを探しています。ここに私のコードは次のとおりです。OpenCV.normのアサーションエラー

#include <iostream> 
#include "opencv2/opencv.hpp" 
using namespace cv; 
int main(int argc, char** argv) 
{ 
    char const* filename = ("video.mp4"); 
    VideoCapture video(filename); 
    Mat frame, temp; 
    for(unsigned int i = 0; i<100; i++) 
    { 
     video >> frame; 
     if (i > 0) 
     { 
      double dist = norm(frame, temp, NORM_HAMMING); 
      cout<<"Dist= "<< dist <<endl; 
     } 
     temp = frame; 
    } 
    return 0; 
} 

問題が

double dist = norm(frame, temp, NORM_HAMMING); 

にプログラムが

**OpenCV Error**: Assertion failed (normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U))in norm, in file /home/andrio/.local/share/Trash/files/build/OpenCV/modules/core/src/stat.cpp, line 3123 terminate called after throwing an instance of 'cv::Exception' what(): /home/andre/.local/share/Trash/files/build/OpenCV/modules/core/src/stat.cpp:3123: error: (-215) normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) in function norm 

UPDに落ちるということです:このコードは仕事です:

double dist = norm(frame, temp, NORM_L2); 
+0

この関数を呼び出すと、どのようなデータ型が 'frame'マトリックスですか?実際にイメージが読み込まれていますか?他の関数へのパラメータとして渡す前に、その検証を試みることはありません。 –

+0

frame.type()とtemp.type()の出力は16です。ここで[OpenCV](http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html)では、配列型。 –

答えて

1

イメージを灰色にする必要があります

cvtColor(frame, frame, CV_BGR2GRAY); 
関連する問題