C++ 从sobel打印输出垫(opencv)

C++ 从sobel打印输出垫(opencv),c++,opencv,C++,Opencv,我想知道存储在sobel输出中的变量的正确类型(在我的例子中是x)。当我运行此代码时 Mat x; Sobel( input, x, CV_32F, 1, 0); for(int i=0;i<input.cols;i++){ for(int j=0;j<input.rows;j++){ printf("%f\n",x.at<float>(i,j)); } } 但是当我跑的时候 Mat x; Sobel( input, x, CV_32F,

我想知道存储在sobel输出中的变量的正确类型(在我的例子中是x)。当我运行此代码时

Mat x;
Sobel( input, x, CV_32F, 1, 0);
for(int i=0;i<input.cols;i++){
    for(int j=0;j<input.rows;j++){
        printf("%f\n",x.at<float>(i,j));
    }
}
但是当我跑的时候

Mat x;
Sobel( input, x, CV_32F, 1, 0);
std::cout<<x<<endl;
这是因为printf将%f视为double,而不是float

我错了。我试图重现您的问题,两种类型的输出都给出了正确的结果。检查x矩阵是否具有不同的大小或类型,CV_32F为5

std::cout << x.type() << " " << x.rows << " " << x.cols << " " << std::endl;
std::cout << input.type() << " " << input.rows << " " << input.cols << " " << std::endl;

std::cout有意义。有没有办法把它转换成可读的格式?是的,我想问题与你回答后的“printf”有关。输出为x和输入都提供了5。结果表明,我在循环中将行与列混合,然后返回垃圾。无论如何,谢谢你的帮助!
2, 0, 2, 4, 2, -6, -4, 0, -6, -10, -10, -34, ...
std::cout << x.type() << " " << x.rows << " " << x.cols << " " << std::endl;
std::cout << input.type() << " " << input.rows << " " << input.cols << " " << std::endl;