在迭代cv :: Mat以输出其所有值时,您可以执行以下操作:
for (int r = 0; r < t.rows; r++)
{
for (int c = 0; c < t.cols; c++)
{
std::cout << t.at<float>(r,c) << ", ";
}
std::cout << std::endl << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果存储在该数组中的信息不是float类型,则会崩溃.你如何强制执行这个矩阵的类型?
对于2个Mats nonFloatMat,floatMat当第一个是源矩阵而最后一个是目标矩阵时
nonFloatMat.convertTo(floatMat, CV_32F); //if its a color image use CV_32FC3, or
// CV_32FC4 if its RGBA
Run Code Online (Sandbox Code Playgroud)
编辑:
顺便说一句,如果您将浮动更改为矩阵的正确具体类型,即如果垫子是CV_8U您可以做的t.at<char>(r,c)等等,代码将起作用.