Giter Site home page Giter Site logo

dat-ng / ar-location-based-android Goto Github PK

View Code? Open in Web Editor NEW
202.0 202.0 85.0 3.92 MB

This AR app generally show where things are in the real-world by indicating where the app thinks they are over the camera view when the user holds the phone up and moves it about.

License: MIT License

Java 100.00%

ar-location-based-android's People

Contributors

dat-ng avatar sameerjj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ar-location-based-android's Issues

Is your code exported as a library?

Hello,

this is a very interesting implementation. I downloaded the app and it surely meets my needs.
Is it possible to have it as a library and have it imported through my gradle file?

Thank you in advance.

collide with one another

I want to show all the places near to user location. But the issue is all the places are near to each other and they collide with one another. How can I stack the views one above other without any collision.

Point Collision & add custom views instead of default circles (SOLUTIONS)

package ng.dat.ar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.location.Location;
import android.opengl.Matrix;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import ng.dat.ar.helper.LocationHelper;
import ng.dat.ar.model.ARPoint;

/**

  • Created by ntdat on 1/13/17.
    */

public class AROverlayView extends RelativeLayout {

private Context context;
private float[] rotatedProjectionMatrix = new float[16];
private Location currentLocation;
private final List<ARPoint> arPoints;
private final List<TextView> textViews;

public AROverlayView(Context context) {
    super(context);

    textViews = new ArrayList<>();

    this.context = context;
    this.setWillNotDraw(false);
    //Demo points
    arPoints = new ArrayList<ARPoint>() {{
        add(new ARPoint("New York", 40.7128, 74.0060, 50));
        add(new ARPoint("London", 51.5074, 0.1278, 100));
        add(new ARPoint("Frankfurn", 50.1109, 8.6821, 150));
        add(new ARPoint("Sydney", 33.8688, 151.2093, 200));
        add(new ARPoint("Rome", 41.9028, 12.4964, 250));
        add(new ARPoint("Athens", 37.9838, 23.7275, 300));
    }};


    for (int i = 0; i < arPoints.size(); i++) {

        textViews.add(new TextView(context));
        textViews.get(i).setTextSize(40);
        textViews.get(i).setBackgroundColor(Color.RED);
        this.addView(textViews.get(i));
    }
}


public void updateRotatedProjectionMatrix(float[] rotatedProjectionMatrix) {
    this.rotatedProjectionMatrix = rotatedProjectionMatrix;
    this.invalidate();
}

public void updateCurrentLocation(Location currentLocation) {
    this.currentLocation = currentLocation;
    this.invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (currentLocation == null) {
        return;
    }

    for (int i = 0; i < arPoints.size(); i++) {
        float[] currentLocationInECEF = LocationHelper.WSG84toECEF(currentLocation);
        float[] pointInECEF = LocationHelper.WSG84toECEF(arPoints.get(i).getLocation());
        float[] pointInENU = LocationHelper.ECEFtoENU(currentLocation, currentLocationInECEF, pointInECEF);

        float[] cameraCoordinateVector = new float[4];
        Matrix.multiplyMV(cameraCoordinateVector, 0, rotatedProjectionMatrix, 0, pointInENU, 0);

        // cameraCoordinateVector[2] is z, that always less than 0 to display on right position
        // if z > 0, the point will display on the opposite
        if (cameraCoordinateVector[2] < 0) {
            float x = (0.5f + cameraCoordinateVector[0] / cameraCoordinateVector[3]) * getWidth();
            float y = (0.5f - cameraCoordinateVector[1] / cameraCoordinateVector[3]) * getHeight();

            textViews.get(i).setX(x);
            textViews.get(i).setY(y);
            textViews.get(i).setText(arPoints.get(i).getName());
        }
    }
}

}

I do not see anything on camera.

I don't see anything on camera screen.It just display latitude, longitude and altitude on screen.I don't see any point on camera screen.Please let me know your view.

Azimuth

Hi! You've made a wonderful job with this example, however I think it can be improved if we take into account the azimuth.

From my understanding, you take the rotation values coming from the sensors and applying it to the Camera somehow. I didnt get the math yet of those operations.

However maybe if we compute the theoretical azimuth from the mobile to the object and the real azimuth of the device, maybe the drawed points can be filtered by some threshold

