当前位置:网站首页>Arfoundation starts from scratch 5-ar image tracking
Arfoundation starts from scratch 5-ar image tracking
2022-07-29 08:29:00 【suelee_ hm】
Take something in the real world 、 A medium as a reference , take AR The content is fixed to the relative position of the reference , The relative position changes with the movement of the reference , That is to say AR track .
2D Image tracking (ARKit and ARCore), By detecting specific 2D Images ,Tracked Image Manager You can automatically create a GameObject, It allows you to change according to specific images AR Experience .
The sample source code of this project :
https://github.com/sueleeyu/ar-augment
One 、 Create project project
1. New projects

2. Rename it to ImagesScene, choice Window-Package Manager- Unity Register, Download... In turn :
XR Plugin Management 4.0.7
AR Foundation 4.1.10
ARCore XR Plugin 4.1.10
ARKit XR Plugin 4.1.10

3. as follows :

Two 、 add to AR Components
1. Delete the original camera , Click on “+”, add to Session Origin,AR Session:

2. choice AR Session Origin,Inspector Click Add component , Search box input art, choice AR Tracked Image Manager add to .

3、 ... and 、 Add interface UI And models
1.log Text, Used to display log information :Hierarchy-‘+’- UI –Text, newly build Text Components , name Log, Set up :

2. add to Button,Hierarchy-Canvas Right click ,UI-Button, Set up :

Button-Text Set up :

Four 、 Create reference Gallery
1.Project –Assets Right click ,Create-Folder, New folder , name Images:

2. Create reference Gallery ,Project –Assets –Images Right click ,Create-XR-Reference Image Library:

3. Copy multiple pictures to Images Under the table of contents :

4. Add reference figure , choice ReferenceImageLibrary, Click the right side. Inspector Of Add Image

5. Drag the picture to the right map , Complete the addition of reference figures in turn :

Add the following :

Refer to the meaning of attributes in the figure :
Name: Each reference diagram has a unique guid And a name,Name It can be used to match the detected image and reference image in real time
Specify Size: Specify the size of the picture , Some platforms need to be specified to recognize , All best to choose .
Keep Texture at Runtime: Whether to use texture , If you want to modify Prefab Appearance can be selected .
6. AR Tracked Image Manager add to Reference Library attribute : choice Hierarchy-AR Session Origin, Select right Inspector Of AR Tracked Image Manager Term Serialized Library Right dot , Click the corresponding item in the list to add :

5、 ... and 、 Pictures and prefabricated parts needed
1.Hierarchy Under the new Cube, name One( Corresponding to the pictures in the reference library Name), Drag the Images Next One.png To... In the scene Cube:

2.Assets Under the new Resources/Prefabs Folder , Put the cube One Drag to Prefabs Next , Delete... In the scene One, Others are made in turn .

6、 ... and 、 Write a script
1. Project-Assets Right click , newly build Scripts Folder , newly build Logger.cs, For viewing log journal

2.Logger mount

Make connections :

3. newly build MultiImageTracking.cs, Write code .
Load the preform , stay Strat in :
voidStart()
{
// Load the preform
GameObject one = Resources.Load<GameObject>("Prefabs/One");
prefabs.Add("One", one);
GameObject two= Resources.Load<GameObject>("Prefabs/Two");
prefabs.Add("Two", two);
GameObject qrcode = Resources.Load<GameObject>("Prefabs/QRCode");
prefabs.Add("QRCode", qrcode);
Logger.Log("MultiImageTracking-Start");
}
4. register ARTrackedImagesChangedEventArgs event :
privatevoidOnEnable()
{
ImgTrackedManager.trackedImagesChanged += OnTrackedImagesChanged;
}
OnTrackedImagesChanged To load :
void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
foreach (var trackedImage in eventArgs.added)
{
// Give the initial image a reasonable default scale
var minLocalScalar = Mathf.Min(trackedImage.size.x, trackedImage.size.y) / 2;
trackedImage.transform.localScale = new Vector3(minLocalScalar, minLocalScalar, minLocalScalar);// Scale the model
Instantiate(prefabs[trackedImage.referenceImage.name], trackedImage.transform);// Instantiate the prefabricated part
//OnImagesChanged(trackedImage);
}
}
5. mount MultiImageTracking.cs To AR Session Origin, choice AR Session Origin,Inspector Click on the Add Component, Enter and select MultiImageTracking.cs, take Button-Text Drag components to MultiImageTracking Of Toggle Text Property bar :

7、 ... and 、android pack
1. function :

8、 ... and 、 common problem
1.ARFoundration Packing will report an error :“Failded to generated ARCore reference image library”
The reason for the error should be that the image quality does not meet the requirements .

Nine 、 reference
1. Unity api:
Unity - Manual: Unity User Manual 2021.3 (LTS)
2.ARFoundation Example :
3.ARCore file
Add dimensions to the image | ARCore | Google Developers
4. The sample source code of this project :
边栏推荐
- Inclination monitoring solution of Internet of things
- Day5: PHP simple syntax and usage
- Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
- 6.2 function-parameters
- Product promotion channels and strategies, cosmetics brand promotion methods and steps
- Virtual augmentation and reality Part 2 (I'm a Firebird)
- 【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
- 125kHz wake-up function 2.4GHz single transmitter chip-si24r2h
- 搜索与回溯经典题型(八皇后)
- Deep learning (1): prediction of bank customer loss
猜你喜欢

Day4: SQL server is easy to use

Inclination sensor is used for long-term monitoring of communication tower and high-voltage tower

Hal learning notes - Advanced timer of 7 timer

Importerror: no module named XX

Random lottery turntable wechat applet project source code

Hal library learning notes - 8 concept of serial communication

Cs4344 domestic substitute for dp4344 192K dual channel 24 bit DA converter

110 MySQL interview questions and answers (continuously updated)

Deep learning (1): prediction of bank customer loss

集群使用规范
随机推荐
MySQL中的时间函数
commonjs导入导出与ES6 Modules导入导出简单介绍及使用
AES 双向加密解密工具
Detailed steps of installing MySQL 5.7 for windows
Security baseline of network security
NFC two-way communication 13.56MHz contactless reader chip -- si512 replaces pn512
Segment paging and segment page combination
Application of explosion-proof inclination sensor in safe operation of LNG
Windows 安装 MySQL 5.7详细步骤
Basic shell operations (Part 2)
Cs5340 domestic alternative dp5340 multi bit audio a/d converter
用户身份标识与账号体系实践
[[first blog]p controller implementation instructions in UDA course]
Tensorboard use
6.2 function-parameters
Lora opens a new era of Internet of things -asr6500s, asr6501/6502, asr6505, asr6601
Four pin OLED display based on stm32
centos7/8命令行安装Oracle11g
数仓分层设计及数据同步问题,,220728,,,,
Data warehouse layered design and data synchronization,, 220728,,,,