Ask Your Question
0

Android: Problem passing BGRA Mat to JNI function with C++ background

asked 2014-01-11 16:28:19 -0600

danksch gravatar image

updated 2014-01-11 16:30:19 -0600

Hello,

I'm currently trying to develop an android app that utilizes my desktop webcam project I've written in C++; it is basic image processing stuff with an OOP approach. So far I've managed to launch the app onto my via USB connected HTC device (without selecting a modifier; just showing the plain frame), but as soon as I select a process mode in the Menubar the application closes (or more precisely, it closes the window, but I can reenter the application again.)

It seems like it cannot access the function I need from my C++ files, at least LOGCAT prints an error that implies this assumption:

01-11 23:15:53.097: E/cv::error()(22022): OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/highgui/src/window.cpp, line 483

Theres another error immediately after the app launches:

01-11 23:15:45.630: E/OpenCV_for_Tegra(22022): Tegra Version detected: 0

I've also tried several ways to get the frame passed from java to jni, and as of now im using the getNativeObjAddr to pass a pointer to the rgba frame.

ProcessPlainFrame(mRgba.getNativeObjAddr(), mRgba.width(), mRgba.height(), mBw, mCart, mScary, mColhead);

I'm using booleans to determine which process type object shall be created. They're toggled in the onOptionsItemSelected method and then passed in the ProcessPlainFrame method, which is a native method defined in the JNI file:

JNIEXPORT void JNICALL Java_com_example_opencvandroidapp_MainActivity_ProcessPlainFrame(JNIEnv*, jobject, jlong rgba, jint width, jint height, jboolean bw_on, jboolean cart_on, jboolean scary_on, jboolean colhead_on){


Mat* pMatRgba = (Mat*)rgba;                         // create pointer to rgba mat that will function as input parameter
Mat plainFrame(height, width, CV_8UC3);             // create a an output Mat (processedFrame)


// call C++ code
if(bw_on){
    BlackWhiteSketch sketch;
    sketch.processFrame(*pMatRgba, plainFrame);
}
else if(cart_on){
    CartoonPainter cart;
    cart.processFrame(*pMatRgba, plainFrame);
}
else if(scary_on){
    ScaryFigure scary;
    scary.processFrame(*pMatRgba, plainFrame);
}
else if(colhead_on){
    ColorHead colhead;
    colhead.processFrame(*pMatRgba, plainFrame);
}

}

The processFrame() funtion does different things (it's virtual), depending on the class. You can take a look at them in my github repository:

Github Link

Sorry for the huge wall of text, but I'd greatly appreciate if anyone of you folks could take a look at it, I'm still a beginner in all of this and dont really know if my whole approach makes sense at all.

Regards

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-01-13 08:18:37 -0600

Daniil Osokin gravatar image

Hi, as logcat says, your code have some unimplemented under Android methods, like imshow or namedWindow. Suggest you to check Java API docs.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-11 16:28:19 -0600

Seen: 1,750 times

Last updated: Jan 13 '14