Do you think that would work in order to fix the issue with the moving points?

Best

Exception configuring surface

java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:2138)
at ng.dat.ar.ARCamera.surfaceChanged(ARCamera.java:215)

how can I apply low pass filter on it?

I want more accurate mark on camera view. As of now mark in camera is jiggling. I somewhere read that jiggling can be reduce by applying low pass filters. Anyone knows how to use that here.

Landscape orientation not working

i am using your code sample and your work is great but i have an issue
i need the orientation to be landscape the points is not being drawn correctly and they are not correctly moving over the camera view appreciate your help

Location Updates

Location for points works OK, but coords never update until I resume activity.

Its posible update coords of currentLocation when we are walking with the activity open?

Thanks a lot for this example is very useful, you safe my life.

Camera preview stretched

camera previewing the image as stretched in both horizontal and vertical orientation. the stretched level is look like double the original object size.

OnClick?

Is there a way, to add an OnClickListener for the ARPoints?

Changing or swapping around camera size

where exactly need to change if i may ask kindly?
I am new to this and its no much comment.
Could you give a small example how to change it to landscape?

After changing the camera size by swapping the target height to the width.

still not scroll horizontally

int targetHeight = width;

Collision between points

Two points get collide when they are near to each other. How to stack the points one above the other if they collide with each other. Please help.

flashback

The app can installed successfully. But when i open it , the app always flashback. The logcat is as below.

FATAL EXCEPTION: main
Process: ng.dat.ar, PID: 27374
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1953)
at ng.dat.ar.ARCamera.surfaceChanged(ARCamera.java:215)
at android.view.SurfaceView.updateWindow(SurfaceView.java:608)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5435)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Drawing distorted polylines and polygons

Hi @dat-ng actually I have a problem when I want to draw a polyline or a polygon on canvas. I made the calculates like you made in your project, but for my case I want to draw polylines and poligons like google maps. The issue is that I draw some them, they don't have the correct align. It's look like a error's margin on the calculate but I don't have any idea how I can correct it. Could you have some solution for this?

Here a screenshot with my app to the right and a page where I get the exact coordinates to the left.

artest

Not able to add TextView using Relative Layout.

I am creating location based AR app using Kotlin, in which i used RelativeLayout and added TextView in that RelativeLayout as below code.

class AROverlayByViewGroup(context: Context) : RelativeLayout(context)
{
val TAG: String = "AROverlayByViewGroup"
var rotatedProjectionMatrix: FloatArray = kotlin.FloatArray(16)
private var currentLocation: Location? = null
var arPoints: MutableList = ArrayList()
val cameraCoordinateVector: FloatArray = kotlin.FloatArray(4)

var parentHeight: Int? = null
var parentWidth: Int? = null

fun updateARPoints(arPoints: MutableList<ARPoint>)
{
    this.arPoints = arPoints
}

fun updateRotatedProjectionMatrix(rotatedProjectionMatrix: FloatArray)
{
    this.rotatedProjectionMatrix = rotatedProjectionMatrix
}

fun updateCurrentLocation(location: Location)
{
    this.currentLocation = location
    this.invalidate()
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {

    if (currentLocation == null) {
        return
    }

    for ((location, name) in arPoints) {
        val currentLocationInECEF: FloatArray = LocationHelper.WSG84toECEF(currentLocation!!)
        val pointInECEF: FloatArray = LocationHelper.WSG84toECEF(location)
        val pointInENU: FloatArray = LocationHelper.ECEFtoENU(currentLocation!!, currentLocationInECEF, pointInECEF)

        Matrix.multiplyMV(cameraCoordinateVector, 0, rotatedProjectionMatrix, 0, pointInENU, 0)

        if (cameraCoordinateVector[2] < 0) {

            val x: Float = (0.5f + cameraCoordinateVector[0] / cameraCoordinateVector[3]) * parentWidth!!
            val y: Float = (0.5f - cameraCoordinateVector[1] / cameraCoordinateVector[3]) * parentHeight!!

            val mTextView: TextView = TextView(this.context)
            mTextView.text = name
            mTextView.setTextColor(Color.BLUE)
            mTextView.textSize = 50F

            val params = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT)
            params.leftMargin = x.toInt()
            params.topMargin = y.toInt()

            this.addView(mTextView, params)

        }
    }
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec)

