jsmith613 / Aruco-Marker-Tracking-Android

Aruco marker tracking for android devices
GNU General Public License v3.0
30 stars 14 forks source link

"A calibration is required prior to running the activity" mean? #3

Open janardhan1212 opened 7 years ago

janardhan1212 commented 7 years ago

Hi, thanks for sharing this project. how to run this calibration?

jsmith613 commented 7 years ago

There is an activity Here. Just run the activity once on your device and you'll be set to go.

janardhan1212 commented 7 years ago

I didn't find XML files for this activity and why should i run this activity?

AdamMc331 commented 7 years ago

I can't find these XML files either. Any luck @janardhan1212 @jsmith613 ?

jsmith613 commented 7 years ago

Sorry, been busy with schoolwork recently. So basically, lots of openCV and aruco methods require camera parameters as an input. To get those camera parameters, you need to run a calibration activity. You only need to run this once for a device and the parameters can be saved on your device. I believe I posted the wrong calibration activity on here. I'll take a look and see if I can get it working.

oradomskyi commented 7 years ago

Hi all =) Rough and extremely fast solution - instead of loading camera parameters from file, create CameraParameters with some generic hardcoded data...

  1. Add below code to CameraParameters class / -------------- ADD TO CameraParameters -----------/ public void loadConstandCalibration() { cameraMatrix.put(0,0, 100000, 0.0, 960, 0.0, 100000, 540, 0.00000, 0.00000, 1.00000 );

    double[] distArray =  { 0.0,
                            0.0,
                            0.0,
                            0.0,
                            0.0
    };
    distorsionMatrix.fromArray(distArray);

    } / ----------------------------------------------------------/ Here is fx fy - focal length; fx=100000, fy=100000 cx cy - camera center in pixels(my camera 1920x1080) cx=960 cy=540 works pretty well on Note 4

  2. Force MarkerTracker to load hardcpded data instead of loading file a) find and comment this line: camParams.readFromFile(Environment.getExternalStorageDirectory().toString() + DATA_FILEPATH); ...it becomes: //camParams.readFromFile(Environment.getExternalStorageDirectory().toString() + DATA_FILEPATH);

b) next to connemted line add this code: camParams.loadConstandCalibration(); ...it becomes //camParams.readFromFile(Environment.getExternalStorageDirectory().toString() + DATA_FILEPATH); camParams.loadConstandCalibration();

  1. Trick detector. After some debugging i found that there is normal marker tracking but some fails when adding new markers... so let's go a) Find this section of code in MarkerDetector ... int id = marker.calculateMarkerId(); if(id != -1){ // rotate the points of the marker so they are always in the same order no matter the camera orientation Collections.rotate(marker.toList(), 4-marker.getRotations()); newMarkers.add(marker); } ...

b) Move line "newMarkers.add(marker);" outside the IF statement ... int id = marker.calculateMarkerId(); if(id != -1){ // rotate the points of the marker so they are always in the same order no matter the camera orientation Collections.rotate(marker.toList(), 4-marker.getRotations()); newMarkers.add(marker); // inside the IF statement } newMarkers.add(marker); // outside the IF statement ...

Now all the stuff should work... Enjoy =)

pietjanssen commented 6 years ago

Hey. I am trying to get this library to work on Android Studio 3.0. I am still having trouble with trying to run the camera calibration.

Can someone explain to me what I am supposed to do in order to run the camera calibration? Should I change anything in the AndroidManifest.xml in openCVTutorial1CameraPreview?

I tried the FrayaMiner's approach, and it works, but it makes the camera look distorted in color.