Ask Your Question

elish's profile - activity

2020-04-11 10:10:59 -0600 received badge  Notable Question (source)
2020-03-12 12:43:48 -0600 received badge  Popular Question (source)
2018-11-14 00:47:31 -0600 received badge  Popular Question (source)
2016-09-11 05:37:32 -0600 asked a question Image view disappears during tracking

Hi,

I am working on an augmented reality app in android,
I have an imageView overlayed on opencv camera and i am moving it according to the average movement of the phone.
The problem is, that when its moved lower then its height it starts disappearing.
I can not understand why.

this is the xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.benzy.image.MainActivity"
tools:showIn="@layout/activity_main"
android:id="@+id/camera_preview">

<org.opencv.android.JavaCameraView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:id="@+id/tutorial1_activity_java_surface_view"
    opencv:show_fps="true"
    opencv:camera_id="any" />
<ImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:id="@+id/iv"
    android:alpha=".5"/>

</RelativeLayout>

Can any one help me figure it out? Tank you!!

2016-09-07 10:27:40 -0600 asked a question Increase org.opencv.android.JavaCameraView fps

Hi,

I am working on an android app using opencv and java camera (org.opencv.android.JavaCameraView ),
I had a problem with the frame resolution so i changed something in opencv source code and it solved it.
But it caused a problem that now the frame rate is very low, it is about 6 and it use to be more then 20, and i need it to be that because i process the frames and i need them to be fast.

How can i set this problem??

Thanks!!

2016-09-05 01:04:01 -0600 asked a question Set good aspect ratio for CvCameraViewListener2 camera frames in android

Hi,

I have a problem displaying the frames from CvCameraViewListener2 camera in android,
Something happens to the ratio of the frames and i can not set it to be normal and correct resolution.

Does any one know how can i set or resize the frames so it should look correct?

Thanks in advance!!

2016-09-04 07:37:09 -0600 commented answer how to use submat for a non square image

@berak Thank you so much berak, it is a perfect answer for me!

2016-09-04 05:51:26 -0600 asked a question how to use submat for a non square image

Hi,

I am working on an augmented reality app in android,
I am trying to overlay an image that is a shape of a star, its not a full squar onto the camera frame,

       dst.copyTo(submat);

but i get a black square in roi area and in the middle is the star.

How can i limit the size of submat to be the shape i want,
Is there a way to copy pixels instead of rows and cols?

Thank you!!

2016-09-04 05:33:43 -0600 commented answer convert a Mat type to be a type of frame Mat

@berak Thank you very much!! it worked!!

2016-09-04 04:43:27 -0600 asked a question convert a Mat type to be a type of frame Mat

Hi,

I am working on an augmented reality app in android,
In "onCameraFrame" i am trying to overlay a small Mat which is an image that was converted from bitmap, onto frame Mat that will be returned to camera preview, i am using submat to do it.
The problem is that the 2 Mat objects need to be the same type and i can not get the way to do it.

when i print the type of the small mat -

ImageMat.type()

i get 24.
when i print the frame Mat -

rgba.type()

i get 16.
How can i make the first one also 16 ?

2016-09-01 06:42:37 -0600 asked a question Paste a Mat onto another Mat

Hi,

I am creating an augmented reality app in android using opencv,
In "onCameraFrame" before returning the Mat (which is the preview frame) i want to paste on it another smaller Mat, i am doing it but nothing is happening, this is the line -

ImageMat.copyTo(frame.submat(120, ImageMat.rows(), 120, ImageMat.cols()));

Can any one help?
Thanks!!

2016-08-28 03:59:57 -0600 commented question Draw circles on opencv camera preview

@berak Hi, i explained it. thank you!

2016-08-28 03:32:33 -0600 asked a question Draw circles on opencv camera preview

Hi, i am trying to draw circles on a CameraBridgeViewBase - opencv camera on android,
But i need to do it on a point that i am not in onCameraFrame any more - i am doin tracing , and i need to check why my image is not tracking the way i whant, so on the point where i calculate the average movement of the camera to know where to put the image, here i need to draw the circle - it is on a separate thread, so i can not use Core.circle(),
Is there a way to do such a thing? how?

Thanks!!!

2016-08-10 02:55:06 -0600 asked a question Convert org.opencv.core.Point[] pointsTmp to MatOfPoint2f

Hi,

I need to convert an org.opencv.core.Point[] array to a MatOfPoint2f array, And i can not find a way to do it.

This is my org.opencv.core.Point[] array named pointsTmp

org.opencv.core.Point[] pointsTmp = tmpPts.toArray();
for (org.opencv.core.Point p : pointsNext) {

     if(byteArray[count]==1){

          Core.circle(tmp2, p, 8, circleColor);
          pointsTmp[i]=p;
          i++;
     }
     count++;
}

can any one help me convert it to a MatOfPoint2f array type?

Tanks in advance!

