Ask Your Question
0

HTC One, OpenCV & Native Activity

asked Jul 30 '13

XavierP gravatar image

updated Jul 30 '13

HTC One, OpenCV & Native Activity are on a boat.

I tried to run a native activity application, on my HTC One, with Android 4.1.2. I'm using OpenCV 2.4.6.

I tried the sample, provided by OpenCV4Android, but had a couple of errors. So I reduced the code to keep only the necessary things.

I've got a segmentation fault, right after initialising the camera. Here's my code :

struct Engine {
android_app* app;
cv::Ptr<cv::VideoCapturecapture;
};

static void engine_handle_cmd(android_app* app, int32_t cmd) {
    Engine* engine = (Engine*) app->userData;
    switch (cmd) {
    case APP_CMD_INIT_WINDOW:
        if (app->window != NULL) {
            LOGI("APP_CMD_INIT_WINDOW");
            engine->capture = new cv::VideoCapture(0);

            cv::Size camera_resolution = cv::Size(720, 480);
            engine->capture->set(CV_CAP_PROP_FRAME_WIDTH,
                    camera_resolution.width);
            engine->capture->set(CV_CAP_PROP_FRAME_HEIGHT,
                    camera_resolution.height);
            return;
        }
        break;
    case APP_CMD_TERM_WINDOW:
        LOGI("APP_CMD_TERM_WINDOW");

        engine->capture->release();
        break;
    }
}

void android_main(android_app* app) {
    Engine engine;

    // Make sure glue isn't stripped.
    app_dummy();

    size_t engine_size = sizeof(engine); // for Eclipse CDT parser
    LOGI("Size of = %i", engine_size);
    memset((void*) &engine, 0, 12);

    app->userData = &engine;
    app->onAppCmd = engine_handle_cmd;
    engine.app = app;

    float fps = 0;
    cv::Mat drawing_frame;
    std::queue<int64time_queue;

    // loop waiting for stuff to do.
    while (1) {
        // Read all pending events.
        int ident;
        int events;
        android_poll_source* source;

        // Process system events
        while ((ident = ALooper_pollAll(0, NULL, &events, (void**) &source))
                >= 0) {
            // Process this event.
            if (source != NULL) {
                source->process(app, source);
            }

            // Capture frame from camera and draw it
            if (!engine.capture.empty()) {
                if (engine.capture->grab()) {
                    engine.capture->retrieve(drawing_frame,
                            CV_CAP_ANDROID_COLOR_FRAME_RGBA);
                }
            }
        }
    }
}

Have anyone experienced something like that?

Many thanks!

Here's the log file:

07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
GTK+ 2.x:                    NO 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):
GThread :                    NO 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):
GtkGlExt:                    NO 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):
OpenGL support:              NO 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):   Media
I/O:  07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
ZLib:                        z (ver
1.2.3) 07-30 09:53:47.568: I/OpenCVManager/Helper(23841):
JPEG:                        build
(ver 62) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
PNG:                         build
(ver 1.5.12) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
TIFF:                        build
(ver 42 - 4.0.2) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
JPEG 2000:                   build
(ver 1.900.1) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
OpenEXR:                     build
(ver 1.7.1) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):   Video
I/O: 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):
AndroidNativeCamera:         YES, use
prebuilt libraries 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841):   Other
third-party libraries: 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):     Use
IPP:                     NO 07-30
09:53:47.568:
I/OpenCVManager/Helper(23841):     Use
Eigen:                   YES (ver
3.1.2) 07-30 09:53:47.568: I/OpenCVManager/Helper(23841):     Use
TBB:                     YES (ver 4.1
interface 6102) 07-30 09:53:47.568:
I/OpenCVManager/Helper(23841 ...
(more)
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Jul 30 '13

There were some memory access fixes in Native Activity sample after 2.4.6 release. Try to build sample from 2.4 branch and test it on your devices. If you still have problems, I recommend you to create issue on OpenCV bug tracker.

Preview: (hide)

Comments

Okay, so you recommend to use OpenCV 2.4 instead of 2.4.6, when compiling the sample? Thanks, I'll try this.

XavierP gravatar imageXavierP (Jul 30 '13)edit

I think there are some reminiscents of this in 2.4.8 - got the same crash

kagali-san gravatar imagekagali-san (Jan 5 '14)edit

Question Tools

Stats

Asked: Jul 30 '13

Seen: 929 times

Last updated: Aug 21 '13