当前位置:网站首页>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 :
边栏推荐
- Basic crawler actual combat case: obtaining game product data
- Background management system platform of new energy charging pile
- Search and recall classic questions (eight queens)
- Week 1 task deep learning and pytorch Foundation
- Tensorboard use
- TCP - sliding window
- Usage of torch.tensor.to
- Charging pile charging technology new energy charging pile development
- Use SQL client How can the job generated by SH achieve breakpoint continuation after cancle?
- Low power Bluetooth 5.0 chip nrf52832-qfaa
猜你喜欢

New energy shared charging pile management and operation platform

PostgreSQL手动创建HikariDataSource解决报错Cannot commit when autoCommit is enabled

Chrony 时间同步

Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on

Cv520 domestic replacement of ci521 13.56MHz contactless reader chip

用户身份标识与账号体系实践

A problem encountered in SQL interview

Cs5340 domestic alternative dp5340 multi bit audio a/d converter

Lesson 3 threejs panoramic preview room case

Node: file write data (readfile, WriteFile), two modes: overwrite and increment
随机推荐
DC motor control system based on DAC0832
Day15: the file contains the vulnerability range manual (self use file include range)
Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on
PostgreSQL手动创建HikariDataSource解决报错Cannot commit when autoCommit is enabled
Low power Bluetooth 5.0 chip nrf52832-qfaa
01-01-osg GL3 environment setup
HC-SR04超声波测距模块使用方法和例程(STM32)
Multifunctional signal generator based on AD9850
Inclination sensor accuracy calibration test
Tensorboard use
Hal learning notes - Advanced timer of 7 timer
Txt plain text operation
深度学习(1):银行客户流失预测
Detailed steps of installing MySQL 5.7 for windows
6.2 function-parameters
C language calculates the length of string
Alibaba political commissar system - Chapter III, Alibaba political commissar and cultural docking
[opencv] - Operator (Sobel, canny, Laplacian) learning
Simulation of four way responder based on 51 single chip microcomputer
深度学习(2):图片文字识别