Qualcomm AR的Unity3D代码中,在QCARManagerImpl类获得图像,并进行识别、跟踪物体,得到目标物体的姿态(位置和旋转量)。所有的更新操作,在QCARManagerImpl.Update()中实现。
主要使用到的相关的数据结构
ImageHeaderData图像头结构体
public struct ImageHeaderData
{
public int width;
public int height;
public int stride;
public int bufferWidth;
public int bufferHeight;
public int format;
public int reallocate;
public int updated;
public IntPtr data;
}
FrameState结构体包含了识别跟踪到的数据
private struct FrameState
{
public int numTrackableResults;
public int numVirtualButtonResults;
public int frameIndex;
public IntPtr trackableDataArray;
public IntPtr vbDataArray;
public int numWordResults;
public IntPtr wordResultArray;
public int numNewWords;
public IntPtr newWordDataArray;
public IntPtr videoModeData;
}
numTrackableResults:找到的跟踪目标个数
numVirtualButtonResults:虚拟按键的个数
frameIndex:帧的索引号
trackableDataArray:跟踪结果数据(指向TrackableResultData结构体)
vbDataArray:虚拟按键跟踪结果
numWordResults:识别文字个数
wordResultArray:识别跟踪的文字结果数据
TrackableResultData结构体包含了图像识别跟踪的数据
public struct TrackableResultData
{
public PoseData pose;
public TrackableBehaviour.Status status;
public int id;
}
pose:pose数据
status:跟踪状态,为如下枚举中的一个值
public enum Status
{
NOT_FOUND = -1,
UNKNOWN = 0, ///< The state of the TrackableResult is unknown
UNDEFINED = 1,///< The state of the TrackableResult is not defined
DETECTED = 2,///< The TrackableResult was detected
TRACKED = 3 ///< The TrackableResult was tracked
}
id:目标的id号
PoseData结构体包含了姿态
public struct PoseData
{
public Vector3 position;
public Quaternion orientation;
}
position:位置
orientation:旋转量