在Android + OpenCV上执行透视转换后的黑色图像

时间:2015-12-13 20:46:02

标签: java android opencv

我有4个点代表扭曲矩形的4个角。我试图计算透视变换并应用于我的图像;但我得到的只是一个黑色的图像。有人可以帮忙吗?我尝试了不同的选项,但没有一个可行。这是我的片段:

  1. //////////////////////////////////////

    Mat cropped_image;
    cropped_image = original.clone();
    
    
         Mat pointsDES = new Mat(4,1,CvType.CV_32F);
         Mat pointsSRC = new Mat(4,1,CvType.CV_32F);
         pointsDES.put(0,300,0,0,800,0,800,300,0,300);
    

    pointsSRC.put((int)的coin.x,(INT)coin.y,(INT)coin1.x,(INT)coin1.y,(INT)coin2.x,(INT)coin2.y,( INT)coin3.x,(INT)coin3.y,(INT)coin.x,(INT)coin.y);

    Mat perspectiveTransform = Imgproc.getPerspectiveTransform(pointsSRC,pointsDES); Imgproc.warpPerspective(原始,cropped_image,perspectiveTransform,cropped_image.size());

  2. /////////////////////////////

    列表dst_pnt = new ArrayList();         点p4 =新点(0.0,500.0);         dst_pnt.add(P4);         点p5 =新点(0.0,0.0);         dst_pnt.add(P5);         点p6 =新点(800.0,0.0);         dst_pnt.add(P6);         点p7 =新点(800.0,500.0);         dst_pnt.add(P7);

        List<Point> src_pnt = new ArrayList<Point>();
        src_pnt.add(coin);
        src_pnt.add(coin1);
        src_pnt.add(coin2);
        src_pnt.add(coin3);
    
        Mat startM = Converters.vector_Point2f_to_Mat(src_pnt);
        Mat endM = Converters.vector_Point2f_to_Mat(dst_pnt);
    
        Mat perspectiveTransform = Imgproc.getPerspectiveTransform(startM, endM);
        Size size = new Size(5000, 8000);
        Scalar scalar = new Scalar(50.0);
        Mat outputMat = new Mat();
        Imgproc.warpPerspective(original, outputMat, perspectiveTransform, size);
    

0 个答案:

没有答案