Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void overlayImage(Mat background,Mat foreground,Mat output,Point location){
- Log.i("call","Calling OVerlay Image");
- background.copyTo(output);
- // start at the row indicated by location, or at row 0 if location.y is negative.
- for(int y = (int) Math.max(location.y , 0); y < background.rows(); ++y){
- int fY = (int) (y - location.y); // because of the translation
- // we are done of we have processed all rows of the foreground image.
- if(fY >= foreground.rows())
- break;
- // start at the column indicated by location,
- // or at column 0 if location.x is negative.
- for(int x = (int) Math.max(location.x, 0); x < background.cols(); ++x){
- int fX = (int) (x - location.x); // because of the translation.
- // we are done with this row if the column is outside of the foreground image.
- if(fX >= foreground.cols()){
- break;
- }
- //determine the opacity of the foregrond pixel, using its fourth (alpha) channel.
- /// here tried other type of arrays like short , int and float but same problem is there
- double[] opacity = new double[(int) (foreground.total()*foreground.channels())];
- /// Mat type not compatible error over here
- foreground.get(fY , fX, opacity);
- ///OR
- //double[] opacity = foreground.get(fY , fX, opacity);
- Log.i("Length", String(opacity.length));
- /// assuming that opacity will be array of 4 values and
- /// opacity[3] will contain alpha channel values
- if ( opacity[3] > 0){
- double[] foregroundPx = foreground.get(fY, fX);
- double[] backgroundPx = background.get(fY, fX);
- double[] finalPixelValue = new double[3] ;
- finalPixelValue[0] = backgroundPx[0] * ( 1.0 - opacity[3]) + foregroundPx[0] * opacity[3];
- finalPixelValue[1] = backgroundPx[1] * ( 1.0 - opacity[3]) + foregroundPx[1] * opacity[3];
- finalPixelValue[2] = backgroundPx[2] * ( 1.0 - opacity[3]) + foregroundPx[2] * opacity[3];
- output.put(fY, fX,finalPixelValue);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment