Comments (6)
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.
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.
I resolved the problem, but needed to make changes to cvjni.h
and cvjni.cpp
:
- The datatype of
Java_org_siprop_opencv_OpenCV_getSourceImage()
should bejbyteArray
, notjbooleanArray
. - 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.
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.
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.
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)
- simple OpenCVSample failed with segmentation fault HOT 1
- Enhancement to support Android 1.5 HOT 1
- VideoEmulation - Fatal Exception initFaceDetection HOT 3
- VideoEmulation - Don't show image HOT 1
- Error during Load of cascade file HOT 1
- (Not really and Issue) Very slow performance with VideoEmulation HOT 1
- Crash on mobile phone HOT 1
- I want to open jpg or png files but I cannot open them.
- Unable to build on Windows HOT 6
- VideoEmulation Issues
- how can compile it with cygwin HOT 1
- undefined reference
- Core.putText() chinese words show "???" HOT 1
- why preview picture is left-right-reverse ?
- How to manage an image with the library? HOT 1
- OpenCV sample not working on Moto Droid HOT 3
- Current structure will not work on latest Android NDK r4 HOT 3
- (Not really an issue...) Any differences between this OpenCV-Android and "official" OpenCV project? HOT 3
- New build instructions for android-ndk-r4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv-android.