看最近物體識別互動桌比較火
本人就自己開發了一套物體識別底層開發包,以Unity插件的形式調用
CSDN好像放不了視頻
先看效果! 案例視頻均爲基於此開發包開發的程序,案列視頻鏈接:
https://objrecong.oss-cn-shanghai.aliyuncs.com/206.MP4
https://objrecong.oss-cn-shanghai.aliyuncs.com/394.MP4
https://objrecong.oss-cn-shanghai.aliyuncs.com/880.MP4
https://objrecong.oss-cn-shanghai.aliyuncs.com/881.MP4
https://objrecong.oss-cn-shanghai.aliyuncs.com/882.MP4
一、示例場景快速實踐:
- 新建一個場景,將Assets\TouchScript\Prefabs\下的Cursor和TouchManager預設體拖到場景中
- 新建一個Canvas,在Canvas下新建一個空物體取名ModelPanel(命名隨意),將需要識別的對象放在ModelPanel子目錄下(最多5個),例如創建5個不同顏色的Image,取名Model00,Model01, ... ,Model04
在Canvas下新建一個Text取名ScanText,默認隱藏
如下圖所示:
3. 選中Canvas,爲Canvas添加組件Config和ObjectRecog
AddComponent-->搜索”Config”
AddComponent-->搜索”ObjectRecog”
ObjectRecog中的Cursor爲步驟3.1中的Cursor預設體
ModelPanel爲步驟3.2中場景中的空物體ModelPanel
Config中的SacnText爲步驟3.2中新建的Text
如下圖所示:
至此,最簡單的場景已經搭建完成,配合硬件運行即可
二、腳本里獲取模塊位置與角度信息:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Manager : MonoBehaviour
{
ObjectRecog objrecog = new ObjectRecog();
// Start is called before the first frame update
void Start()
{
objrecog = transform.GetComponent<ObjectRecog>();
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < objrecog.modelsInfoList.Count; i++)
{
int modelId = objrecog.modelsInfoList[i].modelId;
Debug.Log("模塊編號爲:"+ modelId + "\n");
Debug.Log("模塊"+ modelId + "已激活? " + objrecog.modelsInfoList[i].isActive + "\n");
Debug.Log("模塊" + modelId + "的 AnchorPositon 爲:" + objrecog.modelsInfoList[i].modelPos + "\n");
Debug.Log("模塊" + modelId + "的 eularAngle的Z軸爲:" + objrecog.modelsInfoList[i].modelAngleZ + "\n");
Debug.Log("-----------------------------------\n");
}
}
}
其中
objrecog.modelsInfoList爲一個Struct結構體
每個struct包含:
一個int型的modelId,即爲識別到的模塊的編
一個bool型的isActive,即爲判斷編號爲modelId的模塊有沒有被檢測到
true就是檢測到了,false就是未檢測到
一個vector2類型的modelPos,記錄當前模塊的位置,實時刷新,此位置爲RectTransform 下的anchorPositon,不是tranform的position和localPosition 例如:transform.GetComponent<RectTransform>().anchorPositon=modelPos
一個float型的modelAngleZ,即爲eularAngle的z值
qq:1102841793