2016-07-31 03:17:32 -0600 commented question OpenCV Error: Assertion failed (prevPyr[level * lvlStep1].size() == nextPyr[level * lvlStep2].size()) in void cv::calcOpticalFlowPyrLK

@berak They seem to be ok, with tmp i was able to find goodFeaturesToTrack and draw it on the image, and second tmp seems to be the same.

2016-07-18 08:23:07 -0600 asked a question OpenCV Error: Assertion failed (prevPyr[level * lvlStep1].size() == nextPyr[level * lvlStep2].size()) in void cv::calcOpticalFlowPyrLK

I am working on 2 images, on the first one i found goodFeaturesToTrack and draw it then on it, i am trying to to tracking with that to the second image but the line of calling calcOpticalFlowPyrLK gets an error:

error(): OpenCV Error: Assertion failed (prevPyr[level * lvlStep1].size() == nextPyr[level * lvlStep2].size()) in void  cv::calcOpticalFlowPyrLK(InputArray, InputArray, InputArray, InputOutputArray, OutputArray, OutputArray, Size, int, cv::TermCriteria, int, double), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/video/src/lkpyramid.cpp, line 979

And i do not understand what the proble, is.

    MatOfPoint2f prevPts = new MatOfPoint2f();
    MatOfPoint2f nextPts = new MatOfPoint2f();
    MatOfByte status = new MatOfByte();
    MatOfFloat err = new MatOfFloat();
    //when to stop
    TermCriteria optical_flow_termination_criteria=new TermCriteria();
    optical_flow_termination_criteria.epsilon=0.3;
    optical_flow_termination_criteria.maxCount =20;
    int maxlevel = 2;
    Size s = new Size( 21, 21);


    MatOfPoint corners = new MatOfPoint();
    Imgproc.goodFeaturesToTrack(tmp,corners,maxCorners,qualityLevel,minDistance,newMat(),blockSize,
  useHarrisDetector,k);

    org.opencv.core.Point[] points = corners.toArray();
    for (org.opencv.core.Point p : points) {
        Core.circle(tmp2, p, 8, circleColor);
    }

    corners.convertTo(prevPts, CvType.CV_32FC2);

    Video.calcOpticalFlowPyrLK(tmp, secondtmp, prevPts, nextPts, status, err,s,maxlevel,optical_flow_termination_criteria,2,1);

Thank in advance!!

2016-07-17 07:46:57 -0600 asked a question Using android camera and processing frames for tracking

Hi,

I need to do tracking using opencv in android,
I can't find a way to process the frames and then show them on preview.
Is the way to do it is not to show the camera preview and just paste the processed frame on screen?

Thank you!

2016-07-05 03:23:25 -0600 commented answer Hot to convert a Mat object to byte[] data object in "onPreviewFrame" and show it in camera preview

@berak I tried to do it in onCameraFrame() but the resolution of the camera preview of CvCameraViewListener2 was very bad. Can i use the camera of android and together with that use CvCameraViewListener2 only for onCameraFrame and it will work?

2016-07-04 07:37:18 -0600 asked a question Hot to convert a Mat object to byte[] data object in "onPreviewFrame" and show it in camera preview

In my android app, I am trying to take frames in "onPreviewFrame" and convert them to Mat object so i can do on them some image processing, but i don't know how to convert them back to byte[] type and make them be shown on camera preview.

Does any one know how to do that?

Here is my onPreviewFrame function, i am trying to change frame color to grey:

public void onPreviewFrame(byte[] data, Camera arg1)
{
    Mat mRgba = new Mat(PreviewSizeWidth, PreviewSizeHeight, CvType.CV_8UC3);
    mRgba.put(0, 0, data);

    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_BGR2GRAY);
    mRgba.put(0, 0, data);

    mCamera.addCallbackBuffer(data);

}

Thanks in advance!

2016-07-02 15:41:52 -0600 asked a question onCameraFrame returns mat with bad resolution and small.

I am a beginner and trying to show camera preview in JavaCameraView with CvCameraViewListener2,
I get very bad resolution, and not managing to get size of preview to be full screen.

My onCameraViewStarted is:

    mRgba = new Mat(height, width, CvType.CV_8UC4);
    mRgbaF = new Mat(height, width, CvType.CV_8UC4);
    mRgbaT = new Mat(width, width, CvType.CV_8UC4);

And my onCameraFrame code is:

    mRgba = inputFrame.rgba();
    Core.transpose(mRgba, mRgbaT);
    Imgproc.resize(mRgbaT, mRgbaF, mRgbaF.size(), 0, 0, 0);
    Core.flip(mRgbaF, mRgba, 1);

    return mRgba;

Thanks in advance!

2016-06-14 04:48:04 -0600 asked a question How to force "org.opencv.android.JavaCameraView" preview to be full screen

Hi,

