Giter Site home page Giter Site logo

Comments (6)

pflammertsma avatar pflammertsma commented on July 29, 2024

After some debugging, I've confirmed that the native method getSourceImage() in cvjni.cpp:134 is actually called; the JNI WARNING above is raised immediately after the function returns, and has the following trace:

"Thread-8" prio=5 tid=15 RUNNABLE
  | group="main" sCount=0 dsCount=0 s=N obj=0x43d16548 self=0x119ff8
  | sysTid=16284 nice=0 sched=0/0 cgrp=default handle=1196176
  at org.siprop.opencv.OpenCV.getSourceImage(Native Method)
  at org.siprop.opencv.VideoEmulation$1.run(VideoEmulation.java:226)

from opencv-android.

pflammertsma avatar pflammertsma commented on July 29, 2024

If I change the type declaration in OpenCV.java:38 from:

public native byte[] getSourceImage();

To:

public native boolean[] getSourceImage();

The application no longer crashes, but then of course I cannot decode the byte array in VideoEmulation.java:240.

from opencv-android.

pflammertsma avatar pflammertsma commented on July 29, 2024

I resolved the problem, but needed to make changes to cvjni.h and cvjni.cpp:

  1. The datatype of Java_org_siprop_opencv_OpenCV_getSourceImage() should be jbyteArray, not jbooleanArray.
  2. With all subsequent modifications within that function (line 152, 154 and 157), the Android application works as expected.

I would also suggest changing the datatype of Java_org_siprop_opencv_OpenCV_findContours() to jbyteArray.

from opencv-android.

ntbb avatar ntbb commented on July 29, 2024

The solution mentioned above was so useful, and therefore I've completed the porting of face detector from PC to android.

Thanks to pflammertsma and the author of this awesome project!

from opencv-android.

bruciebruce avatar bruciebruce commented on July 29, 2024

Hello,

Thanks for all the good pointers (pardon the joke).

I took your advice and made changes to cvjni.h file. Here are the changes:

JNIEXPORT
jbyteArray
JNICALL
Java_org_siprop_opencv_OpenCV_findContours(JNIEnv* env,
jobject thiz,
jint width,
jint height);

and also this:

JNIEXPORT
jbyteArray
JNICALL
Java_org_siprop_opencv_OpenCV_getSourceImage(JNIEnv* env,
jobject thiz);

I then made chanes to the implementation file cvjni.cpp as such:

/ Generate and return a boolean array from the source image.
// Return 0 if a failure occurs or if the source image is undefined.
JNIEXPORT
jbyteArray
JNICALL
Java_org_siprop_opencv_OpenCV_getSourceImage(JNIEnv* env,
jobject thiz)
{

...

jbyteArray res_array = env->NewByteArray(imageSize);
if (res_array == 0) {
    LOGE("Unable to allocate a new boolean array for the source image.");
    return 0;
}
env->SetByteArrayRegion(res_array, 0, imageSize, (jbyte*)strm->GetByte());

strm->Close();
SAFE_DELETE(strm);

return res_array;

}

and finally the 2nd file:

JNIEXPORT
jbyteArray
JNICALL
Java_org_siprop_opencv_OpenCV_findContours(JNIEnv* env,
jobject thiz,
jint width,
jint height) {
...

jbyteArray res_array = env->NewByteArray(imageSize);
LOGV("Load NewBooleanArray.");
if (res_array == 0) {
    return 0;
}
env->SetByteArrayRegion(res_array, 0, imageSize, (jbyte*)strm->GetByte());
LOGV("Load SetBooleanArrayRegion.");

LOGV("Release sourceImage");
if (m_sourceImage) {
    cvReleaseImage(&m_sourceImage);
    m_sourceImage = 0;
}
LOGV("Release binaryImage");
cvReleaseImage( &binaryImage );
LOGV("Release grayImage");
cvReleaseImage( &grayImage );
LOGV("Release contourImage");
cvReleaseImage( &contourImage );
LOGV("Release storage");
cvReleaseMemStorage( &storage );
LOGV("Delete strm");
strm->Close();
SAFE_DELETE(strm);

return res_array;

}

I still get the same seg fault alluded to by the previous writers on this thread.

I have not run the emulator program. I have an ADP2

Thanks!

-Bruce

from opencv-android.

billmccord avatar billmccord commented on July 29, 2024

Yes, much thanks to pflammertsma. I have been rather disconnected from this project of late because of other priorities, but I am going to try to integrate this work back into the project.

from opencv-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.