hi,
I have tried writing a jni call for the simple c code. when i try to install this on the phone running 2.3.3 it doesnt install, sometimes even if it installs then it is being force closed.Please help me with this. the code details are as follows:
The java code of which i generate the header file.
package com.hosa;
public class edgejava{
static{
System.loadLibr ary("edgejava") ;
}
public native int main();
}
the generated header file is as below
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_hosa_edgeja va */
#ifndef _Included_com_h osa_edgejava
#define _Included_com_h osa_edgejava
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_hosa_edgeja va
* Method: main
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_hosa_e dgejava_main
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
the implementation of native function is as below
#include "com_hosa_edgej ava.h"
#include <jni.h>
#include <cv.h>
#include <highgui.h>
using namespace cv;
JNIEXPORT jint JNICALL Java_com_pes_ed gejava_main(JNI Env *, jobject){
VideoCapture cap(0); // open the default camera
if(!cap.isOpene d()) // check if we succeeded
return -1;
Mat edges;
namedWindow("ed ges",CV_WINDOW_ AUTOSIZE);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(ed ges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
the android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include /home/srijith/android-opencv/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
LOCAL_MODULE := edgejava
LOCAL_SRC_FILES := edgecpp.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_ LIBRARY)
the application.mk
APP_MODULES := edgejava
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
the activity file is as follows
package com.hosa;
import android.app.Act ivity;
import android.os.Bund le;
public class Andedge2Activit y extends Activity {
edgejava nativelib;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceSt ate) {
super.onCreate( savedInstanceSt ate);
setContentView( R.layout.main);
nativelib= new edgejava();
int i=nativelib.mai n();
System.out.prin tln("value returned to andedgeactivity "+i);
}
}
All necessary changes to the manifest has been done like mention of use of camera and permissions has been set.
I have tried writing a jni call for the simple c code. when i try to install this on the phone running 2.3.3 it doesnt install, sometimes even if it installs then it is being force closed.Please help me with this. the code details are as follows:
The java code of which i generate the header file.
package com.hosa;
public class edgejava{
static{
System.loadLibr ary("edgejava") ;
}
public native int main();
}
the generated header file is as below
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_hosa_edgeja va */
#ifndef _Included_com_h osa_edgejava
#define _Included_com_h osa_edgejava
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_hosa_edgeja va
* Method: main
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_hosa_e dgejava_main
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
the implementation of native function is as below
#include "com_hosa_edgej ava.h"
#include <jni.h>
#include <cv.h>
#include <highgui.h>
using namespace cv;
JNIEXPORT jint JNICALL Java_com_pes_ed gejava_main(JNI Env *, jobject){
VideoCapture cap(0); // open the default camera
if(!cap.isOpene d()) // check if we succeeded
return -1;
Mat edges;
namedWindow("ed ges",CV_WINDOW_ AUTOSIZE);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(ed ges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
the android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include /home/srijith/android-opencv/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
LOCAL_MODULE := edgejava
LOCAL_SRC_FILES := edgecpp.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_ LIBRARY)
the application.mk
APP_MODULES := edgejava
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
the activity file is as follows
package com.hosa;
import android.app.Act ivity;
import android.os.Bund le;
public class Andedge2Activit y extends Activity {
edgejava nativelib;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceSt ate) {
super.onCreate( savedInstanceSt ate);
setContentView( R.layout.main);
nativelib= new edgejava();
int i=nativelib.mai n();
System.out.prin tln("value returned to andedgeactivity "+i);
}
}
All necessary changes to the manifest has been done like mention of use of camera and permissions has been set.