Ask Your Question

My User's profile - activity

2017-01-26 05:51:56 -0600 asked a question OpenCV Matrix get wrong values JNI Java

I'm trying to pass OpenCV Matrix to a cpp file but the data I read from the Matix in the cpp is not right.

I don't know what I'm missing here, Maybe something with the pointer.

This is part of my cpp file:

 jintArray
Java_qc_yotm_mes_com_yo_1qc_MainActivity_stringFromJNI(JNIEnv *env,jclass cls,jint NUMBER_OF_HALF_LINES, jint HALF_LINE_LENGTH, jlong inMat) {

    cv::Mat* GraySubMat =  (cv::Mat*)inMat;
    unsigned char * MatData = GraySubMat->data;

    jdouble SumSpikesHeight = 0;
    jint ListOfPeaks = 0;

    jintArray ListSpikesCount = env->NewIntArray(2 * NUMBER_OF_HALF_LINES);
    jintArray ListSpikesCountHeight = env->NewIntArray(2 * NUMBER_OF_HALF_LINES);

    jint outarray[2 * NUMBER_OF_HALF_LINES];


    for(int line_number = 0 ; line_number <  2 * NUMBER_OF_HALF_LINES ; line_number++) {
        //Find Peaks on every 5 pixels
        for (int i = 2; i < (HALF_LINE_LENGTH * 2) - 3; i++) {

            if ((MatData[(line_number *HALF_LINE_LENGTH * 2)+i] > MatData[(line_number *HALF_LINE_LENGTH * 2)+i - 1]) && (MatData[(line_number *HALF_LINE_LENGTH * 2)+i] > MatData[(line_number *HALF_LINE_LENGTH * 2)+i - 2]) &&
                (MatData[(line_number *HALF_LINE_LENGTH * 2)+i] > MatData[(line_number *HALF_LINE_LENGTH * 2)+i + 1]) && (MatData[(line_number *HALF_LINE_LENGTH * 2)+i] > MatData[(line_number *HALF_LINE_LENGTH * 2)+i + 2]) &&
                (MatData[(line_number *HALF_LINE_LENGTH * 2)+i] > 0) ) {
                ListOfPeaks++;
                SumSpikesHeight += MatData[(line_number *HALF_LINE_LENGTH * 2)+i];

                i += 3;
            }
        }

        outarray[line_number] = ListOfPeaks*SumSpikesHeight;

        SumSpikesHeight = 0;
        ListOfPeaks=0;
    }
    env->SetIntArrayRegion(ListSpikesCountHeight, 0, 2 * NUMBER_OF_HALF_LINES, outarray);
    return ListSpikesCountHeight;
}

This is the Java call:

 int[] spikecountheight = stringFromJNI(NUMBER_OF_HALF_LINES, HALF_LINE_LENGTH, GraySubMat.getNativeObjAddr());
2016-09-14 02:28:06 -0600 asked a question gl_FragColor get different color depends on andorid device

In my app I'm doing some image pixels manipulations. My code based on THIS example.

The only change that I've made is to change the FRAGMENT_SHADER to a grayscale and it looks like this:

private static final String FRAGMENT_SHADER =
        "#extension GL_OES_EGL_image_external : require\n" +
        "precision mediump float;\n" +      // highp here doesn't seem to matter
        "varying vec2 vTextureCoord;\n" +
        "uniform samplerExternalOES sTexture;\n" +
        "void main() {\n" +
        "    vec4 tc = texture2D(sTexture, vTextureCoord);\n" +
        "    gl_FragColor.r = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    gl_FragColor.g = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    gl_FragColor.b = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "}\n";

The problem: I've recorded a video from Galaxy s7 device, after recording I've taken the recorded video and I was reading the first frame from 2 different devices(Galaxy S7 and Galaxy s3), I found that the pixel values are absolutely different between those devices.

Does someone know why does it happen? and what can I do in order to solve this issue, since my algorithm fails because of this differences?

Update:

This is example of the diferences I've got.

Gaaxy S3: Part of the matrix 213, 214, 212, 214, 216, 214, 213, 212, 212, 212, 213, 214, 214, 214, 213, 213, 214, 214, 214, 214, 212, 213, 212, 213, 212, 214, 214, 212, 212, 210, 211, 210, 211, 210, 211, 211, 214, 211, 214, 213, 213, 214, 214, 216, 216, 216, 215, 215, 216, 212, 213, 213, 214, 213, 213, 212, 211, 209, 209, 207, 208, 208, 210, 211, 209, 207, 209, 210, 217, 219, 216, 209, 209, 210, 210, 210, 211, 209, 207, 205, 205, 206, 210, 210, 220, 211, 202, 210, 211, 206, 206, 209, 210, 211, 213, 219, 222, 216, 217, 217

count of non zeroes pixels: 1632816

Sum of all the pixels: 3.1834445E8

Galaxy S7: same part of the Matrix as Galaxy 3 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, 164

count of non-zeros pixels: 1063680

Sum of all the pixels: 1.6593408E8

Update2:

I found that the image received is absolutely ruined, but the video recorded well. This is the good image from Galaxy S3: enter image description here