    parentWidth = MeasureSpec.getSize(widthMeasureSpec)
    parentHeight = MeasureSpec.getSize(heightMeasureSpec)

    Log.e(TAG, "width: " + parentWidth.toString())
    Log.e(TAG, "height: " + parentHeight.toString())
}

}

I am not getting any textview. What do i need to change for this?

App is not showing arpoints

I am geting right gps location but no arpoints are rendered on camera rotation. Maybe the sensor implementation?? I have a Moto G4 play runing Android Marshmallow

Why points are not fixed in android like iOS ?

Point of interest which are showing are not fixed. They change their positions.

Please, refer this link how the points are fixed in iOS from below link.
https://github.com/ProjectDent/ARKit-CoreLocation

I have applied low pass filter to the sensor values, then also I have the same problem. I don't have the proper knowledge of OpenGl matrix you used. Can It be corrected through matrix or some other way, please look at this, and kindly at-least revert back on this issue.

Use FusedLocationProviderApi of Google Play Services

Can you tell me why we need to use LocationManager of Android framework instead of the optimized FusedLocationProviderApi of Google Play Services?

I think the Fused one will better and consume less energy than the old LocationManager?

License

What is the license of this code?
Can I use it in commercial product?

Point question

Why is the point so unstable? It doesn't stop moving in the screen, and then it shows off for a while, and I don't have a mobile phone. Can you answer my question? Thanks~

OnClickListener for each ARPoint

First of all, thanks for this implementation. It is working as expected. By the way, getting gps location one time and making processes according to that fixed location provided me a more stable experience.

My question:
I want to add onclick listener for each ARPoint so a detail page of that point will be opened. Do you have any suggestion or code snippet for this?

High Precision

Hi,
I want to increase its precision to next level. As of now it is showing accurate direction moreover it shows two ARPoints overlaping if those points are differed by decimals in latitude and longitude. Any idea on this?

Points

I feel that the X and Y points that have been changed through the sensor are not very accurate. Is it the problem of the formula?

java.lang.RuntimeException: setParameters failed

To Everyone who's facing this problem :

Process: com.androidluckyguys, PID: 6480
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:2034)
at com.androidluckyguys.ARCamera.surfaceChanged(ARCamera.java:215)
at android.view.SurfaceView.updateWindow(SurfaceView.java:634)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:161)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2265)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1286)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6536)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

I solved the problem when the preview camera doesn't show up and being force closed.

I tried with high end LG devices and debug the ARCamera code to verify some values related to dimension supported.

I start with finding the preview value for width and height from surfaceChanged() :

       this.cameraWidth = width;
           this.cameraHeight = height;

           Camera.Parameters params = camera.getParameters();
           params.setPreviewSize(previewSize.width, previewSize.height);
           requestLayout();

           camera.setParameters(params);
           camera.startPreview();

           generateProjectionMatrix();

I got the supplied value was 1440 for width and 2072 for height. And this is the problem, the dimension supplied was too big and
not supported by the device itself. So I compared with the received value in supportPreviewSizes and I got :

SupportedPreviewSizes : size = 16

with this values :

1920x1080
1600x1200
1280x960
1280x768
1280x720
1024x768
......... and soon

So it proved that the index 0 of the supportedPreviewSizes is smaller than supplied value in this line
params.setPreviewSize(previewSize.width, previewSize.height);

The solution was easy : I changed the supplied value from the index 0 of supportedPreviewSizes so the line will be
params.setPreviewSize(supportedPreviewSizes.get(0).width,
supportedPreviewSizes.get(0).height);

and overall method will be like this

@UiThread
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(camera != null) {
if (!supportedPreviewSizes.isEmpty()){
this.cameraWidth = width;
this.cameraHeight = height;

           Camera.Parameters params = camera.getParameters();
           params.setPreviewSize(supportedPreviewSizes.get(0).width,
                   supportedPreviewSizes.get(0).height);
           requestLayout();

           camera.setParameters(params);
           camera.startPreview();

           generateProjectionMatrix();
       }
    }
}          

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.