我正在尝试通过使用平方差之和作为误差度量(图像配准)将面部图像与参考面部图像对齐。基本上,尝试实现 cvMatchTemplate 函数的类似功能(但是我没有模板图像,而是常见的面部表情)。尝试对差异图像求平方时,我收到断言失败错误:-215。我的问题正是:我是否必须使用矩阵乘法运算符 A*A 或每元素乘法 A.mul(A) 来获得差异图像的平方?(目前我使用 A*A)
//Start search
Mat result;
for(int i= 0; i<15; i++){
for(int j= 0; j<15; j++){
xTrans = i; //Translation on x-Axis
yTrans = j; //Translation on y-Axis
//Initialize translation matrix
double m[2][3] = {{1,0,xTrans}, {0,1,yTrans}};
Mat map = Mat(2,3,CV_64F, m);
//Get the transformed image
warpAffine(displaced, aligned, map, aligned.size());
//Calculate the sum of squared differences
absdiff(reference,aligned,result);
try{
squared = result*result; //Error line
} catch (Exception const & e){
cerr<<"OpenCV exception: "<<e.what()<<std::endl;
}
SSD = sum(squared)[0]; //Sum of squared difference
cout <<xTrans << "," << yTrans << ","<<SSD<<endl;
}
}
这是错误:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type ==
CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in unknown function, file ..
\..\..\src\opencv\modules\core\src\matmul.cpp, line 711
OpenCV exception: ..\..\..\src\opencv\modules\core\src\matmul.cpp:711: error: (-
215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32F
C2 || type == CV_64FC2)
两个图像具有相同的大小和类型,因为 warpAffine 工作正常。任何关于为什么会发生此错误或我的实施正确性的建议将不胜感激!