相关疑难解决方法(0)

Android OpenCV getPerspectiveTransform和warpPerspective

我对getPerspectiveTransform的参数有点困惑,因为我看不到合适的图像.这是我的代码.original_image变量是包含我想要裁剪并创建新图像的方形对象(以及其他一些对象)的图像(类似于此Android OpenCV查找最大正方形或矩形).变量p1,p2,p3和p4是图像中最大正方形/矩形的角的坐标.p1是左上角,p2是右上角,p3是右下角,p4是左下角(顺时针分配).

    Mat src = new Mat(4,1,CvType.CV_32FC2);
    src.put((int)p1.y,(int)p1.x, (int)p2.y,(int)p2.x, (int)p4.y,(int)p4.x, (int)p3.y,(int)p3.x);
    Mat dst = new Mat(4,1,CvType.CV_32FC2);
    dst.put(0,0, 0,original_image.width(), original_image.height(),original_image.width(), original_image.height(),0);

    Mat perspectiveTransform = Imgproc.getPerspectiveTransform(src, dst);
    Mat cropped_image = original_image.clone();
    Imgproc.warpPerspective(untouched, cropped_image, perspectiveTransform, new Size(512,512));
Run Code Online (Sandbox Code Playgroud)

当我尝试显示cropped_image时,我得到一个"我不知道它是什么"的图像.我认为我在getPerspectiveTransform()中的参数不正确(或者是它).请帮忙.谢谢!

更新:当我调试我的代码时,我发现我的方形/矩形的边缘是不正确的,有些是非常正确的,除了p4.这是我检测图像中正方形或矩形边缘的代码.我的图像全黑,除了具有白色轮廓的最大正方形/矩形的轮廓.

    //we will find the edges of the new_image (corners of the square/rectangle)
    Point p1 = new Point(10000, 10000); //upper left; minX && minY
    Point p2 = new Point(0, 10000); //upper right; maxX && minY
    Point p3 = new Point(0, 0); //lower right; …
Run Code Online (Sandbox Code Playgroud)

android opencv transformation warp

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

opencv ×1

transformation ×1

warp ×1