使用 Emgu (OpenCV) 进行变换 - 仿射/透视?
我目前正在尝试通过使用 EMGU 来实现转换,尽管我似乎无法理解它是如何工作的(并且网上似乎没有任何示例)。
我已经得到了我的图像,其中包含我希望转换的 4 个点,虽然我不知道还需要什么其他变量,但它要求 'mapMat' ?
这是我到目前为止所得到的:
float[,] tmp = {
{bottomLeft.x, bottomLeft.y},
{topLeft.x, topLeft.y},
{topRight.x, topRight.y},
{bottomRight.x, bottomRight.y}
};
Matrix<float> sourceMat = new Matrix<float>(tmp);
float[,] target = {
{0, height},
{0, 0},
{width, 0},
{width, height}
};
Matrix<float> targetMat = new Matrix<float>(target);
//mapMat = just a placeholder matrix?
Matrix<float> mapMat = new Matrix<float>(target);
CvInvoke.cvGetAffineTransform(sourceMat.Ptr, targetMat.Ptr, mapMat.Ptr);
但这不起作用。我也不确定仿射变换是否是最理想的解决方案?我也读过一些有关 FindHomography 和透视变换的内容,但不确定它们是否适用于这里。
我希望实现的目标转换是这样的:
http://img832.imageshack.us/ img832/5157/targettransform.png
任何帮助将不胜感激,
谢谢
I'm currently trying to implement transformations through using EMGU, though I can't seem to get my head round how it works (and there doesn't seem to be any examples online).
I've got my image, with the 4 points I wish to transform from (and to), though I don't know what other variables are required, it asks for 'mapMat' ?
Here is what I have so far:
float[,] tmp = {
{bottomLeft.x, bottomLeft.y},
{topLeft.x, topLeft.y},
{topRight.x, topRight.y},
{bottomRight.x, bottomRight.y}
};
Matrix<float> sourceMat = new Matrix<float>(tmp);
float[,] target = {
{0, height},
{0, 0},
{width, 0},
{width, height}
};
Matrix<float> targetMat = new Matrix<float>(target);
//mapMat = just a placeholder matrix?
Matrix<float> mapMat = new Matrix<float>(target);
CvInvoke.cvGetAffineTransform(sourceMat.Ptr, targetMat.Ptr, mapMat.Ptr);
This however doesn't work. I was also unsure whether or not an affine transformation was the most ideal solution? I read something about FindHomography too and also perspective transformations, but not sure if they would apply here.
The target transformation i wish to achieve is like this:
http://img832.imageshack.us/img832/5157/targettransform.png
Any help would be greatly appreciated,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先有一点介绍:
所以假设您有 4 个源角和目标角,并且您想要估计透视变换,此代码应该执行您想要的操作:
查看 CameraCalibration 了解其他有用的方法
First a little intro:
So suppose you have your 4 source and destination corners, and you want to estimate a Perspective Transformation this code should do what you want:
Take a look at CameraCalibration for other useful methods