buildCostMatrix函数中Output矩阵的数据类型是什么?

时间:2017-05-26 10:34:19

标签: opencv histogram opencv3.0 scilab

我在函数中传递了一个Mat容器。但我不知道输出会是什么。我该如何显示输出?因为当我将其显示为图像时,它显示一个空白矩阵。请提供建议。提前谢谢。

这是我的代码

#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;
}

1 个答案:

答案 0 :(得分:0)

成本矩阵的类型是:CV_32FC1,即单通道浮点矩阵。

您可以在创建_costMatrix的{​​{3}}中看到:

_costMatrix.create(costrows, costrows, CV_32FC1);