I've to find this angle of the image and change its perspective as per its angle.
I use the following code to achieve that
Bitmap sourceBitmap = BitmapFactory.decodeResource(res, R.drawable.layer1, options); Bitmap wall = BitmapFactory.decodeResource(res, R.drawable.wallpaper2, options); Bitmap descBitmap=Bitmap.createBitmap(sourceBitmap.getWidth(),sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888); // Utils.matToBitmap(imgMat,descBitmap); Bitmap temp=CropBitmapTransparency(sourceBitmap); Bitmap resultBitmap=Bitmap.createBitmap(sourceBitmap.getWidth(),sourceBitmap.getHeight(),Bitmap.Config.ARGB_8888); Mat inputMat = new Mat(); Mat outputMat = new Mat(); Mat outputMat1 = new Mat(); // descBitmap=sourceBitmap; Utils.bitmapToMat(sourceBitmap, inputMat); System.out.println("INput matrix = "+inputMat.toString()); List<point> src_pnt = new ArrayList<point>(); Point p0 = new Point(startWidth,startHeight); src_pnt.add(p0); Point p1 = new Point(endWidth, startHeight); src_pnt.add(p1); Point p2 = new Point(startWidth, endHeight); src_pnt.add(p2); Point p3 = new Point(endWidth, endHeight); src_pnt.add(p3); Mat startM = Converters.vector_Point2f_to_Mat(src_pnt);
List<Point> dst_pnt = new ArrayList<Point>();
Point p4 = new Point(0.0, 0.0);
dst_pnt.add(p4);
Point p5 = new Point(0.0, sourceBitmap.getHeight());
dst_pnt.add(p5);
Point p6 = new Point(sourceBitmap.getWidth(), sourceBitmap.getHeight());
dst_pnt.add(p6);
Point p7 = new Point(sourceBitmap.getWidth(), 0);
dst_pnt.add(p7);
Mat endM = Converters.vector_Point2f_to_Mat(dst_pnt);
Mat perspectiveTransform = Imgproc.getPerspectiveTransform(startM, endM);
Size size = new Size(sourceBitmap.getWidth(), sourceBitmap.getHeight());
Scalar scalar = new Scalar(50.0);
Imgproc.warpPerspective(inputMat, outputMat, perspectiveTransform, size, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS,Imgproc.COLOR_BayerBG2BGR , scalar);
Utils.matToBitmap(inputMat, descBitmap);
image3.setImageBitmap(descBitmap);
PLease help me as soon as possible.
Thanks in advance