当前位置:网站首页>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 :
边栏推荐
- Day15 (day16 extension): file contains vulnerability
- NFC two-way communication 13.56MHz contactless reader chip -- si512 replaces pn512
- Personal study notes
- Day13: file upload vulnerability
- To create a thread pool for the rate, start the core thread
- Day6: using PHP to write landing pages
- Usage of torch.tensor.to
- OSG advanced sequence
- Clickhouse learning (III) table engine
- 集群使用规范
猜你喜欢

Chrony time synchronization

Virtual augmentation and reality Part 2 (I'm a Firebird)

Privacy is more secure in the era of digital RMB

DAC0832 waveform generator based on 51 single chip microcomputer

集群使用规范

Dp1332e multi protocol highly integrated contactless read-write chip

Day4: SQL server is easy to use

Inclination sensor accuracy calibration test

Flask reports an error runtimeerror: the session is unavailable because no secret key was set

What is the working principle of the noise sensor?
随机推荐
OSG advanced sequence
node:文件写入数据(readFile、writeFile),覆盖与增量两种模式
DC motor speed regulation system based on 51 single chip microcomputer (use of L298)
Application scheme of charging pile
User identity identification and account system practice
A problem encountered in SQL interview
Data warehouse layered design and data synchronization,, 220728,,,,
Inclination monitoring solution of Internet of things
Product promotion channels and strategies, cosmetics brand promotion methods and steps
Application of explosion-proof inclination sensor in safe operation of LNG
Intelligent shelf safety monitoring system
Temperature acquisition and control system based on WiFi
Basic shell operations (Part 1)
Proteus simulation based on msp430f2491 (realize water lamp)
Pnpm install appears: err_ PNPM_ PEER_ DEP_ ISSUES Unmet peer dependencies
Day13: file upload vulnerability
Osg3.6.5 failed to compile freetype
Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on
Inclination sensor accuracy calibration test