Ask Your Question

and.ryx's profile - activity

2013-10-12 05:11:09 -0500 received badge  Editor (source)
2013-10-09 09:32:04 -0500 asked a question Acquiring and Viewing frames in separate thread on android

Hi! As the title of question suggest i need to acquire and view frame by camera in two separate thread, not in the same as is common using. The main scope of this splitting is that i've after make these thread parts of a server process and client process.

Since the common way to obtain frame (in a gray scale on my case) and view it is as i shown in tutorial1 sample:

public class Tutorial1Activity extends Activity implements CvCameraViewListener2 {
    private static final String TAG = "OCVSample::Activity";

    private CameraBridgeViewBase mOpenCvCameraView;
    private boolean              mIsJavaCamera = true;
    private MenuItem             mItemSwitchCamera = null;

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    public Tutorial1Activity() {
        Log.i(TAG, "Instantiated new " + this.getClass());
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.tutorial1_surface_view);

        if (mIsJavaCamera)
            mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);
        else
            mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view);

        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

        mOpenCvCameraView.setCvCameraViewListener(this);
    }

    @Override
    public void onPause()
    {
        super.onPause();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
    }

    public void onDestroy() {
        super.onDestroy();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        Mat mOutput = inputFrame.gray();

        return mOutput;
    }
}

instead to use the same class for the viewing of the Mat returned by onCameraFrame() i would that this is work of an other thread for example,

thread for acquiring:

public class AcquireThread implements Runnable, CvCameraViewListener{
// I know the interface class for siply acquire frames may be wrong
}

thread for viewing:

public class ViewThread implements Runnable, CvCameraViewListener2{

}

I hope someone can help me :D!!

2013-10-02 05:10:34 -0500 commented answer Accessing to OpenCv cell values of Mat from native c++ function of android app

Thank you bery much. I know that exist Sobel function that apply sobel filter to the image but, i have to do moreover than this application. So i just want to try manual filtering with a simple convolution! However i thank you again :-D !!

2013-10-02 05:07:11 -0500 received badge  Scholar (source)
2013-09-20 09:24:35 -0500 asked a question Accessing to OpenCv cell values of Mat from native c++ function of android app

:) I'm programming an algorithm for detect symmetric radial center of an image, to detect eyes position into face framePicture. I know that already exist a project of public domain that do this work, but i would base my work about another kind of studies.

This is the scenario:

Doing by hand this manipulation frame by frame, i have seen that writting code on java layer, like this:

private Mat mGray = new Mat(height,width,CvType.CV_8U);
private Mat mOut = new Mat(height,width,CvType.CV_8U);
private Mat mIntermediateMat = Mat.zeros(height,width,CvType.CV_32F);   

[...common methods of opencv app...]

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    switch (ImageManipulationsActivity.viewMode) {
    case ImageManipulationsActivity.VIEW_MODE_RGBA:
        mOut = inputFrame.rgba();
        break;

    case ImageManipulationsActivity.VIEW_MODE_MODIFY:
        mGray = inputFrame.gray();

        int h = mGray.rows();
        int w = mGray.cols();

        int sobxVal,sobyVal;    

        /** 
        * Appling manually sobel filtering to calculate dx and dy image, 
        * moreover calculate magnitudo matrix and cosValue and sinValue
        * matrices for computing, using lut techniques.
        */
        for(int i = 1; i < h-1; i++)
            for(int j = 1; j < w-1; j++) {
                sobxVal = (int) (
                        ((int)mGray.get(i-1,j)[0] << 1) +
                        mGray.get(i-1,j-1)[0] +
                        mGray.get(i-1,j+1)[0] - (
                        ((int)mGray.get(i+1,j)[0] << 1) +
                        mGray.get(i+1,j-1)[0] +
                        mGray.get(i+1,j+1)[0] ) );
                sobyVal = (int) (
                        ((int)mGray.get(i,j-1)[0] << 1) +
                        mGray.get(i-1,j-1)[0] +
                        mGray.get(i+1,j-1)[0] - (
                        ((int)mGray.get(i,j+1)[0] << 1) +
                        mGray.get(i-1,j+1)[0] +
                        mGray.get(i+1,j+1)[0] ) );
//      compute magnitudo and atan2
            }

//      ...other calculations...

        Core.convertScaleAbs(mIntermediateMat, mOut);

    }

    return mOut;
}

is not all efficient! So I decided to write c++ for a native function to manipulate matrix in this way:

Code by c++ side

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <math.h>
#include <vector>

#include <android/log.h>

#define LOG_TAG "Example Filter"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))

#define RADIUS 10
#define _K      9.9
#define _A      2   //radial strictness parameter, found experimentally
using namespace std;

using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(
        JNIEnv* env, 
        jobject, 
        jlong addrGray, 
        jlong addrRgba, 
        jlong addrlutCosSin,
        jlong addrlutM );

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(
        JNIEnv* env, 
        jobject, 
        jlong addrGray, 
        jlong addrOut, 
        jlong addrlutCosSin,
        jlong addrlutM )
{
    Mat& mGr  = *(Mat*)addrGray;
    Mat& mOut = *(Mat*)addrOut;
    Mat& lutCosSin = *(Mat*)addrlutCosSin;
    Mat& lutM = *(Mat*)addrlutM;
    int w = mGr.cols;
    int h = mGr.rows;
    double sobelxVal,sobelyVal,angle;

    Mat magnitudo(h,w,CV_32F,Scalar(0));
    Mat xMat(h,w,CV_8S,Scalar(0));
    Mat yMat(h,w,CV_8S,Scalar(0));
    Mat oMat(h,w,CV_32F,Scalar(0));
    Mat mMat(h,w,CV_32F,Scalar(0));
    /*
     * Convolves Matrix with Sobel ky kernel and Sobel kx kernel
     *ky = [ 1  2  1 ;
     *       0  0  0 ;
     *      -1 -2 -1 ]
     *
     *kx = [ 1  0 -1 ;
     *       2  0 -2 ;
     *       1  0 -1 ]
     *
     * doing dedicated computation 
     */
    for( int i = 1; i < h-1; i++ )
    {
        for (int j = 1; j < w-1; j++ )
        {
            sobelxVal = (mGr.at<int>(i-1,j ...
(more)