Opencv android warpprespective [closed]

asked 2015-07-19 08:18:13 -0600

Prem gravatar image

updated 2020-11-13 03:54:17 -0600

Here is my c++, opencv code, which is basically overlaying an image at specified position on cameraFeed.

Mat transmix = getPerspectiveTransform(imagePoints, newLEDPoints);
                warpPerspective(repImage, cameraFeed, transmix, cameraFeed.size(), cv::INTER_LINEAR,   cv::BORDER_TRANSPARENT);

Here imagePoints and newLEDPoints are two vectors containing exactly four Cartesian points in proper order. I am trying to achieve similar effect in android, opencv here is the code

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub
    Log.i(TAG, "called onCameraFrame");
    cameraFeed = inputFrame.rgba();
    Point center = new Point(cameraFeed.width()/2, cameraFeed.height()/2);
    Point topLeft = new Point( center.x - 100, center.y - 100 );
    Point topRight = new Point( center.x + 100, center.y - 100);
    Point bottomRight = new Point( center.x + 100, center.y + 100 );
    Point bottomLeft = new  Point( center.x - 100, center.y + 100 );
    List<Point> LEDPoints = new ArrayList<Point>();
    LEDPoints.add( topLeft );
    LEDPoints.add( topRight );
    LEDPoints.add( bottomRight );
    LEDPoints.add( bottomLeft );
    Log.i(TAG, "Before LEDPoint Conversion");
    Mat LEDPointss = Converters.vector_Point2f_to_Mat( LEDPoints );

    List<Point> imagePoints = new ArrayList<Point>();
    imagePoints.add( new Point( 0, 0));
    imagePoints.add( new Point( repImage.width(), 0 ));
    imagePoints.add( new Point( repImage.width(), repImage.height()));
    imagePoints.add( new Point( 0, repImage.height()));
    Log.i(TAG, "Before imagePoint Conversion");
    Mat imagePointss = Converters.vector_Point2f_to_Mat( imagePoints );

    Log.i(TAG, "Before transmix");
    Mat transmix = Imgproc.getPerspectiveTransform(imagePointss, LEDPointss);

    Log.i(TAG, "Before warp");

    if ( !repImage.empty())
    {
        Imgproc.warpPerspective(repImage, 
            cameraFeed,
            transmix,
            cameraFeed.size(), 
            Imgproc.INTER_LINEAR);
    }
    else
    {
        Log.i(TAG, "repImage is empty");
    }
    //Scalar color = new Scalar( 0, 255, 0 );
    //Core.circle(rgba, center, 10, color, 2);

    return cameraFeed;
}

I am just getting repImage on screen when I run this on my android tablet. I actually want repImage to appear on cameraFeed at stipulated co-ordinates ( as my c++ code does ) Kindly guide me what am I missing ? or what am I doing wrong?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-05 23:42:18.502630

Comments

Here is the code that reads repImage from drawable written inside onCameraViewStarted

try {
        repImage = Utils.loadResource(this, R.drawable.ring, Highgui.CV_LOAD_IMAGE_COLOR);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Imgproc.cvtColor( repImage,  repImage,  Imgproc.COLOR_BGR2RGBA);`enter code here`
Prem gravatar imagePrem ( 2015-07-19 09:54:08 -0600 )edit