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
ArucoDetectionZED.hpp
Go to the documentation of this file.
1
11
17
18
27{
28 // Initialize and start handlers.
29 globals::g_pCameraHandler = new CameraHandler();
30 globals::g_pTagDetectionHandler = new TagDetectionHandler();
31
32 // Get pointer to camera.
33 std::shared_ptr<ZEDCamera> ExampleZEDCam1 = globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eHeadMainCam);
34 // Start basic cam.
35 ExampleZEDCam1->Start();
36
37 // Get pointer to the tag detector for the basic cam.
38 std::shared_ptr<TagDetector> ExampleTagDetector1 = globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam);
39 // Start the basic cam detector.
40 ExampleTagDetector1->Start();
41
42 // Declare mats to store images in.
43 cv::Mat cvNormalFrame1;
44 cv::Mat cvDetectionsFrame1;
45 cv::cuda::GpuMat cvGPUNormalFrame1;
46 // Declare vector to store tag detections in.
47 std::vector<tagdetectutils::ArucoTag> vTagDetections1;
48
49 // Declare FPS counter.
50 IPS FPS = IPS();
51
52 // Loop forever, or until user hits ESC.
53 while (true)
54 {
55 // Create instance variables.
56 std::future<bool> fuCopyStatus1;
57 std::future<bool> fuDetectionCopyStatus1;
58 std::future<bool> fuDetectionFrameCopyStatus1;
59
60 // Check if the camera is setup to use CPU or GPU mats.
61 if (ExampleZEDCam1->GetUsingGPUMem())
62 {
63 // Grab normal frame from camera.
64 fuCopyStatus1 = ExampleZEDCam1->RequestFrameCopy(cvGPUNormalFrame1);
65 }
66 else
67 {
68 // Grab normal frame from camera.
69 fuCopyStatus1 = ExampleZEDCam1->RequestFrameCopy(cvNormalFrame1);
70 }
71 // Get detections overlay frame from detector.
72 fuDetectionFrameCopyStatus1 = ExampleTagDetector1->RequestDetectionOverlayFrame(cvDetectionsFrame1);
73 // Grab other info from detector.
74 fuDetectionCopyStatus1 = ExampleTagDetector1->RequestDetectedArucoTags(vTagDetections1);
75
76 // Show first frame copy.
77 if (fuCopyStatus1.get())
78 {
79 // Check if the camera is setup to use CPU or GPU mats.
80 if (ExampleZEDCam1->GetUsingGPUMem())
81 {
82 // Download memory from gpu mats if necessary.
83 cvGPUNormalFrame1.download(cvNormalFrame1);
84 }
85
86 // Put FPS on normal frame.
87 cv::putText(cvNormalFrame1,
88 std::to_string(ExampleZEDCam1->GetIPS().GetExactIPS()),
89 cv::Point(50, 50),
91 1,
92 cv::Scalar(255, 255, 255));
93
94 // Display frame.
95 cv::imshow("BasicCamExample Frame1", cvNormalFrame1);
96 }
97
98 // Show detections overlay frame.
99 if (fuDetectionFrameCopyStatus1.get() && !cvDetectionsFrame1.empty())
100 {
101 // Put detector FPS on frame.
102 cv::putText(cvDetectionsFrame1,
103 std::to_string(ExampleTagDetector1->GetIPS().GetExactIPS()),
104 cv::Point(50, 50),
106 1,
107 cv::Scalar(255, 255, 255));
108
109 // Display frame.
110 cv::imshow("Detections Overlay Frame1", cvDetectionsFrame1);
111 }
112
113 // Wait for detections to be copied.
114 if (fuDetectionCopyStatus1.get())
115 {
116 // Print length of detections vector.
117 LOG_INFO(logging::g_qConsoleLogger, "Detections1 vector length: {}", vTagDetections1.size());
118 }
119
120 // Tick FPS counter.
121 FPS.Tick();
122 // Print FPS of main loop.
123 LOG_INFO(logging::g_qConsoleLogger, "Main FPS: {}", FPS.GetAverageIPS());
124
125 char chKey = cv::waitKey(1);
126 if (chKey == 27) // Press 'Esc' key to exit
127 break;
128 }
129
130 // Close all OpenCV windows.
132
134 // Cleanup.
136 // Stop RoveComm quill logging or quill will segfault if trying to output logs to RoveComm.
137 network::g_bRoveCommUDPStatus = false;
138 network::g_bRoveCommTCPStatus = false;
139
140 // Stop camera threads.
141 globals::g_pTagDetectionHandler->StopAllDetectors();
142 globals::g_pCameraHandler->StopAllCameras();
143}
void RunExample()
This example demonstrates the proper way to interact with the TagDetectionHandler....
Definition ArucoDetectionZED.hpp:26
Defines functions and objects used project wide.
Implements Logging for Autonomy.
Defines functions and objects used for Autonomy Networking.
Defines the BasicCam class.
This file is a utility used to check if any file from the example directory has been included....
The CameraHandler class is responsible for managing all of the camera feeds that Autonomy_Software us...
Definition CameraHandler.h:34
This util class provides an easy way to keep track of iterations per second for any body of code.
Definition IPS.hpp:30
double GetAverageIPS() const
Calculates the average iterations per second.
Definition IPS.hpp:180
void Tick()
This method is used to update the iterations per second counter and recalculate all of the IPS metric...
Definition IPS.hpp:138
The TagDetectionHandler class is responsible for managing all of the different detectors that Autonom...
Definition TagDetectionHandler.h:28
bool empty() const
void download(OutputArray dst) const
Point2i Point
Scalar_< double > Scalar
void imshow(const String &winname, InputArray mat)
int waitKey(int delay=0)
void destroyAllWindows()
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
FONT_HERSHEY_COMPLEX