与旋转相对于任意点的OpenCV warpa仿射
OpenCV warpAffine with rotation with respect to arbitrary point
我在c++中使用OpenCV。我有两张脸的图像,我试着让这两张脸对齐。我用五官来表示眼睛、鼻子和脸部的其他兴趣点。我使用Arun的方法提取旋转、平移和缩放,将一张图像中的特征集的质心转换到另一张图像。然后,它旋转并缩放它。我试着用这个变换来扭曲一个图像,这样图像中的脸就和另一个图像中的脸对齐了。至少是这么想的,但我遇到了问题。在warpAffine中,旋转和平移的执行顺序似乎与我预期的不同。与x/y坐标相比,行/列排序似乎也存在问题。同样,正如题目所暗示的,我认为warpAffine是对图像中的0,0进行操作,而我希望它们是围绕面点的质心进行的。我该怎么做才能让这两组点正确对齐呢?下面是我的代码:
// R is the rotation as computed by Arun's method
// centered_moving is the moving points with the centroid subtracted from them
// same with centered_base
for (int i = 0; i < base.cols; i++)
{
a = centered_base.col(i);
b = centered_moving.col(i).t();
H += a*b;
}
SVD sv;
Mat W, U, Vt;
sv.compute(H, W, U, Vt);
Mat R = (Vt.t())*(U.t());
// centroid_moving and centroid_base are the centroids of the two point clouds, moving is the cloud that will be translated
Mat trans = -centroid_moving + centroid_base;
Mat Afmat = Mat::zeros(2, 3, ddepth);
Mat tmpmat = Afmat(Rect(0, 0, 2, 2));
R = Mat::eye(2, 2, ddepth);
R.copyTo(tmpmat);
Afmat.at<double>(1, 2) = trans.at<double>(0);
Afmat.at<double>(0, 2) = trans.at<double>(1);
warpAffine(image_moving, affine_result, Afmat, image_moving.size());
问题是我正在使用行,列顺序的点,而warpAffine想要从x,y顺序(又名列,行)的点派生的矩阵。翻转点并使用getAffineTransform解决了这个问题。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- C++ OpenCV 卡尔曼滤波器构造函数错误
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 如何使用OpenCV-C++编写*.mp4视频?
- 与旋转相对于任意点的OpenCV warpa仿射