If the company wants to study the AR technology in advance, it will try to study the arttoolkit. The Internet is full of examples about compiling arttoolkit 5. Arttoolkit 5 has not been updated for a long time, and arttoolkit x is the latest version, but it has not found a way to compile arttoolkit x, so it will try to compile by itself
First, environment: Windows 10, Android studio 3.5.3, arttoolkit x 1.0.6, ndkr20b
Download first artoolkitx
Create a new project by yourself
Create a new module in the new project
Choose Android Library
Arxj for module name, org.arttoolkit x.arx.arxj for package name
In the dependencies {} of build.gradle of app
implementation project(path: ':arxj')
Enter the Source folder of the downloaded arttoolkit x Source code, copy all folders and files except the arxj folder to the cpp folder of the arxj you just created, without creating one yourself
Modify arxj's build.gradle and add the associated CMakeLists.txt code in android {}
externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" } }
Add code in defaultConfig {}
externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared", "-DANDROID_CPP_FEATURES=rtti exceptions" cppFlags"-std=c++11" } }
Run 'app', wait for a long time and report an error
Build command failed. Error while executing process x:\xxx\xxx\cmake\3.6.4111459\bin\cmake.exe with arguments {--build x:\xxxx\xxxx\AndroidArtoolkitx\arxj\.cxx\cmake\debug\arm64-v8a --target ARX}
Pull down to see the error code
Click in, it turns out that the arRefineCorners function cannot be found
Click arefinecorners. H to find that if have? Opencv is hidden
If have ා opencv is used to determine whether opencv is currently used. If not, it will be hidden. However, opencv is not used in ardetectmarket. C, and opencv is also found in arRefineCorners.cpp
There are two ways to judge opencv in arRefineCorners.h. One is to delete the error code directly. The other is not to judge opencv in arRefineCorners.h. I chose the latter one and commented out "if have" OpenCV
//#if HAVE_OPENCV #ifdef __cplusplus extern "C" { #endif // Given corner locations 'vertex' in observed coordinates, refine location. // buff is a luma-only buffer of dimensions width x height. void arRefineCorners(float vertex[4][2], const unsigned char *buff, int width, int height); #ifdef __cplusplus } #endif //#endif // HAVE_OPENCV
Run 'app' again and continue to report errors
x:\xxx\xxx\AndroidArtoolkitx\arxj\src\main\cpp\ARX\ARUtil/nftw.c:123: error: undefined reference to 'fts_close'
Click to open the error file. The original error file is for the code of the system with the lower SDK version. Maybe my ndk version is too high. If you don't want to try one version at a time, just comment it out and set the minimum SDK version to 21
Run 'app' again, run successfully, and then compile successfully. Then copy the java code of arxj in demo to your own arxj
Then copy the files or folders in the res folder to the res of your arxj
After that, I run demo. In the source code Examples folder, I found that 2d tracking example can't run. Because this demo is useful to opencv, I didn't use opencv, so I used Square tracking example for testing
Copy the assets folder, java code and layout layout of Square tracking example to the corresponding location of your project, and copy the cparam? Cache folder under Source/etc/android to the assets folder
Finally, modify Android manifest.xml
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-feature android:name="android.hardware.camera.any" /> <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-feature android:name="android.hardware.camera2" android:required="true"/> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> <application android:name="org.artoolkitx.arx.arsquaretracking.ARSquareTrackingApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="org.artoolkitx.arx.arsquaretracking.ARSquareTrackingActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="org.artoolkitx.arx.arxj.camera.CameraPreferencesActivity"/> </application>
The test pictures are all in pdf under the document / square marker pattern images folder
The startup is very slow. The default screen is horizontal. The code needs to be studied. It should be optimized