And this is the image I've got from Galaxy S7 (Same frame#) enter image description here

I have no Idea at all what is going here, but I know that the last image is the same for ... (more)

2016-04-18 01:55:14 -0600 asked a question Use OpenCV without any external installation Android

Hi,

I'm using OpenCV on Android devices.

I have 2 kinds of problem using OpenCV libraries:

  1. If I'm trying to download the OpenCV package by using the apk file, The user interrupted twice, first, he needs to go to settings and change the "Unknown sources" option and after it install the OpenCV.

  2. If I'm using the option to let the user download the OpenCV Manager from google play, I'll take a risk that maybe a new version should not work with my app(already happened).

I'm using really few OpenCV functions.

I would like to know if there is a way to use OpenCV Manager/OpenCV specific libraries without any interrupt to external installation?

2016-01-17 05:22:27 -0600 commented question From where OpenCV samples load libopencv_java.so ?

Did you try to use it?

2016-01-03 05:20:44 -0600 asked a question Imgproc.BORDER_REPLICATE not exist in OpenCV Manager 3.0.1

Hi,

I have tried to upgrade the OpenCV manager to version 3.0.1 but I've got this error:

BORDER_REPLICATE cannot be resolved or is not a field

Can someone tell me how can I fix this issue?

2016-01-03 04:59:53 -0600 commented question From where OpenCV samples load libopencv_java.so ?

Sorry, but I can't do what they did, cause I can't work with OpenCV 3.0, the reason is that there is no implementation to the constant 'Imgproc.BORDER_REPLICATE' and as I see I don't need to work with this version because the sample projects works fine with version 2.4. am I right?

2015-12-21 03:17:43 -0600 commented question From where OpenCV samples load libopencv_java.so ?

How can I do that?

2015-12-20 01:55:05 -0600 commented question From where OpenCV samples load libopencv_java.so ?

why OpenCV application that came with sdk 2.4.9 worked and mine not? it trying to load the same library

2015-12-19 03:38:47 -0600 commented question From where OpenCV samples load libopencv_java.so ?

So, what should I do?

2015-12-15 05:01:03 -0600 asked a question From where OpenCV samples load libopencv_java.so ?

Hi,

I would like to know from where or how did OpenCV load libopencv_java.so file to the device?

The sample project(Face Detection) of OpenCV work fine, but If I try to load OPENCV_VERSION_2_4_3, it's falied to load the libopencv_java file, and the following error was shown:

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/org.opencv.engine-1/lib/arm/libopencv_java.so" is 32-bit instead of 64-bit

Why is my libopencv_java is different if I use the same sdk?

2015-12-15 03:16:48 -0600 commented question libopencv_java.so - 64bit Android

Is something work here?

2015-12-10 07:26:34 -0600 commented question libopencv_java.so is 32-bit instead of 64-bit in android eclipse issue

I changed it, but as I said it doesn't work and now also the Opencv samples doesn't work.

2015-12-10 06:24:25 -0600 commented question libopencv_java.so is 32-bit instead of 64-bit in android eclipse issue

Ok, I tried to use SDK 3.0.0 but it's not the problem, It still the same problem

2015-12-10 04:02:18 -0600 commented question libopencv_java.so is 32-bit instead of 64-bit in android eclipse issue

I'm using SDK version 2.4.9, I also tried to work with 3.0 but in that SDK There is a missing variable called "BORDER_REPLICATE", So I didn't trying to run it.

One more thing that is wired, Is that the sample application of the OpenCV works fine with the 2.4.9 SDK

2015-12-10 01:24:02 -0600 commented question libopencv_java.so is 32-bit instead of 64-bit in android eclipse issue

Can someone help here please.

2015-12-10 01:21:11 -0600 received badge  Enthusiast
2015-12-09 01:19:01 -0600 asked a question libopencv_java.so is 32-bit instead of 64-bit in android eclipse issue

Hi,

This is the error that I've got after I trying to load the library in loadLibrary function inside AsyncServiceHelper class.

*My application work in android devices that run version bellow lollipop. *The OCV Face Detection run fine so I know that this is something in my app.

I already look over websites but nothing found to work.

Do anyone face with this error?

2015-12-06 02:29:43 -0600 asked a question initDebug can't load library in android 5.0

I think that my problem is a basic one.

Till now I work on devices that runs android version less than Lollipop and everything works fine.

Now after I tried to work with Lollipop, the same code doesn't work.

After a search on web I found some solutions but nothing works for me:

  1. I was changed the initOpenCV function to this:

    public static boolean initOpenCV(String Version, final Context AppContext,
        final LoaderCallbackInterface Callback) {
        AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext,
                Callback);
        Intent intent = new Intent("org.opencv.engine.BIND");
        intent.setPackage("org.opencv.engine");
        if (AppContext.bindService(intent, helper.mServiceConnection,
                Context.BIND_AUTO_CREATE)) {
            return true;
        } else {
            AppContext.unbindService(helper.mServiceConnection);
            InstallService(AppContext, Callback);
            return false;
        }
    }
    
  2. I called the library statically :

    static {
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
        Log.d("OpenCVManager/Helper", "opencv - Handle initialization error");
    }
    

    }

  3. I changed the apk file to :

