使用 cvTransform 和 cvGetAffineTransform openCv 调整矩形大小

发布于 2024-11-18 11:25:01 字数 1001 浏览 4 评论 0原文

我正在处理多尺度图像,有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界和平 2024-11-25 11:25:01

我已经解决了它,

我只是找到了另一个函数 - 它是 cvConvertScale

       for (int i = 0; i < Brectangles.Count; i++) {

            src[0, 0] = Brectangles[i].X;    //top left
            src[0, 1] = Brectangles[i].Y;
            src[1, 0] = Brectangles[i].Right;  //top right
            src[1, 1] = Brectangles[i].Y;
            src[2, 0] = Brectangles[i].X;    //bottom left
            src[2, 1] = Brectangles[i].Bottom;


            CvInvoke.cvConvertScale(src, dst, rescaleFactor, 0); // rescaleFactor variable is 2 for half size & 0.5 for double size

            temp.X = dst[0, 0];
            temp.Y = dst[0, 1];
            temp.Width = dst[1, 0] - dst[0, 0];
            temp.Height = dst[2, 1] - dst[0, 1];

            Brectangles[i] = temp;


         }

它调整矩形的大小并将其重新定位到新大小的正确位置

I have solved it,

I simply found another function - it's cvConvertScale

       for (int i = 0; i < Brectangles.Count; i++) {

            src[0, 0] = Brectangles[i].X;    //top left
            src[0, 1] = Brectangles[i].Y;
            src[1, 0] = Brectangles[i].Right;  //top right
            src[1, 1] = Brectangles[i].Y;
            src[2, 0] = Brectangles[i].X;    //bottom left
            src[2, 1] = Brectangles[i].Bottom;


            CvInvoke.cvConvertScale(src, dst, rescaleFactor, 0); // rescaleFactor variable is 2 for half size & 0.5 for double size

            temp.X = dst[0, 0];
            temp.Y = dst[0, 1];
            temp.Width = dst[1, 0] - dst[0, 0];
            temp.Height = dst[2, 1] - dst[0, 1];

            Brectangles[i] = temp;


         }

It resizes the rectangle and relocates it in its proper position is the new size

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文