I am trying to set org.opencv.android.JavaCameraView to be full screen, but its not working,

This is main xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.benzy.image.MainActivity"
tools:showIn="@layout/activity_main"
android:id="@+id/camera_preview">

<org.opencv.android.JavaCameraView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:id="@+id/tutorial1_activity_java_surface_view"
    opencv:show_fps="true"
    opencv:camera_id="any" />

</RelativeLayout>

This is the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.benzy.image">

<!--<uses-sdk
     android:minSdkVersion="10"
     android:targetSdkVersion="19" />-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>

<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!--<uses-feature android:name="android.hardware.camera.front" android:required="false" />-->


<supports-screens android:resizeable="true"
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:anyDensity="true" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">





        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

The main activity:

public class MainActivity extends Activity implements CvCameraViewListener2{


private static final String TAG = "OCVSample::Activity";

// Loads camera view of OpenCV for us to use. This lets us see using OpenCV
private CameraBridgeViewBase mOpenCvCameraView;

// Used in Camera selection from menu (when implemented)
private boolean              mIsJavaCamera = true;
private MenuItem             mItemSwitchCamera = null;

// These variables are used (at the moment) to fix camera orientation from 270degree to 0degree
Mat mRgba;
Mat mRgbaF;
Mat mRgbaT;

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;
        }
    }
};

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);


    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.content_main);

    mOpenCvCameraView = (JavaCameraView) findViewById(R.id.tutorial1_activity_java_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();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this, mLoaderCallback);
    } else {
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

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

public void onCameraViewStarted(int width, int height) {

    mRgba = new Mat(height, width, CvType.CV_8UC4);
    mRgbaF = new Mat(height, width, CvType.CV_8UC4);
    mRgbaT = new Mat(width, width, CvType.CV_8UC4);
}

public void ...
(more)
2016-06-08 04:54:20 -0600 asked a question Cannot find opencv2 in native c++ android studio

I have a project in android studio, I added native c++ file, and in that file i am trying to include:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

but he cannot find the opencv2. In my main activity i checked-

(!OpenCVLoader.initDebug())

and it is loaded.
Does any one know why he cannot find the opencv2 ?
Thank you!

2016-06-07 03:30:02 -0600 received badge  Student (source)
2016-06-07 02:30:10 -0600 asked a question System.loadLibrary(...) could not find native library in my case

I want to create a simple android project using native libs,
I copied existing native library from another Android project into my android project under jniLibs folder.
I am new in this, i will appreciate any help,

In my java code I load the library by:

public native String helloWorld();
static{
    System.loadLibrary("ndktest");
}

When I run my new android project, I got an error:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.benzy.finalimage-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.benzy.finalimage-2/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libndktest.so"

And i don't have that file nowhere in my project.

The content of Android.mk is:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := ndktest

LOCAL_SRC_FILES := ndktest.c

include $(BUILD_SHARED_LIBRARY)

The content of Application.mk is:

APP_ABI := all

And my ndktest.c file is:

#include <jni.h>
#include <string.h>

jstring java_com_example_benzy_finalimage_MainActivity_helloWorld(JNIEnv* env,jobject obj){

      return (*env)->NewStringUTF(env,"hello world jni");
}

Thank you all.

2016-06-01 04:47:45 -0600 commented answer make white background of image transparent using android

Wow wow, if it is just "a per-pixel loop..." why didn't you answer this question?

2016-06-01 02:47:35 -0600 received badge  Editor (source)
2016-05-31 11:54:38 -0600 asked a question grab frames from camera buffer and display them in an image view using android opencv

Hi, I am trying to make an app that shows camera preview, And i want to take frames of the shown preview and do on it processing.

What is working is the camera preview,but I don't find any solution how to get the frames.

if any one has done something like that and can share it i would appreciate it very much.

Thank's!

2016-05-31 11:38:33 -0600 marked best answer make white background of image transparent using android

I am trying to take an image from drawable and make it's white background transparent Thank you!

2016-05-31 11:38:33 -0600 received badge  Scholar (source)
2016-05-31 11:38:28 -0600 answered a question make white background of image transparent using android

I found a solution, i would like to share it -

        // imageToShow is Bitmap
        int imgWidth = imageToShow[0].getWidth();
        int imgHeight = imageToShow[0].getHeight();
        int pixel;
        imageToShow[0].setHasAlpha(true);

        for(int i =0;i<imgWidth;i++) {
            for(int j=0;j<imgHeight;j++) {
                pixel = imageToShow[0].getPixel(i, j);
                if(Color.red(pixel)==255 && Color.green(pixel)==255 && Color.blue(pixel)==255){ //if white
                     imageToShow[0].setPixel(i, j, Color.argb(0x00, 0xff, 0xff, 0xff));//make it transparent

            }
        }

        imageView.setImageBitmap(imageToShow);
2016-05-25 00:13:54 -0600 received badge  Enthusiast