2017-05-26 87 views
0

我在函數中傳遞一個Mat容器。但我不知道輸出是什麼。我應該如何顯示輸出?因爲當我將它顯示爲圖像時,它顯示一個空白矩陣。請提供建議。先謝謝你。buildCostMatrix函數中Output矩陣的數據類型是什麼?

這是我的代碼

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include <iostream> 
#include <stdio.h> 
#include"opencv2/opencv.hpp" 
#include"opencv2/shape.hpp" 
using namespace std; 
using namespace cv; 


/** 
* @function main 
*/ 
int main() 
{ 
    Mat src, dst; 
    Mat src1,dst1; 
    /// Load image 
    src = imread("photo.jpg"); 
    src1= imread("photo1.jpg"); 
    if(!src.data) 
    { return -1; } 
    if(!src1.data) 
    { return -1; } 


    int bins = 256; 
    int histSize[] = {bins}; 
    // Set ranges for histogram bins 
    float lranges[] = {0, 256}; 
    const float* ranges[] = {lranges}; 
    // create matrix for histogram 
    cv::Mat hist,hist1, out; 
    int channels[] = {0};double k; 
    int const hist_height = 256; 
    cv::Ptr<HistogramCostExtractor> model = createChiHistogramCostExtractor(25,0.2f); 
    cv::Mat3b hist_image = cv::Mat3b::zeros(hist_height, bins); 
    cv::calcHist(&src, 1, channels, cv::Mat(), hist, 1, histSize, ranges, true, false); 
    cv::calcHist(&src1, 1, channels, cv::Mat(), hist1, 1, histSize, ranges, true, false); 
    //double cost[256][256]; 
    // int costrows = std::max(hist.rows,hist1.rows)+nDummies; 
    //out.create(costrows,costrows,CV_32F); 
    cout << hist_height; 


    model->buildCostMatrix(hist,hist1,out); 
    normalize(out, out, 0, 1, NORM_MINMAX, -1, Mat()); 


    cout << out; 


cv::waitKey(); 
return 0; 
} 
+0

顯示至少你嘗試過什麼解決或至少儘可能您已經成功地獲得了一些示例代碼。你的問題目前對於人們的幫助太缺乏細節。具體來說,顯示嘗試和結果。 –

+0

我傳遞2個histograsm作爲buildCostMatrix函數的輸入{model-> buildCostMatrix(hist,hist1,out); cout << out;}我無法在評論中發佈整個代碼。 –

+0

您可以隨時編輯您的問題以提供更多詳細信息(建議)。這也可以幫助其他人在未來遇到你的問題。 –

回答

0

類型的成本矩陣的是:CV_32FC1,即,單一信道浮點數矩陣。

你可以看到,在source code其中_costMatrix被創建爲:

_costMatrix.create(costrows, costrows, CV_32FC1); 
+0

謝謝。但是,你能幫我關於如何把它作爲輸出。因爲當我印刷它時,我獲得了很多浮動值。 –

相關問題