当运行起项目之后,进去选择页面,会看到一个列表选项,随便点一个进去。
会发现报错提示:
这是初始化失败,但是具体原因,打开log查看相关信息:
AR: No Vuforia license key defined!
SampleAppSession: InitVuforiaTask.onPostExecute: Failed to initialize Vuforia. Exiting.
ImageTargets: Failed to initialize Vuforia.
原因是没有许可密钥,导致初始化失败。
image.png
下面的大致意思是这样的:
注册码
开发
价格:免费
Reco使用量: 每月 1,000
云目标: 1,000
VuMark模板: 1活跃
VuMarks: 100
然后点开你申请的许可密钥 应用名称:
然后吧 license key 加入你的项目,这里我是说明android 其他的ios 或者unity 请看官方文档。
https://library.vuforia.com/content/vuforia-library/en/articles/Solution/How-To-add-a-License-Key-to-your-Vuforia-App.html
Adding a License Key to a native Android app
Use the setInitParameters() method:
Vuforia.setInitParameters(mActivity, mVuforiaFlags, " your_license_key ");
Example:
In com.vuforia.samples.SampleApplication
File SampleApplicationSession.java
Line 336
然后我们看demo 目录com.vuforia.samples.SampleApplication
SampleApplicationSession.java文件第 336行,(但是我发现其实在401行左右这块。哈哈哈)
// An async task to configure and initialize Vuforia asynchronously.
private static class InitVuforiaTask extends AsyncTask<Void, Integer, Boolean>
{
// Initialize with invalid value:
private int mProgressValue = -1;
private final WeakReference<SampleApplicationSession> appSessionRef;
InitVuforiaTask(SampleApplicationSession session)
{
appSessionRef = new WeakReference<>(session);
}
protected Boolean doInBackground(Void... params)
{
SampleApplicationSession session = appSessionRef.get();
// Prevent the onDestroy() method to overlap with initialization:
synchronized (session.mLifecycleLock)
{
// Configure Vuforia
// 注意:许可密钥进入第三个参数
Vuforia.setInitParameters(session.mActivityRef.get(), session.mVuforiaFlags, "");
do
{
// Vuforia.init() blocks until an initialization step is
// complete, then it proceeds to the next step and reports
// progress in percents (0 ... 100%).
// If Vuforia.init() returns -1, it indicates an error.
// Initialization is done when progress has reached 100%.
mProgressValue = Vuforia.init();
...
添加许可密钥之后,重新编译项目,开始使用吧。
选择列表 Model Targets 会看到相应的水印加模型图:
然后对着下面的图片扫吧,效果自己看吧。这样才有意思,不是吗?
网友评论