Opencv android warpprespective [closed]
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?
Here is the code that reads repImage from drawable written inside onCameraViewStarted