# Real-Time Motion Adaptation with Spatial Perception for an Augmented Reality Character
## 4 Implementation  
Algorithm 1 shows the overall implementation algorithm. First, we performed object recognition to express the AR character's movements and apply them to real-world situations using context information. Note that object detection attempts to identify the location of a recognized object from an image and video [28]. Figure 4 shows examples of our results using puddle objects detected in real-life images. Here, among the many real-world objects, we selected the puddle as the most suitable object for the adaptive motion control of the AR character, and in this study, we used 1000 labeled puddle datasets for learning to establish object detection related to predictions to identify the specific object in the image. When a client running our AR content sends a request for object recognition, the server processes it based on the learned results of YOLOv5 [29]. YOLOv5 is a model for detecting objects in the You Only Look Once family of computer vision technologies, commonly processed with images or video datasets generated in the real world. The AR environment requires real-time object detection, and the recognition accuracy is high [30]. Object recognition methods must also be able to simultaneously detect various objects that may affect the character [31]. Due to these recognition constraints in AR content, we selected YOLOv5 from among the related object recognition methods [32]. As a result of object recognition, the area of the recognized results was indicated by a red square (or bounding box), and the location of the detected object was received from the server. Then, we configured the object recognition dataset using the X and Y position in the top left, the X and Y position (or X/Y coordinate) in the bottom right, and the confidence level for the object in the given image. ```
Input: Original motions and configurations of the AR character's surrounding environment Output: Adapted motions Function Adapted_motion(Detected object, Original motion) // Estimate newly updated motion to apply detected objects if motion_transition_value > detection_threshold // Calculate 3D position/rotation/scale factors to be superimposed 3D transformation \(\leftarrow\) depth maps from multi-view 2D images for each motion(m) in all motions(M) // match the character behavior using fuzzy inference  updated_character_motion \(\leftarrow\) original_motion + detected object End for End if Return Adapted motion for animation controller, 3D transformation data
```  
**Algorithm 1** Motion adaption algorithm of the AR character determined by spatial properties in the real-world configurations  
Second, we estimated the 3D position from 2D images (or moving pictures) to calculate the location where the AR character would be registered and superimposed. We adopted [PERSON] et al. 's method of monocular depth estimation [33]. In this study, we predicted the 3D shape of the object related to transformation from the viewpoint of several input images [33] and used the view-synthesis approach to estimate the appearance of the target image from the viewpoint of another image to construct depth maps [33]. Using the reconstructed depth map (or spatial map) captured from the actual environment and the object recognition result, we estimated the relative locations related to spatial perception such as the position and orientation of the camera included in a user's mobile computing device with six degrees of freedom (DOFs). In short, we estimated the depth in the given space using relative poses with multi-view methods and calculated the 3D spatial location of the camera. Additionally, we used the interpolation method to correct 3D positioning errors. Then, the virtual object, namely the AR character, was registered by applying transformations (e.g., position, rotation, and scale) based on the predicted camera position,which is the process of synthesizing a virtual object accurately at a specific location in the real environment.