OPenCV perspective transformation and Region of Interest

I start to play with OpenCV using Greg Borensteins Processing implementation. I've implemented a PVImage to MAT class to access OpenCV methods direct. Now I'm looking into perspective transformation and Region of Interest but have no success so far. Any hints are welcome.

Tagged:

Comments

  • Region of Interest seems to be very easy.

    Rect ROI = new Rect(1280/2-300,300,500,300); Mat roiImg = new Mat(mask_yw_image, ROI);

    But results like Hughlines have to be transferred back.

    Core.line(img_BGR, new Point(val[0]+1280/2-300, val[1]+300), new Point(val[2]+1280/2-300, val[3]+300), new Scalar(255, 0, 0), 5);

  • edited February 2018

    And PerspectiveTransformation is slightly more difficult. It seems to be more difficult to define correct input and outputQuads.

  • Indeed , at least it is very simple.

    // -------
     MatOfPoint2f srcMat = new MatOfPoint2f(new Point(0, 0), // Top-left corner 
        new Point(img.width-1, 0),                            // Top-right corner
        new Point(img.width-1, img.height-1),                 // Bottom-reight corner
        new Point(0,img.height-1));                           // Pottom-left corner
    
      MatOfPoint2f dstMat = new MatOfPoint2f(new Point(150, 300), 
        new Point(img.width-150, 300), 
        new Point(img.width-1, img.height-1),
        new Point(0, img.height-1));
    
      Mat affine = Imgproc.getPerspectiveTransform(srcMat, dstMat); 
      Mat in = cv.getBGR(); 
      Mat out = new Mat(in.size(), in.type()); 
      Mat outnew = new Mat(in.size(), in.type()); 
      Imgproc.warpPerspective(in, out, affine, out.size()); 
      Mat affineback = Imgproc.getPerspectiveTransform(dstMat, srcMat);
      Imgproc.warpPerspective(out, outnew, affineback, outnew.size());
     // -------- 
    
Sign In or Register to comment.