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
ArucoDetectionBasicCam.hpp
Go to the documentation of this file.
1
11
16
17
26{
27 // Initialize and start handlers.
28 globals::g_pCameraHandler = new CameraHandler();
29
30 // Get pointer to camera.
31 std::shared_ptr<BasicCamera> ExampleBasicCam1 = globals::g_pCameraHandler->GetBasicCam(CameraHandler::BasicCamName::eHeadGroundCam);
32 // Start basic cam.
33 ExampleBasicCam1->Start();
34
35 // Get pointer to the tag detector for the basic cam.
36 std::unique_ptr<TagDetector> ExampleTagDetector1 = std::make_unique<TagDetector>(ExampleBasicCam1);
37 // Start the basic cam detector.
38 ExampleTagDetector1->Start();
39
40 // Declare mats to store images in.
41 cv::Mat cvNormalFrame1;
42 cv::Mat cvDetectionsFrame1;
43 // Declare vector to store tag detections in.
44 std::vector<tagdetectutils::ArucoTag> vTagDetections1;
45
46 // Declare FPS counter.
47 IPS FPS = IPS();
48
49 // Loop forever, or until user hits ESC.
50 while (true)
51 {
52 // Grab normal frame from camera.
53 std::future<bool> fuCopyStatus1 = ExampleBasicCam1->RequestFrameCopy(cvNormalFrame1);
54 // Get detections from tag detector for BasicCam.
55 std::future<bool> fuDetectionCopyStatus1 = ExampleTagDetector1->RequestDetectedArucoTags(vTagDetections1);
56 // Get detections overlay frame from detector.
57 std::future<bool> fuDetectionFrameCopyStatus1 = ExampleTagDetector1->RequestDetectionOverlayFrame(cvDetectionsFrame1);
58
59 // Show first frame copy.
60 if (fuCopyStatus1.get() && !cvNormalFrame1.empty())
61 {
62 // Put FPS on normal frame.
63 cv::putText(cvNormalFrame1,
64 std::to_string(ExampleBasicCam1->GetIPS().GetExactIPS()),
65 cv::Point(50, 50),
67 1,
68 cv::Scalar(255, 255, 255));
69
70 // Display frame.
71 cv::imshow("BasicCamExample Frame1", cvNormalFrame1);
72 }
73
74 // Show detections overlay frame.
75 if (fuDetectionFrameCopyStatus1.get() && !cvDetectionsFrame1.empty())
76 {
77 // Put detector FPS on frame.
78 cv::putText(cvDetectionsFrame1,
79 std::to_string(ExampleTagDetector1->GetIPS().GetExactIPS()),
80 cv::Point(50, 50),
82 1,
83 cv::Scalar(255, 255, 255));
84
85 // Display frame.
86 cv::imshow("Detections Overlay Frame1", cvDetectionsFrame1);
87 }
88
89 // Wait for detections to be copied.
90 if (fuDetectionCopyStatus1.get())
91 {
92 // Print length of detections vector.
93 LOG_INFO(logging::g_qConsoleLogger, "Detections1 vector length: {}", vTagDetections1.size());
94 }
95
96 // Tick FPS counter.
97 FPS.Tick();
98 // Print FPS of main loop.
99 LOG_INFO(logging::g_qConsoleLogger, "Main FPS: {}", FPS.GetAverageIPS());
100
101 char chKey = cv::waitKey(1);
102 if (chKey == 27) // Press 'Esc' key to exit
103 break;
104 }
105
106 // Close all OpenCV windows.
108
110 // Cleanup.
112 // Stop camera threads.
113 globals::g_pTagDetectionHandler->StopAllDetectors();
114 globals::g_pCameraHandler->StopAllCameras();
115
116 // Set dangling pointers to null.
117 globals::g_pCameraHandler = nullptr;
118 globals::g_pTagDetectionHandler = nullptr;
119}
void RunExample()
This example demonstrates the proper way to interact with the TagDetectionHandler....
Definition ArucoDetectionBasicCam.hpp:25
Defines functions and objects used project wide.
Implements Logging for Autonomy.
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
bool empty() 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