## 3 Proposed System
### Software Module
#### 3.1.3 Multithread Processing Framework for Acceleration  
Previous fiducial marker application studies have mostly relied on single-thread frameworks. However, this approach can be detrimental to algorithm detection speed and fail to maximize the processing unit's computational resources in cost-sensitive embedded systems. To address this issue, we propose a multithread framework for DAH pattern detection, as shown in Figure 3. We implement a thread pool for parallel processing of different frames and an image state hash table to manage each frame's current status. Each frame can have one of three statuses: processing (state 0), finished processing with a valid pose (state 1), or finished processing with an invalid pose (state -1).  
Figure 3: The multithread DAH pattern detection processing framework.  
```
Input:ArtUco region set (arucoRegionSet) and Data Matrix region set (dmRegionSet) Output:DAH pattern region set
1 Initialize a set tempDAHPatternSet to store currDAHPattern in each traversal; foreach\(dm\in dmRegionSet\)do
2 ifdm.isprocessed()then
3 continue;
4 end if
5 currDAHPattern.store(dm); currDAHPattern.content \(\leftarrow\) dm.content; id1, id2 \(\leftarrow\) dm.content.ids; ifdm.friend.exist()then
6 currDAHPattern.store(dm.friend()); dm.friend().isprocessed() \(\leftarrow\) true;
7 end if
8 dm.isprocessed() \(\leftarrow\) true; foreach\(m\in\)arucoRegionSetdo
9 if(m.isprocessed()) or(m.id is neither id1 nor id2)then
10 continue;
11 else
12 ifdistance(m, dm) is satisfiedthen
13 currDAHPattern.store(m); m.isprocessed() \(\leftarrow\) true;
14 end if
15
16 end if
17 end if
18
19 end if
20 ifcurrDAHPattern.innerCodeNums() \(\geq\) 2 then
21 tempDAHPatternSet.store(currDAHPattern);
22 end if
23
24 end if
25 foreach\(tDAH\in\)tempDAHPatternSetdo
26 iftDAH.invalid()then
27 tempDAHPatternSet.remove(tDAH);
28 end if
29
30 end if
31 end if
32 return tempDAHPatternSet;
```  
**Algorithm 1**Integrate region to DAH pattern.  
When a new frame is input from the camera, a task is submitted to the thread pool. The detection process, as described in Section 3.1.2, is executed for the first time. Once the detection process is complete, the current task obtains a set of DAH pattern regions. Using the coordinates of the DAH pattern region corners in the world and pixel coordinate systems, a PnP problem solver calculates the camera pose. We use an infinitesimal plane-based pose estimation (IPPE) [34] solver for this purpose, and the IPPE result is saved temporarily.  
To ensure that the output queue order is the same as the input queue, the current task in the thread pool must wait until the last task in the thread pool exits. The image state hash table allows for this waiting mechanism. Each time the current thread is awakened by another thread notification, the current state of the last frame is queried, and the hibernation is stopped if the status is not zero.  
To overcome the ambiguous fiducial marker problem, we use the last frame pose to constrain the current frame pose, which is inspired by ArUco. If the last frame pose is valid, the task discards the IPPE pose result calculated before, and the last stamp pose is refined using the Levenberg-Marquarelt (LM) algorithm as the initial value. If the last frame pose is invalid, the IPPE pose result is used for the refined process as the initial value. The optimization objective in the LM algorithm is to minimize the reprojection error of all four corner points of the DAH pattern in the current frame whether the source of the initial value is the IPPE result or the last frame.  
When the current thread exits, regardless of the exit phase, it must update the current stamp state on the image state hash table. If the current thread exits after notification, which means the last stamp is useless in the hash table, it must also erase the last stamp date from the hash table. Our proposed multithread framework can accelerate the DAH pattern detection process and effectively utilize computational resources in an embedded system.