Mat在OSX上的opencv2.4.10中显示不同

时间:2016-10-21 17:47:15

标签: c++ macos opencv mat

在opencv的项目中,程序如下:

Mat A = Mat(9, 2, CV_16S );
int x0,y0;
ifstream fr("points.txt",ios::in);
for (int j=0; j<9; j++) {
            frs >> x0;
            frs >> y0;
            A.at<float>(j, 0) = x0;
            A.at<float>(j, 1) = y0;
        }
cout << A << endl;

但我得到了输出:

[0, -16080;
  0, 0;
  0, 16640;
  0, -16160;
  0, -16384;
  0, 16656;
  0, -16128;
  0, 16448;
  0, 16640]

累计,文件frs中的数据为:

 -11 -8
  0  -6 
  8  -6 
 -7  -11 
 -2  -10 
  9  -10 
 -8  -14 
  3  -16
  8  -18

我有什么不对吗?

1 个答案:

答案 0 :(得分:0)

首先,输入文件流的名称是fr,但是你试图从frs读取点。

[UPDATE]

您使用错误的Mat类型CV_16S而不是CV_32F。在这里您可以找到更多信息。见Mat :: depth。 http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html

此代码应该有效。

Mat A = Mat(9, 2, CV_32F);
float x, y;
std::ifstream fr("points.txt", std::ios::in);
for (int j = 0; j < 9; j++) {
    fr >> x >> y;
    A.at<float>(j, 0) = x;
    A.at<float>(j, 1) = y;
}
std::cout << A << std::endl;