Client与高通云端间的传输协议为HTTPS
以下是官网对与云端交互的API介绍,以往云端添加一张图片为例
协议字段介绍:
*NOTE: The Target POST body can contain either the image_url or the image – but not both.
** NOTE:The Target POST body can contain either the application_metadata_url or application_metadata – but not both.
Authorization与key有关,构成:"Authorization", "VWS " + accessKey + ":" + sb.tmsSignature(request, secretKey);
application_metadata即通过高通网站上传图片时同时上传的TXT文件的内容。
VWS 是Vuforia Web Services 缩写
Client发送请求
POST /targets HTTP/1.1
Host: vws.vuforia.com
Date: Mon, 23 Apr 2012 12:45:19 GMT
Authorization: VWS df8d23140eb443505c0661c5b58294ef472baf64:jHX6oLeqTXpynyqcvVC2MSHarhU
Content-Type: application/json
{
“name”:”tarmac”,
“width:32.0,
“image”:”0912ba39x….”,
“application_metadata”:“496fbb6532b3863460a984de1d980bed5ebcd507”
}
云端回答的报文
Example:
HTTP/1.1 201 Created
Content-Type: application/json
{
“result_code”:”Success”,
“transaction_id”:”550e8400e29b41d4a716446655440452”,
“target_id”: ”550e8400e29b41d41626446655440000”
}
Target_id 是对一个Target即图片的唯一ID
transaction_id是传输报文的ID;
Client识别图片大概流程
1、初始化targetfinder
在CloudReco.cpp 172行(targetFinder->startInit(kAccessKey, kSecretKey)) 利用key初始化和云端的连接
2 、Scanning mode 与. content mode
当应用程序是在扫描模式时,此时Client在获取当前扫描到的图片并与云端匹配;这状态是在Client端有动态扫描。 当应用程序在内容模式下,Client不再与云端匹配扫描到的图片,Client不显示动态的扫描,而在界面上显示增强信息。这两种模式是相互排斥的。
具体实现接口
在CloudReco.java启动 Scanning mode
private void enterScanningMode()
{
// Hides the 2D Overlay
hide2DOverlay();
// Enables CloudReco Scanning Mode in Native code
enterScanningModeNative();
}
调用了CloudReco.cpp中670行 的enterScanningModeNative();其中targetFinder->startRecognition()为开始扫描识别。
在CloudReco.cpp中19行CloudReco_UpdateCallback 中updateSearchResults
QCAR::TargetFinder* finder = imageTracker->getTargetFinder();
// Check if there are new results available:
const int statusCode = finder->updateSearchResults();
// Show a message if we encountered an error:
if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
{
// Process new search results
if (finder->getResultCount() > 0)
{
const QCAR::TargetSearchResult* result = finder->getResult(0);
updateSearchResults()向云端发送扫描到的结果;getResult(0);获取向云端发送扫描到结果后云端返回的信息。
(官网对这个API介绍很少,这是猜测的功能。官网介绍见https://developer.vuforia.com/resources/api/class_q_c_a_r_1_1_target_finder
在上面代码中,调用了CloudReco.cpp中的 enterContentMode() (官网这样介绍的,具体不知道是哪个语句调用的),CloudReco.cpp中的 enterContentMode() 实际就是调用java中的 enterContentMode() 方法,并对界面操作,然后调用enterContentModeNative();
enterContentModeNative()完成的操作有1Retrieving the QCAR::TargetFinder 2Stopping the CloudReco service (targetFinder->stop()); 3Setting the scanningMode to false,进入content mode
CloudReco.java中的startWebView中获取json信息并显示
更多介绍
https://developer.vuforia.com/resources/dev-guide/getting-started