OpenCV_3.0.0_Manager_3.00_armeabi-v7a.apk

I just have to say that I tried also to run the samples from Opencv folder and they're work.

Another thing that can maybe cause the problem is that I called to the static method not from Activity extended class.

This is a part of my code:

public class CodecOutputSurface implements  SurfaceTexture.OnFrameAvailableListener 
{

    static {
        if (!OpenCVLoader.initDebug()) {
            // Handle initialization error
            Log.d("OpenCVManager/Helper", "opencv - Handle initialization error");
        }
    }

        Mat mainMat;

        /**
         * Creates a CodecOutputSurface backed by a pbuffer with the specified dimensions.  The
         * new EGL context and surface will be made current.  Creates a Surface that can be passed
         * to MediaCodec.configure().
         */
        public CodecOutputSurface(int width, int height, int frameSize,int frameSizeROI,  int _iteration, SurfaceHolder surfaceHolder, int Screenwidth, int Screenheight, int _zoom , Activity _parentActivity) {

            try{

                mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);

                eglSetup();
                makeCurrent();
                setup();
                Log.v("My Error", "End CodecOutputSurface constructor");
            }
            catch(Exception ex)
            {Log.v("My Error", "CodecOutputSurface constructor Exception -" + ex.toString());}
        }

        private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(parentActivity) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                    case LoaderCallbackInterface.SUCCESS:
                    {
                        Log.v("My Error", "Start SetMatix");
                        mainMat =  new Mat(new Size(mWidth,mHeight),CvType.CV_8U);
                        //Mat TempmMainMat = new Mat(new Size(mainMat.width(),mainMat.height()),mainMat.type());
                        Log.v("My Error", "Start SetMatix1");
                        GrayImage1 = new Mat(new Size(CROPPED_FRAME_SIZE_WIDTH,CROPPED_FRAME_SIZE_HEIGHT),CvType.CV_8U);
                        GrayImage2 = new Mat(new Size(CROPPED_FRAME_SIZE_WIDTH,CROPPED_FRAME_SIZE_HEIGHT),CvType.CV_8U);
                        Log.v("My Error", "End SetMatix");
                    } break;
                    default:
                    {
                        super.onManagerConnected(status);
                    } break;
                }
            }
        };
2015-12-03 06:15:32 -0600 received badge  Editor (source)
2015-12-03 04:00:45 -0600 asked a question Cannot load library /libopencv_java.so on android 5.0

Hi,

I have android application that read a video frame by frame and do some manipulation on the input frames.

My app work fine on any android version less Lollipop.

At Lollipop version my app was crashed and after debug I found that the OpenCV is the issue and I get this in logcat:

12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Service connection created
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Trying to get library path
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Trying to get library list
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Library list: "libopencv_java.so"
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): First attempt to load libs
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Trying to init OpenCV libs
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Trying to load libs by dependency list
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Trying to load library /data/app/org.opencv.engine-1/lib/arm/libopencv_java.so
12-03 11:22:25.901: D/OpenCVManager/Helper(6260): Cannot load library "/data/app/org.opencv.engine-1/lib/arm/libopencv_java.so"
12-03 11:22:25.911: D/OpenCVManager/Helper(6260): First attempt to load libs fails
12-03 11:22:25.911: D/OpenCVManager/Helper(6260): Init finished with status 255
12-03 11:22:25.911: D/OpenCVManager/Helper(6260): Unbind from service
12-03 11:22:25.911: D/OpenCVManager/Helper(6260): Calling using callback

this is a part of mt code:

  public CodecOutputSurface(int width, int height, int frameSize,int frameSizeROI,  int _iteration, SurfaceHolder surfaceHolder, int Screenwidth, int Screenheight, int _zoom , Activity _parentActivity) {

            try{
                Log.v("My Error", "Start CodecOutputSurface constructor");
                msurfaceHolder1 = surfaceHolder;
                FRAME_SIZE = frameSize;
                FRAME_SIZE_ROI = frameSizeROI;
                iteration = _iteration;
                if (width <= 0 || height <= 0) {
                    throw new IllegalArgumentException();
                }
                mEgl = (EGL10) EGLContext.getEGL();
                mWidth = width;
                mHeight = height;

                frameWidth = mWidth;
                frameHeight = mHeight;
                startX = 0; 
                startY = 0;

                mScreenwidth1 = Screenwidth;
                mScreenheight1= Screenheight;
                parentActivity = _parentActivity;

                 //If I comment the line bellow the error doesn't called.
                OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, parentActivity, mLoaderCallback);

                SumDiff1 = new ArrayList<Double>();
                SumDiff2 = new ArrayList<Double>();
                MeanDiff = new ArrayList<Double>();
                eglSetup();
                makeCurrent();
                zoom = _zoom;
                setup();
                Log.v("My Error", "End CodecOutputSurface constructor");
            }
            catch(Exception ex)
            {Log.v("My Error", "CodecOutputSurface constructor Exception -" + ex.toString());}
        }

I tried to find solution in the web but nothing helped me.
Again the application work fine with previous android versions.

It is something known?