Convert Android Bitmap to OpenCV Mat and backwards -
i wanted convert bitmap android mat object opencv. topic adressed on stack overflow. example:
convert mat bitmap opencv android ;
convert bitmap mat after capture image using android camera ;
templatematching mattobitmap opencv android
there more find. followed instrcutions in answers, i'm still unable done right way.
minimal code:
//first convert bitmap mat mat imagemat = new mat ( image.getheight(), image.getwidth(), cvtype.cv_8u, new scalar(4)); bitmap mybitmap32 = image.copy(bitmap.config.argb_8888, true); utils.bitmaptomat(mybitmap32, imagemat); //do smth. imgproc.cvtcolor(imagemat, imagemat, imgproc.color_rgb2gray,4); //then convert processed mat bitmap bitmap resultbitmap = bitmap.createbitmap(imagemat.cols(), imagemat.rows(),bitmap.config.argb_8888);; utils.mattobitmap(imagemat, resultbitmap); //set member result bitmap. member displayed in imageview mresult = resultbitmap;
(note: image bitmap supplied lines of code)
errors:
08-07 15:13:59.188: e/androidruntime(2115): fatal exception: main
08-07 15:13:59.188: e/androidruntime(2115): java.lang.noclassdeffounderror: org.opencv.core.mat
but imports are:
import android.graphics.bitmap; import android.graphics.bitmap.config; //opencv import org.opencv.android.utils; import org.opencv.core.cvtype; import org.opencv.core.mat; import org.opencv.core.scalar; import org.opencv.imgproc.imgproc;
would appreciate sort of help. dans
you can work opencv after initialized. need initialize that:
1.create callback:
private baseloadercallback mopencvcallback = new baseloadercallback(this) { @override public void onmanagerconnected(int status) { switch (status) { case loadercallbackinterface.success: //do work/stuff here break; default: super.onmanagerconnected(status); break; } } };
2.you need initialize callback in onresume method of activity:
@override protected void onresume() { super.onresume(); opencvloader.initasync(opencvloader.opencv_version_2_4_8, this, mopencvcallback); }
and thats it, hope helpful :d
Comments
Post a Comment