Ask Your Question

Aadhi's profile - activity

2020-10-08 09:55:54 -0600 received badge  Notable Question (source)
2018-05-08 21:27:19 -0600 received badge  Enthusiast
2018-05-06 11:50:04 -0600 asked a question How can i read alpha numeric Register no from multiple Identity card from android app using video mode

How can i read alpha numeric Register no from multiple Identity card from android app using video mode Hi , I'm having

2018-02-01 07:39:29 -0600 received badge  Popular Question (source)
2017-06-30 04:52:26 -0600 asked a question How can i identify transparent and non-transparent pixel by iterating all pixels of bitmap in opencv(Java) android?

I've a bitmap.Part of the bitmap is nontransparent and remaining transparent area. Using OpenCV Android Mat how can I identify nontransparent coordinates.?

2017-06-19 02:15:56 -0600 asked a question 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.

image description I've to find this angle of the image and change its perspective as per its angle.

I find non-transparent coordinate pixels of the above image using following

 Bitmap CropBitmapTransparency(Bitmap sourceBitmap)
{
    sourceBitmap.setHasAlpha(true);
    startWidth = sourceBitmap.getWidth();//  int minX
    startHeight= sourceBitmap.getHeight();//  int minY
    endWidth= -1;//  int maxX
    endHeight= -1;//  int maxY
    for(int y = 0; y < sourceBitmap.getHeight(); y++)
    {
        for(int x = 0; x < sourceBitmap.getWidth(); x++)
        {
            int alpha = ((sourceBitmap.getPixel(x, y) & 0xff000000) >> 24);
          //
            if(alpha != 0)   // pixel is not 100% transparent
            {
               // Log.d("Alpha",alpha+" ");
                if(x < startWidth)
                    startWidth = x;
                if(x > endWidth)
                    endWidth = x;
                if(y < startHeight)
                    startHeight = y;
                if(y > endHeight)
                    endHeight = y;
            }
        }
    }
    if((endWidth < startWidth) || (endHeight < startHeight))
        return null; // Bitmap is entirely transparent
    Log.w("Startwidh = ",startWidth+" ");
    Log.w("StartHeight = ",startHeight+" ");
    Log.w("Endwidh = ",endWidth+" ");
    Log.w("End Height = ",endHeight+" ");

   // angle=getAngle(startWidth,startHeight,endWidth,endHeight);

    // crop bitmap to non-transparent area and return:
    return Bitmap.createBitmap(sourceBitmap, startWidth, startHeight, (endWidth - startWidth) + 1, (endHeight - startHeight) + 1);
}

Based on the non-transparent part of the image i've change the perspective using following code

 public Bitmap perspectiveBitmap(Bitmap sourceBitmap)
   {
    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();

    Utils.bitmapToMat(sourceBitmap, inputMat);
    Mat src_mat=new Mat(4,1,CvType.CV_32FC2);
    Mat dest_mat=new Mat(4,1,CvType.CV_32FC2);
    src_mat.put(0,0,startWidth,startHeight,endWidth,startHeight,startWidth,endHeight,endWidth,endHeight);
    dest_mat.put(0,0,0.0,0.0,endWidth,0.0,0.0,endHeight,endWidth,endHeight);
    Mat perspectiveTransform=Imgproc.getPerspectiveTransform(src_mat,dest_mat);
    Mat dst=inputMat.clone();
    Size size = new Size(sourceBitmap.getWidth(), sourceBitmap.getHeight());

    Imgproc.warpPerspective(inputMat, dst, perspectiveTransform, size,Imgproc.INTER_CUBIC);

    Log.e("1=",""+inputMat.cols()+" "+inputMat.rows());
    Log.e("outmat.."," "+outputMat.cols()+" "+outputMat.rows());

    Utils.matToBitmap(dst, resultBitmap);
    //Utils.matToBitmap(tmp, b);

  return  resultBitmap;

}

But i'm not getting the perspective change

PLease help me as soon as possible. Thanks in advance