OpenCV for Android: Simple example to convert Image to Greyscale -
as starter want convert bitmap greyscale via opencv. have running, crashes hard want convert image greyscale. can out? hope snippets enough, if not can attach rest.
part of java file:
// convert opencv structure mat image = new mat(); mat grayimage = new mat(); utils.bitmaptomat(b2, image); // call opencv processing grayimage = converttogray (image); // convert utils.mattobitmap(grayimage, b2);
jni cpp file:
jniexport jlong jnicall java_com_my_sample_mainmenuactivity_converttogray (jnienv*, jobject, jlong addrrgba) { logi("converting gray."); mat *mrgba = (mat*)addrrgba; mat *_retval_; cvtcolor(*mrgba, *_retval_, cv_rgb2gray); logi("successfully finished converting gray."); return (jlong) _retval_; }
it never gets logging successful having converted image. seems if bitmap not converted mat. bitmap exist, can show on imageview. clue i'm (obviously) doing wrong?
05-14 21:26:27.082: i/native(22394): converting gray. 05-14 21:26:27.082: a/libc(22394): fatal signal 11 (sigsegv) @ 0xcd10001d (code=1), thread 22394 (ialabs.mysample)
sorry if question answered elsewhere, haven't found example mat, iplimage, seems.
you have 2 empty mat
objects. can't convert that's empty gray.
try this:
mat tmp = new mat (b.getwidth(), b.getheight(), cvtype.cv_8uc1); utils.bitmaptomat(b, tmp); imgproc.cvtcolor(tmp, tmp, imgproc.color_rgb2gray);
where b
image bitmap
.
utils.mattobitmap(tmp, b);
add convert mat
object bitmap
.
Comments
Post a Comment