Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
ArucoGenerateTags.hpp File Reference

This example uses the OpenCV TagGenerator.hpp example and multithreads the generation of all available Aruco tags for the given dictionary type. More...

#include "../../src/interfaces/AutonomyThread.hpp"
#include "../../src/util/ExampleChecker.h"
#include "../opencv/TagGenerator.hpp"
Include dependency graph for ArucoGenerateTags.hpp:

Go to the source code of this file.

Classes

class  ArucoGenerateTagsThreaded
 This class inherits the AutonomyThread interface and implements the threaded container methods. It also utilizes the ability to create a thread pool of subroutines and the ability to parallelize loops. More...
 
class  ArucoGenerateTagsLinear
 This class is non threaded. More...
 

Functions

void RunExample ()
 Main example method.
 

Detailed Description

This example uses the OpenCV TagGenerator.hpp example and multithreads the generation of all available Aruco tags for the given dictionary type.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-23

Function Documentation

◆ RunExample()

void RunExample ( )

Main example method.

Returns
int - Return status.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-23

Linear generator.

Threaded generator.

208{
212 // Start the timer
213 std::chrono::time_point tmStartTime = std::chrono::high_resolution_clock::now();
214
215 // Create generator.
216 ArucoGenerateTagsLinear LinearTagGenerator;
217
218 // Configure tag generator for first run.
223 LinearTagGenerator.SetNumTagsToGenerate(50);
224 // Start first run.
225 LinearTagGenerator.Start();
226
227 // Add new dictionary to generator.
232 LinearTagGenerator.SetNumTagsToGenerate(100);
233 // Start second run.
234 LinearTagGenerator.Start();
235
236 // Add new dictionary to generator.
241 LinearTagGenerator.SetNumTagsToGenerate(250);
242 // Start third run.
243 LinearTagGenerator.Start();
244
245 // Add new dictionary to generator.
250 LinearTagGenerator.SetNumTagsToGenerate(1000);
251 // Start fourth run.
252 LinearTagGenerator.Start();
253
254 // End the timer
255 std::chrono::time_point tmEndTime = std::chrono::high_resolution_clock::now();
256 // Calculate the elapsed time
257 int nSingledThreadedDuration = std::chrono::duration_cast<std::chrono::milliseconds>(tmEndTime - tmStartTime).count();
258 // Print the result
259 std::cout << "Time taken for single threaded generator: " << nSingledThreadedDuration << " milliseconds." << std::endl;
260
261 // Remove all png files in the current directory.
262 for (const std::filesystem::directory_entry& stdEntry : std::filesystem::directory_iterator("."))
263 {
264 // Loop all *.png files.
265 if (std::filesystem::is_regular_file(stdEntry) && stdEntry.path().extension() == ".png")
266 {
267 // Delete.
268 std::filesystem::remove(stdEntry.path());
269 }
270 }
271
275 // Start the timer
276 tmStartTime = std::chrono::high_resolution_clock::now();
277
278 // Create Aruco generator threads.
279 ArucoGenerateTagsThreaded ThreadedTagGenerator1;
280 ArucoGenerateTagsThreaded ThreadedTagGenerator2;
281 ArucoGenerateTagsThreaded ThreadedTagGenerator3;
282 ArucoGenerateTagsThreaded ThreadedTagGenerator4;
283
284 // Configure tag generator for first run.
285 ThreadedTagGenerator1.AddTagDictionaryType(cv::aruco::DICT_4X4_50);
286 ThreadedTagGenerator1.AddTagDictionaryType(cv::aruco::DICT_5X5_50);
287 ThreadedTagGenerator1.AddTagDictionaryType(cv::aruco::DICT_6X6_50);
288 ThreadedTagGenerator1.AddTagDictionaryType(cv::aruco::DICT_7X7_50);
289 ThreadedTagGenerator1.SetNumTagsToGenerate(50);
290 // Start first run.
291 ThreadedTagGenerator1.Start();
292
293 // Add new dictionary to generator.
294 ThreadedTagGenerator2.AddTagDictionaryType(cv::aruco::DICT_4X4_100);
295 ThreadedTagGenerator2.AddTagDictionaryType(cv::aruco::DICT_5X5_100);
296 ThreadedTagGenerator2.AddTagDictionaryType(cv::aruco::DICT_6X6_100);
297 ThreadedTagGenerator2.AddTagDictionaryType(cv::aruco::DICT_7X7_100);
298 ThreadedTagGenerator2.SetNumTagsToGenerate(100);
299 // Start second run.
300 ThreadedTagGenerator2.Start();
301
302 // Add new dictionary to generator.
303 ThreadedTagGenerator3.AddTagDictionaryType(cv::aruco::DICT_4X4_250);
304 ThreadedTagGenerator3.AddTagDictionaryType(cv::aruco::DICT_5X5_250);
305 ThreadedTagGenerator3.AddTagDictionaryType(cv::aruco::DICT_6X6_250);
306 ThreadedTagGenerator3.AddTagDictionaryType(cv::aruco::DICT_7X7_250);
307 ThreadedTagGenerator3.SetNumTagsToGenerate(250);
308 // Start third run.
309 ThreadedTagGenerator3.Start();
310
311 // Add new dictionary to generator.
312 ThreadedTagGenerator4.AddTagDictionaryType(cv::aruco::DICT_4X4_1000);
313 ThreadedTagGenerator4.AddTagDictionaryType(cv::aruco::DICT_5X5_1000);
314 ThreadedTagGenerator4.AddTagDictionaryType(cv::aruco::DICT_6X6_1000);
315 ThreadedTagGenerator4.AddTagDictionaryType(cv::aruco::DICT_7X7_1000);
316 ThreadedTagGenerator4.SetNumTagsToGenerate(1000);
317 // Start fourth run.
318 ThreadedTagGenerator4.Start();
319
320 // Join all.
321 ThreadedTagGenerator1.Join();
322 ThreadedTagGenerator2.Join();
323 ThreadedTagGenerator3.Join();
324 ThreadedTagGenerator4.Join();
325
326 // End the timer
327 tmEndTime = std::chrono::high_resolution_clock::now();
328 // Calculate the elapsed time
329 int nMultiThreadedDuration = std::chrono::duration_cast<std::chrono::milliseconds>(tmEndTime - tmStartTime).count();
330 // Print the result
331 std::cout << "Time taken for multithreaded generator: " << nMultiThreadedDuration << " milliseconds." << std::endl;
332 std::cout << "\n\nCheck your build directory for all aruco tags!" << std::endl;
333}
This class is non threaded.
Definition ArucoGenerateTags.hpp:146
void Start()
Single threaded, runs in main loop.
Definition ArucoGenerateTags.hpp:163
void AddTagDictionaryType(const cv::aruco::PredefinedDictionaryType eDictionary)
Mutator for the Tag Dictionary Type private member.
Definition ArucoGenerateTags.hpp:196
void SetNumTagsToGenerate(const int nNumTags)
Mutator for the Num Tags To Generate private member. Given number must not exceed the dictionary type...
Definition ArucoGenerateTags.hpp:186
This class inherits the AutonomyThread interface and implements the threaded container methods....
Definition ArucoGenerateTags.hpp:33
void AddTagDictionaryType(const cv::aruco::PredefinedDictionaryType eDictionary)
Mutator for the Tag Dictionary Type private member.
Definition ArucoGenerateTags.hpp:135
void SetNumTagsToGenerate(const int nNumTags)
Mutator for the Num Tags To Generate private member. Given number must not exceed the dictionary type...
Definition ArucoGenerateTags.hpp:125
void Join()
Waits for thread to finish executing and then closes thread. This method will block the calling code ...
Definition AutonomyThread.hpp:180
void Start()
When this method is called, it starts a new thread that runs the code within the ThreadedContinuousCo...
Definition AutonomyThread.hpp:117
Here is the call graph for this function:
Here is the caller graph for this function: