Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 1117

I've a bitmap image which contain both transparent area and non-transparent area. I've to find out non-transparent co-ordinates and change its perspective in android.

$
0
0
![image description](/upfiles/1497855809554155.png) 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 src_pnt = new ArrayList(); 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 dst_pnt = new ArrayList(); 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

Viewing all articles
Browse latest Browse all 1117

Trending Articles