Ask Your Question

sumitsh87's profile - activity

2020-03-11 09:46:33 -0600 received badge  Popular Question (source)
2014-05-07 11:10:09 -0600 received badge  Student (source)
2013-03-11 05:38:55 -0600 commented answer grab a frame without JNI Call

Low FPS is not a problem for me, but it must be fixed.

I cant used callback interface for it because they are not being called after an exact period od time. Its varying by a huge factor, which makes my intentions infeasible. with c++ I can use VideoCapture::grab() and retrieve() to grab image at a particular instant of time. that solves my issue. But can I do the same in JAVA somehow w/o JNI call?

2013-03-08 08:42:48 -0600 received badge  Editor (source)
2013-03-08 08:40:15 -0600 asked a question JNI call restarts the calling JAVA Activity

I am stuck at a strange problem, pretty strange!!

Problem : In the following project, a native method is called from java android using JNI call. Whenever the native method returns, the android activity restarts (oncreate callback method is called again). I confirmed this using a Log inside the "oncreate()". It all results into a recursion!! why??

Please help :(

JAVA CODE

   public class Brahma extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.brahma);
    Log.v("Sumit","on create called");
    TextView text=(TextView)findViewById(R.id.textView);
    ImageView img=(ImageView)findViewById(R.id.imageView);
    Mat inputFrame= new Mat();
    String str =JNIMessage(inputFrame.getNativeObjAddr());
    text.setText(str);

    Bitmap bmp = Bitmap.createBitmap(inputFrame.cols(), inputFrame.rows(),    
                                             Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(inputFrame, bmp);
    img.setImageBitmap(bmp);


}


public static native String JNIMessage(long l);

static 
{
    if (!OpenCVLoader.initDebug()) 
    {
        // Handle initialization error
    } else
        System.loadLibrary("brahma");
}

}

NATIVE CODE

  using namespace std;
  using namespace cv;

  extern "C"
  {
 JNIEXPORT jstring JNICALL Java_com_example_brahma_Brahma_JNIMessage(JNIEnv* , jobject, jlong);

 JNIEXPORT jstring JNICALL Java_com_example_brahma_Brahma_JNIMessage(JNIEnv* env, jobject      
  thiz,jlong addr)
  {
   static int i=0;
   char buffer[100];
   sprintf(buffer, "native function called : time : %d", i++);
       __android_log_print(ANDROID_LOG_INFO, "Sumit", buffer);
   Mat& frame  = *(Mat*)addr;
       VideoCapture cap(0); // open the default camera
   cap>>frame;
   return env->NewStringUTF("Success");

  }

   }
2013-03-08 02:26:43 -0600 asked a question grab a frame without JNI Call

Is there a way I can grab frames from android camera using openCV4android or JAVA Api without any JNI calls?

The reason is : I want a fixed fps for a particular application. I dont want to use the call back methods onCameraFrame (from CvCameraViewListener) or onPreviewFrame( using camera.onPreviewcallBack), which fails to give a fixed FPS.

I am desperate for help, after spending days :(

2013-03-04 03:42:23 -0600 commented answer How to decrease the number of processed frames from a live video camera?

I havethe same issue!! I want to know is grab() a native function? shall I need to make JNI calls? when I try to use the Videocapture class and instantiate an object inside onCameraStarted callback of opencv4android API to call grab () and retreive(), it is showing error!! Is it that It has to be in a c++ file and a JNI call need to be made??

2013-03-04 03:33:36 -0600 commented question grab() always returning false

ohk!! But the kind of error it is giving, I think there something to do with the native JNI call!! I am new to opencv. I am only using the JavaAPI for my small project and seems sufficient enough. Do I need to make JNI calls? Is it a native function (videocapture.open)?

what I understand from your comment is, instead of writing capture.open() function inside the callback function "void onCameraViewStarted(int width, int height) ", which tries to open the camera twice, I should write it inside oncreate() ?? but when I do it, I get the following error :

03-04 09:56:01.011: D/JavaCameraView(11016): Java camera view ctor 03-04 09:56:01.011: W/dalvikvm(11016): No implementation found for native Lorg/opencv/highgui/VideoCapture;.n_VideoCapture:(I)J

2013-03-03 07:47:30 -0600 commented question grab() always returning false

I am doing it like this : void onCameraViewStarted(int width, int height) { VideoCapture vidCapture=new VideoCapture(0); Boolean ifopen=vidCapture.open(0); Log.i("sumit", "is camera opened for grabbing : "+ifopen); Thread captureImageThread=new Thread(new cacheFrame()); captureImageThread.start(); Thread imageProcessThread=new Thread(new processFrame()); imageProcessThread.start();

}

However it is throwing error like this :

03-03 14:41:14.417: E/OpenCV_NativeCamera(5153): initCameraConnect: Unable to connect to CameraService 03-03 14:41:14.417: E/OpenCV::camera(5153): CameraWrapperConnector::connectWrapper ERROR: the initializing function returned false 03-03 14:41:14.417: E/OpenCV::camera(5153): Native_camera returned opening error: 6

2013-03-01 09:04:53 -0600 asked a question grab() always returning false

I am trying to capture real time synchronised images with android camera, at a fixed fps. I have an algorithm for that. But the grab() feature always return a false. i.e. I cant get any image captured. what can be the possible issue??

If I use the inputframe that I get from onCameraFrame(Mat inputframe) callback of CvCameraViewListener implemented activity, it works, then why not grab()??

 public void onCameraViewStarted(int width, int height) 
{

    capturedFrame=new Mat(height, width, CvType.CV_8UC4);
    vidCapture=new VideoCapture();
    Thread captureImageThread=new Thread(new cacheFrame());
    captureImageThread.start();
    ----------
            -----------
}

   private class cacheFrame implements Runnable
{

    @Override
    public void run()
    {

        while(true)
        {
            startTime = System.currentTimeMillis();

            if(vidCapture.grab())
            {
              Log.i("sumit", "frame  retreival started at : "+System.currentTimeMillis());
              vidCapture.retrieve(capturedFrame,Highgui.CV_CAP_ANDROID_GREY_FRAME);
            }
            if(capturedFrame!=null)
            {

               frameObject.image=capturedFrame.clone();
                 ---- 
                                     -----
                                     -----
                                     -----
                }       

            }


        }