Search code examples
android3daugmented-realityarcoresceneform

How can i scan a qr code from ARScene Camera usin ARCORE


Here I need some suggestion or a want to a way of doing this

Scenario: i want to scan a qr code in the ar scene and when i scan the qr code what ever content is there in qr code i will place in the ar scene here i dont want to use google vision instead i want to use the below package but the below package opens camera instead i want to use it in the AR scene it self

I used this package for qr scan https://github.com/zxing/zxing

below is my ar code

public class MainActivity extends AppCompatActivity {

    private ArFragment arFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
        arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
          Anchor anchor = hitResult.createAnchor();
            ModelRenderable.builder()
                    .setSource(this, Uri.parse("anchor.sfb"))
                    .build()
                    .thenAccept(modelRenderable -> addModelToScene(anchor,modelRenderable))
                    .exceptionally(throwable -> {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setMessage(throwable.getMessage()).show();
                        return  null;
                    });
        });
    }

    private void addModelToScene(Anchor anchor,ModelRenderable modelRenderable){
        AnchorNode anchorNode  = new AnchorNode(anchor);
        TransformableNode transformableNode  = new TransformableNode(arFragment.getTransformationSystem());
        transformableNode.setParent(anchorNode);
        transformableNode.setRenderable(modelRenderable);
        arFragment.getArSceneView().getScene().addChild(anchorNode);
        transformableNode.select();
    }
}

Solution

  • I recommend trying the existing Augmented Images feature in ARCore

    What you think is a QR code, the AR software sees as a fiducial marker. These markers need to known beforehand. For example in the video on the ARCore page, the painting is a fiducial marker which allows the 3D image to be overlaid.

    The ARCore feature I linked to supports up to 1000 reference images/markers per marker database and you can create and use new predefined marker databases.

    As long as you know what QR codes will have 3D effects, you can prepare them in a marker database.

    If you want/need to have dynamic QR code with ARCore, I would suggest trying to create fiducial around/next to the QR code so that you can scan and then hand off to AR Core to generate the 3d image, but may not work as QR code may be mixed in with the fiducial both need white space to work.

    If you can't use ARCore, then you are in the world of OpenCV and various scene engines (3D renderers) like Ogre or you can draw the AR scene in OpenGL ES.