2017-01-05 19 views
0

私は2ヒストグラムを使用しました。。2つのベクトルのデータ値があります。opencvヒストグラム一致関数を使用しました。しかし、それは間違った値を返します。 (私は1を受けていますCV_COMP_CORRELが、を使用していました。(完全に一致するため、その値。)私は、私が間違っていないアイデアを持っていません。あなたの参考のために、私は以下のコードを添付しました。ありがとうございます。Opencvのヒストグラムが不正確な出力に一致する

ヒストの1code :

Mat hitograme_one() 
{ 
    vector<double>direction_vector_test; 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(10.2); 
    cv::Mat dummy_query = cv::Mat(4, 4, CV_32F, &direction_vector_test.front()); 
    Mat b_hist; 
    float range[] = { 0, 151 }; 
    const float* histRange = { range }; 
    /// Establish the number of bins 
    int histSize = 16; // *IMPORATANT 
    bool uniform = true; bool accumulate = false; 
    int hist_w = 512; int hist_h = 400; 
    int bin_w = cvRound((double)hist_w/histSize); 

    calcHist(&dummy_query, 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); 

    return b_hist; 
} 

ヒスト2コード:

Mat histo_two() 
{ 
    vector<double>direction_vector_test; 
    direction_vector_test.push_back(20.2); 
    direction_vector_test.push_back(20.2); 
    direction_vector_test.push_back(20.2); 
    direction_vector_test.push_back(10.2); 
    direction_vector_test.push_back(40.2); 
    direction_vector_test.push_back(40.2); 
    direction_vector_test.push_back(40.2); 
    direction_vector_test.push_back(77.2); 
    direction_vector_test.push_back(88.2); 
    direction_vector_test.push_back(99.2); 
    direction_vector_test.push_back(100.2); 
    direction_vector_test.push_back(100.2); 
    direction_vector_test.push_back(100.2); 
    direction_vector_test.push_back(100.2); 
    direction_vector_test.push_back(100.2); 
    direction_vector_test.push_back(100.2); 
    cv::Mat dummy_query = cv::Mat(4, 4, CV_32F, &direction_vector_test.front()); 
    Mat b_hist; 
    float range[] = { 0, 151 }; 
    const float* histRange = { range }; 
    /// Establish the number of bins 
    int histSize = 16; // *IMPORATANT 
    bool uniform = true; bool accumulate = false; 
    int hist_w = 512; int hist_h = 400; 
    int bin_w = cvRound((double)hist_w/histSize); 

    calcHist(&dummy_query, 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); 
    return b_hist; 

} 

メインファンクションコード:((1を返す誤っている))

int main(int, char** argv) 
{ 
     double compare = compareHist(hitograme_one(), histo_two(), CV_COMP_CORREL); 
     cout << compare; // returns 1 which is incorrect since input vectors //have different values 
     system("pause"); 
    return 0; 
} 

答えて

0

あなたの問題は、CV_32F

cv::Mat dummy_query = cv::Mat(4, 4, CV_32F, &direction_vector_test.front()); 

CV_8UC1

cv::Mat dummy_query = cv::Mat(4, 4, CV_8UC1, &direction_vector_test.front()); 

CV_8Uは、符号なし8ビット/画素を変更する必要がある - ピクセルが値0〜255を持つことができますつまり、CV_32Fが平らです - ピクセルは0〜1.0の間の任意の値を持つことができるので、ヒストグラムの範囲は0〜1.0の範囲に設定されます。その後、2つのヒストグラム画像が同じになります。これは、一致するパラメータを返します。

関連する問題