使用 cvTransform 和 cvGetAffineTransform openCv 调整矩形大小
我正在处理多尺度图像,有 3 种尺寸:原始尺寸、半尺寸和半尺寸图像。双倍的 我分别从每个组件中提取连接的组件,然后进行一些计算
,最后我想映射一半和一半的边界矩形。双比例连接组件到原始图像中的原始位置和大小
这是我调整大小和重新定位边界矩形的代码
Matrix<int> src = new Matrix<int>(3, 2,3);
Matrix<int> dst = new Matrix<int>(3, 2,2);
IntPtr mat = CvInvoke.cvCreateMat(2, 3, MAT_DEPTH.CV_32F);
src[0,0]=componentBRect.X;
src[0,1]=componentBRect.Y ;
src[1,0]=componentBRect.Right;
src[1,1]=componentBRect.Y;
src[2,0]=componentBRect.X;
src[2,1]=componentBRect.Bottom;
CvInvoke.cvGetAffineTransform(img2, img, mat); //img is the original image & img2 has been resized to 1/2 imgWidth and 1/2 imgHeight
CvInvoke.cvTransform(src.Ptr, dst.Ptr, mat, IntPtr.Zero);
,它应该使 dst 点调整大小和重新定位 但不幸的是,再次返回相同的点,我认为 getAffineTransform 有问题,因为它返回单位矩阵
mat=
|1 0 0 |
|0 1 0 | !!
有什么建议吗?或者是否有另一种方法可以在不使用仿射变换的情况下做我想做的事情
提前致谢
iam dealing with multiscale images , 3 sizes : original , half & double
i extract the connected components from each of them separately then do some computations
finally i want to map the bounding rectangles of the half & double scale connected components to their original location and size in the original image
here's my code of resizing and relocating the bounding rectangle
Matrix<int> src = new Matrix<int>(3, 2,3);
Matrix<int> dst = new Matrix<int>(3, 2,2);
IntPtr mat = CvInvoke.cvCreateMat(2, 3, MAT_DEPTH.CV_32F);
src[0,0]=componentBRect.X;
src[0,1]=componentBRect.Y ;
src[1,0]=componentBRect.Right;
src[1,1]=componentBRect.Y;
src[2,0]=componentBRect.X;
src[2,1]=componentBRect.Bottom;
CvInvoke.cvGetAffineTransform(img2, img, mat); //img is the original image & img2 has been resized to 1/2 imgWidth and 1/2 imgHeight
CvInvoke.cvTransform(src.Ptr, dst.Ptr, mat, IntPtr.Zero);
it's supposed to get dst points reszied and relocated
but unfortunately the same points are returned again , i think there's a problem with getAffineTransform as it returns an identity matrix
mat=
|1 0 0 |
|0 1 0 | !!
Any Suggestions ?? or is there another way to do what i want without using Affine transformation
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了它,
我只是找到了另一个函数 - 它是
cvConvertScale
它调整矩形的大小并将其重新定位到新大小的正确位置
I have solved it,
I simply found another function - it's
cvConvertScale
It resizes the rectangle and relocates it in its proper position is the new size