I'm working on re-writing a function in C++//OpenCV that takes two
images, one a photo, and the second, a photographic filter (e.g.,
solid color, graduated, or split-field) and blends the two. The
first version had the Java side saving the two source images, and
then in C++, they were opened again with imread, and blended. This
works, but it's WAY too slow (4--5 seconds).
So, now that I (thought I knew) how, I'm trying to re-code this
to accept the two images, one now a byte[] array, and the other
a bitmap, passed directly as args. I'm combining code from the
jnipart.cpp from tutorial-3-native, and code I got as a response
to an earlier post here---that part I know works---I've been using
it as a "wrapper" around image processing routines with great
success---somewhere outside of that, however, it's crashing.
The source (so far) and the debug output from addr2line and ndk-stack
are included below. If someone can please help me with this, I would
appreciate it. I've been trying to debug this for some time now, with
no success (or debug output that I can understand).
Here's the source for the revised version (so far):
--------------------------- CUT HERE ---------------------------
#include <jni.h>
#include <cv.h>
#include <highgui.h>
#include <android/bitmap.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
extern "C" {
JNIEXPORT void JNICALL Java_com_jdgapps_FilterTests_FilterTests_cvBlend2(JNIEnv* env, jobject thiz,
jint pw, jint ph, jbyteArray yuv, jobject src, jobject dst) {
// this is adapted from tutorial-3-native/jni/jnipart.cpp
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
Mat myuv(ph, pw, CV_8UC4, (unsigned char *)_yuv);
Mat pbgra, tmp;
// I originally had this in one line, as
// cvtColor(myuv, pbgra, CV_YUV420sp2BGR, 4)
// and when that crashed, I tried this instead, to see
// if that was the problem....it didn't change anything
cvtColor(myuv, tmp, CV_YUV420sp2BGR, 3);
cvtColor(tmp, pbgra, CV_BGR2BGRA, 4);
// now the byte[] array should be an CV_8UC4 format Mat (I think)
// this is from code in response to another post, that imports
// two bitmaps, one src, one dest. I know this part works, as
// I've been using it successfully since I got it as a wrapper
// around image processing routines.
AndroidBitmapInfo infoSrc;
void* pixelsSrc = 0;
AndroidBitmapInfo infoDst;
void* pixelsDst = 0;
CV_Assert( AndroidBitmap_getInfo(env, src, &infoSrc) >= 0 );
CV_Assert( infoSrc.format == ANDROID_BITMAP_FORMAT_RGBA_8888 );
CV_Assert( AndroidBitmap_getInfo(env, dst, &infoDst) >= 0 );
CV_Assert( infoDst.format == ANDROID_BITMAP_FORMAT_RGBA_8888 );
CV_Assert( infoSrc.height == infoDst.height && infoSrc.width == infoDst.width );
int h = infoSrc.height, w = infoSrc.width;
CV_Assert( AndroidBitmap_lockPixels(env, src, &pixelsSrc) >= 0 );
CV_Assert( pixelsSrc );
CV_Assert( AndroidBitmap_lockPixels(env, dst, &pixelsDst) >= 0 );
CV_Assert( pixelsDst );
Mat mSrc(h, w, CV_8UC4, pixelsSrc), mDst(h, w, CV_8UC4, pixelsDst);
// For this test, all I want to do is see if the byte[] array was
// properly converted by displaying it as the result (mDst). If I
// can get that far, blending is easy.... (The next bit will be
// creating the filter bitmap in C++. <grin>)
pbgra.copyTo(mDst);
return;
} // cvBlend2
} // extern C
--------------------------- CUT HERE ---------------------------
And this is the debug output (from addr2line and ndk-stack):
--------------------------- CUT HERE ---------------------------
std::basic_istream<wchar_t, std::char_traits<wchar_t> >& std::basic_istream<wchar_t, std::char_traits<wchar_t> >::_M_extract<unsigned long>(unsigned long&)
eh_type.cc:0
********** Crash dump: **********
Build fingerprint: 'acer/a500_pa_cus1/picasso:4.0.3/IML74K/1333727375:user/release-keys'
pid: 4000, tid: 4000 >>> com.jdgapps.FilterTests <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
Stack frame #00 pc 000178a8 /system/lib/libc.so
--------------------------- CUT HERE ---------------------------
Can anyone help me with A) understanding the above debug output, and
B) understanding why this is crashing?
Thanks,
--jim
PS: Please remember, I am still learning to use the NDK, C++, AND
OpenCV. I've already learned some, but this is one part I've
never gotten to work, despite the tutorials.
--
THE SCORE: ME: 2 CANCER: 0
73 DE N5IAL (/4) MiSTie #49997 < Running Mac OS X Lion >
spook...@gmail.com ICBM/Hurricane: 30.44406N 86.59909W
"sigh, once upon a time T-1 was fast...."
--seen in alt.sysadmin.net-abuse.email
Android Apps Listing at
http://www.jstrack.org/barcodes.html