How to use opencv to acess images to use for alpha blending in java for android

792 views Asked by At

for my app I need to blend two photos using an alpha mask. How do I finish the code? And how do I acess the photos using opecv? This is the code I have until now:

public int abc()
{
 double alpha;
 double beta;
 double input;

 Mat src1;
 Mat src2;
 Mat dst;




 /// We use the alpha provided by the user if it is between 0 and 1
   alpha= 0.5; 

     /// Read image ( same size, same type )
     src1 = imread("");
     src2 = imread("");

     if( !src1.data ) { printf("Error loading src1 \n");return -1; }
     if( !src2.data ) { printf("Error loading src2 \n");return -1; }

 /// Create Windows
 namedWindow("Linear Blend", 1);

 beta = ( 1.0 - alpha );
 addWeighted( src1, alpha, src2, beta, 0.0, dst);

 imshow( "Linear Blend", dst );

 waitKey(0);
 return 0;
}
1

There are 1 answers

3
Dima On BEST ANSWER

i do this in this way:

    public void jpg2mat() {
        File jpeg1 = new File(Environment.getExternalStorageDirectory() + "/dirName/img.jpg");
        Bitmap bmp1 = BitmapFactory.decodeFile(jpeg1.getAbsolutePath());

        Mat mat1 = new Mat();
        Utils.bitmapToMat(bmp1, mat1);
    }

after you have an image as a mat, do your stuff..