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
OpenBasicCam.hpp File Reference

Example file that demonstrates opening and using multiple different features of the basic camera. More...

Include dependency graph for OpenBasicCam.hpp:

Go to the source code of this file.

Functions

void RunExample ()
 This example demonstrates the proper way to interact with the CameraHandler. A pointer to a BasicCam is retrieved and then a couple of local cv::Mat are created for storing frames. Then, the frames are passed to the RequestFrameCopy function of the camera and a future is IMMEDIATELY returned. The method call doesn't wait for frame to be retrieved/copied before returning. This allows you to request multiple frames/data from the camera non-sequentially.

Detailed Description

Example file that demonstrates opening and using multiple different features of the basic camera.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-16

Function Documentation

◆ RunExample()

void RunExample ( )

This example demonstrates the proper way to interact with the CameraHandler. A pointer to a BasicCam is retrieved and then a couple of local cv::Mat are created for storing frames. Then, the frames are passed to the RequestFrameCopy function of the camera and a future is IMMEDIATELY returned. The method call doesn't wait for frame to be retrieved/copied before returning. This allows you to request multiple frames/data from the camera non-sequentially.

Inside the camera thread, the cv::Mat pointer that points to the cv::Mat within THIS class is written to and an std::promise is set to TRUE. The future that was return now contains this TRUE value. When the get() method is called on the returned future, the code will block until the promise is fulfilled (set to TRUE). Once the get() method returns, the cv::Mat within this class now contains a complete frame and can be display or used in other computer vision things.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-22
36{
37 // Initialize basic cam.
38 std::shared_ptr<BasicCamera> ExampleBasicCam1 = std::make_unique<BasicCam>(0, 1280, 720, 60, PIXEL_FORMATS::eBGR, 0, 0, false);
39 // Start basic cam.
40 ExampleBasicCam1->Start();
41
42 // Declare mats to store images in.
43 cv::Mat cvNormalFrame1;
44 cv::Mat cvNormalFrame;
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 std::future<bool> fuCopyStatus2 = ExampleBasicCam1->RequestFrameCopy(cvNormalFrame2);
55
56 // Show first frame copy.
57 if (fuCopyStatus1.get() && !cvNormalFrame1.empty())
58 {
59 // Print info.
60 LOG_INFO(logging::g_qConsoleLogger,
61 "BasicCam Getter FPS: {} | 1% Low: {}",
62 ExampleBasicCam1->GetIPS().GetAverageIPS(),
63 ExampleBasicCam1->GetIPS().Get1PercentLow());
64
65 // Put FPS on normal frame.
66 cv::putText(cvNormalFrame1,
67 std::to_string(ExampleBasicCam1->GetIPS().GetExactIPS()),
68 cv::Point(50, 50),
70 1,
71 cv::Scalar(255, 255, 255));
72
73 // Display frame.
74 cv::imshow("BasicCamExample Frame1", cvNormalFrame1);
75 }
76
77 // Show second frame copy.
78 if (fuCopyStatus2.get() && !cvNormalFrame2.empty())
79 {
80 // Print info.
81 LOG_INFO(logging::g_qConsoleLogger,
82 "BasicCam Getter FPS: {} | 1% Low: {}",
83 ExampleBasicCam1->GetIPS().GetAverageIPS(),
84 ExampleBasicCam1->GetIPS().Get1PercentLow());
85
86 // Put FPS on normal frame.
87 cv::putText(cvNormalFrame2,
88 std::to_string(ExampleBasicCam1->GetIPS().GetExactIPS()),
89 cv::Point(50, 50),
91 1,
92 cv::Scalar(255, 255, 255));
93
94 // Display frame.
95 cv::imshow("BasicCamExample Frame2", cvNormalFrame2);
96 }
97
98 // Tick FPS counter.
99 FPS.Tick();
100 // Print FPS of main loop.
101 LOG_INFO(logging::g_qConsoleLogger, "Main FPS: {}", FPS.GetAverageIPS());
102
103 char chKey = cv::waitKey(1);
104 if (chKey == 27) // Press 'Esc' key to exit
105 break;
106 }
107
108 // Close all OpenCV windows.
110
112 // Cleanup.
114 // Stop camera threads.
115 globals::g_pCameraHandler->StopAllCameras();
116}
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
Here is the call graph for this function: