其他分享
首页 > 其他分享> > 手机相机识别实现ar测距(AR尺子)

手机相机识别实现ar测距(AR尺子)

作者:互联网

【实例简介】手机相机识别实现ar测距,至少三年以上开发经验才能跑通

【实例截图】

在这里插入图片描述
文件:590m.com/f/25127180-490561034-8afed0(访问密码:551685)

【核心代码】

using UnityEngine;
using UnityEngine.XR.ARFoundation;

/// AR尺子AR功能管理
public class ARRulerFoundtion: ARObjectSceneBase
{
/// 判断是否识别到平面
private bool m_IsPlaneChanged = false;

/// <summary>瞄准器模型</summary>
private GameObject m_TakeAim;
/// <summary>屏幕中心位置</summary>
private Vector2 m_ScreenCenter;


/// <summary>Awake</summary>
public override void OnAwake()
{
    base.OnAwake();

    m_ScreenCenter = new Vector2(Screen.width / 2, Screen.height / 2);
    m_TakeAim = Instantiate(Resources.Load("Prefabs/TakeAim") as GameObject, transform);
    m_TakeAim.name = "TakeAim";
    m_TakeAim.SetActive(false);
}

/// <summary>Update</summary>
public override void OnUpdate()
{
    base.OnUpdate();
    if (isSupportAR) Raycast(m_ScreenCenter, UpdateTakeAimPosition);
}

/// <summary>AR初始化完成</summary>
public override void OnInitARFinish()
{
    base.OnInitARFinish();
    Debug.Log(GetType() "/InitARFinish()/初始化AR完成!");

    ARRulerSceneManager.Instance.uIManager.FindPanelPanelSetActive(true);

    planeEffectManager.SetAllPlanesActive(false);
}

/// <summary>平面识别发送改变</summary>
public override void OnPlanesChanged(ARPlanesChangedEventArgs obj)
{
    base.OnPlanesChanged(obj);
    if (m_IsPlaneChanged) return;
    m_IsPlaneChanged = true;

    ARRulerSceneManager.Instance.uIManager.ButtonsPanelSetActive(true);
    ARRulerSceneManager.Instance.uIManager.FindPanelPanelSetActive(false);
}

/// <summary>更新瞄准器的位置信息</summary>
private void UpdateTakeAimPosition(bool hit, ARRaycastHit aRRaycastHit)
{
    m_TakeAim.SetActive(hit);

    ARRulerSceneManager.Instance.uIManager.AddButtonInteractable(hit);
    ARRulerSceneManager.Instance.uIManager.TakePhotosButtonInteractable(hit);

    if (hit)
    {
        m_TakeAim.transform.position = aRRaycastHit.pose.position;
        m_TakeAim.transform.rotation = aRRaycastHit.pose.rotation;

        Vector3 size = Vector3.one;
        float value = 1;
        if (aRRaycastHit.distance < 1) value = 3.3f;
        else if (aRRaycastHit.distance < 2) value = 4;
        else value = aRRaycastHit.distance * 2;
        m_TakeAim.transform.localScale = size * value;
    }
}

以下内容无关:

-------------------------------------------分割线---------------------------------------------

前面我们对IS25WP系列Flash的Dummy Cycle设置很了解了,那么IS25LP系列Flash是不是一样的设计呢?我们查看IS25LP064A数据手册来确认一下。

我们找到如下Read Dummy Cycle与最大工作频率的对应表,从表里可以看到当IS25LP工作在Fast Read Quad I/O模式时,默认的6个Dummy Cycle适用的最大工作频率是104MHz(这点上与IS25WP系列是一致的),不过与IS25WP系列不同的是IS25LP系列Dummy Cycle仅有四档(2bit设置,对应4/6/8/10四种值),而IS25WP系列Dummy Cycle有十五档(4bit设置,对应1-15取值),所以Dummy Cycle设计在IS25LP上其实是精简版。

二、如何更改Flash里的Dummy Cycle?
  意识到IS25LP与IS25WP在Dummy Cycle设计上的差异,改起来就容易了。我们继续看Flash数据手册,IS25LP064A内部有个8bit的Read Register,其bit4-bit3是Dummy Cycles设置(精简设计一),寄存器类型里标明仅易失性一种属性(精简设计二)。

在IS25LP064A的指令集表里,可以看到专门写Read Register的指令,即SRP指令,注意指令值就是唯一的0xC0(精简设计三)。

分析到这里,额外的小工程修改Dummy Cycle是不可能了,只能老老实实在i.MXRT每次启动时直接借助FDCB启动头里的设置用SRP指令更改Flash的Dummy Cycle,即如下所示:

// 设置Dummy Cycle数
#define FLASH_DUMMY_CYCLES 8
#define FLASH_DUMMY_VALUE 0x2
// 写Read Register时序在LUT中的index(可自定义位置,但不要占BootROM预设的几个时序位置)
#define CMD_LUT_SEQ_IDX_SET_READ_PARAM 7
// BootROM中预设的LUT命令时序的index
#define CMD_LUT_SEQ_IDX_READ 0
#define CMD_LUT_SEQ_IDX_READSTATUS 1
#define CMD_LUT_SEQ_IDX_WRITEENABLE 3

const flexspi_nor_config_t qspiflash_config = {
.memConfig =
{
.tag = FLEXSPI_CFG_BLK_TAG,
.version = FLEXSPI_CFG_BLK_VERSION,
.readSampleClkSrc = kFlexSPIReadSampleClk_LoopbackFromDqsPad,
.csHoldTime = 3u,
.csSetupTime = 3u,
// Enable Safe configuration
.controllerMiscOption = 0x10,
.deviceType = kFlexSpiDeviceType_SerialNOR,
.sflashPadType = kSerialFlash_4Pads,
.serialClkFreq = kFlexSpiSerialClk_133MHz,
.sflashA1Size = 8u * 1024u * 1024u,
// 使能Flash寄存器配置操作
.configCmdEnable = 1u,
.configModeType[0] = kDeviceConfigCmdType_Generic,
// 指示Flash寄存器配置时序在LUT中index
.configCmdSeqs[0] =
{
.seqNum = 1,
.seqId = CMD_LUT_SEQ_IDX_SET_READ_PARAM,
.reserved = 0,
},
// 设定Flash寄存器配置值(这里就是写入Read Register的值)
// Note1: 这里写入Read Register的值在IS25WP系列和IS25LP系列有区别
.configCmdArgs[0] = FLASH_DUMMY_VALUE << 3,
.lookupTable =
{
// Fast Read Quad I/O
[4CMD_LUT_SEQ_IDX_READ] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB, RADDR_SDR, FLEXSPI_4PAD, 0x18),
[4
CMD_LUT_SEQ_IDX_READ + 1] = FLEXSPI_LUT_SEQ(MODE8_SDR, FLEXSPI_4PAD, 0x00, DUMMY_SDR, FLEXSPI_4PAD, FLASH_DUMMY_CYCLES-2),
[4*CMD_LUT_SEQ_IDX_READ + 2] = FLEXSPI_LUT_SEQ(READ_SDR, FLEXSPI_4PAD, 0x04, STOP, FLEXSPI_1PAD, 0x00),

                // READ STATUS REGISTER
                [4*CMD_LUT_SEQ_IDX_READSTATUS]         = FLEXSPI_LUT_SEQ(CMD_SDR,   FLEXSPI_1PAD, 0x05, READ_SDR,  FLEXSPI_1PAD, 0x01),
                [4*CMD_LUT_SEQ_IDX_READSTATUS + 1]     = FLEXSPI_LUT_SEQ(STOP,      FLEXSPI_1PAD, 0x00, 0, 0, 0),
               
                // WRTIE ENABLE
                [4*CMD_LUT_SEQ_IDX_WRITEENABLE]        = FLEXSPI_LUT_SEQ(CMD_SDR,   FLEXSPI_1PAD, 0x06, STOP,      FLEXSPI_1PAD, 0x00),

                // Flash寄存器配置时序(这个时序需要上面READ STATUS, WRITE ENABLE的配合)
                // Note2: 这里写入的指令在IS25WP系列和IS25LP系列有区别
                [4*CMD_LUT_SEQ_IDX_SET_READ_PARAM]     = FLEXSPI_LUT_SEQ(CMD_SDR,   FLEXSPI_1PAD, 0xC0, WRITE_SDR, FLEXSPI_1PAD, 0x01),
                [4*CMD_LUT_SEQ_IDX_SET_READ_PARAM + 1] = FLEXSPI_LUT_SEQ(STOP,      FLEXSPI_1PAD, 0x00, 0, 0, 0),
            },
    },
.pageSize           = 256u,
.sectorSize         = 4u * 1024u,
.blockSize          = 64u * 1024u,
.isUniformBlockSize = false,

};

标签:Dummy,FLEXSPI,LUT,IDX,SEQ,CMD,ar,AR,尺子
来源: https://blog.csdn.net/gumenghua_com/article/details/115826184