Flou Gaussien sur une Bitmap
Bonjour à tous!
Après avoir récupérer le flux vidéo de ma Webcam afin d'émuler la caméra sur l'émulateur, je souhaite maintenant traiter la trame, je voudrais effectuer un flou Gaussien sur celle ci, bon j'ai déjà utiliser les fonctions native d' OpenCV sa marche mais c'est trop lent j'obtiens une image toute les 5 secondes...
Donc pourquoi ne pas le faire directement en java, j'ai donc chercher et je suis tomber sur cette fonction
Code:
1 2
|
Bitmap.createBitmap(Bitmap bitmap, int X, int Y, int width, int height, matrice, boolean filtre); |
donc je me dis génial, je vais pouvoir appliquer ma matrice gaussienne sur la bitmap directement, donc je défni ma matrice comme ceci :
Bon je prend un flou moyen :
Code:
1 2 3 4 5 6
|
Matrix matrice = new Matrix();
float [] value = {1/9 ,1/9 , 1/9,
1/9 ,1/9 , 1/9,
1/9 , 1/9 , 1/9,};
matrice.setValues(value); |
Puis j'utilise les fonction avec tous ses paramètres
Code:
1 2
|
resizedBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0,resizedBitmap.getWidth(),resizedBitmap.getHeight(),matrice, true); |
Mais évidement je me retrouve avec une Exception que je ne comprend pas...
" Caused by: java.langIllegalArgumentException: widht and height must be > 0 "
Alors que la largeur et la hauteur de l'image est bien supérieur a 0.
Ai-je mal compris la fonction? Que faire????
Je vous remercie d'avance!:)
Voici mon code test en entier
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
package com.android.test;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Matrix matrice = null;
float [] value = {1/9 ,1/9 , 1/9,
1/9 ,1/9 , 1/9,
1/9 , 1/9 , 1/9,};
matrice = new Matrix();
matrice.setValues(value);
LinearLayout linLayout = new LinearLayout(this);
super.onCreate(savedInstanceState);
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
/* ! On agrandi l'image */
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapOrg, 100, 100, true);
int width = resizedBitmap.getWidth();
int height = resizedBitmap.getHeight();
// recreate the new Bitmap
resizedBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0, width, height, matrice, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
ImageView imageView = new ImageView(this);
// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);
// center the Image
imageView.setScaleType(ScaleType.CENTER);
// add ImageView to the Layout
linLayout.addView(imageView,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
)
);
// set LinearLayout as ContentView
setContentView(linLayout);
}
} |