當(dāng)運(yùn)行起項(xiàng)目之后,進(jìn)去選擇頁(yè)面,會(huì)看到一個(gè)列表選項(xiàng),隨便點(diǎn)一個(gè)進(jìn)去。

會(huì)發(fā)現(xiàn)報(bào)錯(cuò)提示:

這是初始化失敗,但是具體原因,打開(kāi)log查看相關(guān)信息:
AR: No Vuforia license key defined!
SampleAppSession: InitVuforiaTask.onPostExecute: Failed to initialize Vuforia. Exiting.
ImageTargets: Failed to initialize Vuforia.
原因是沒(méi)有許可密鑰,導(dǎo)致初始化失敗。


下面的大致意思是這樣的:
注冊(cè)碼
開(kāi)發(fā)
價(jià)格:免費(fèi)
Reco使用量: 每月 1,000
云目標(biāo): 1,000
VuMark模板: 1活躍
VuMarks: 100
然后點(diǎn)開(kāi)你申請(qǐng)的許可密鑰 應(yīng)用名稱(chēng):


然后吧 license key 加入你的項(xiàng)目,這里我是說(shuō)明android 其他的ios 或者unity 請(qǐng)看官方文檔。
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行,(但是我發(fā)現(xiàn)其實(shí)在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
// 注意:許可密鑰進(jìn)入第三個(gè)參數(shù)
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();
...
添加許可密鑰之后,重新編譯項(xiàng)目,開(kāi)始使用吧。
選擇列表 Model Targets 會(huì)看到相應(yīng)的水印加模型圖:

然后對(duì)著下面的圖片掃吧,效果自己看吧。這樣才有意思,不是嗎?
