|
PiImageStreamer
|


Public Member Functions | |
| NewCamera (int width, int height, std::string threadName) | |
| virtual | ~NewCamera () |
| void | taskMethod () |
| cv::Mat * | takePicture () |
Public Member Functions inherited from SWE4211RPi::FreeRunningRepeatingTask | |
| FreeRunningRepeatingTask (std::string threadName, int priority=1) | |
| virtual | ~FreeRunningRepeatingTask () |
| void | run () final |
| virtual void | printInformation () |
| virtual double | getCPUUsageInfo () |
| virtual void | resetThreadDiagnostics () |
Public Member Functions inherited from SWE4211RPi::RunnableClass | |
| RunnableClass (std::string threadName, int priority=0) | |
| virtual | ~RunnableClass () |
| virtual pid_t | getThreadID () |
| virtual void | start () final |
| virtual void | setPriority (int priority) final |
| virtual int | getPriority () final |
| virtual bool | isShutdown () final |
| virtual bool | isStarted () final |
| virtual void | stopThreadExecution () |
| virtual void | waitForShutdown () |
Private Attributes | |
| cv::VideoCapture * | capture |
| cv::Mat * | lastFrame |
| cv::Mat | capturedFrame |
| std::atomic< bool > | frameRequested {false} |
| std::mutex | mtx |
| bool | startupCompleted = false |
Additional Inherited Members | |
Static Public Member Functions inherited from SWE4211RPi::RunnableClass | |
| static void | printThreads () |
| static void | resetAllThreadInformation () |
Protected Member Functions inherited from SWE4211RPi::FreeRunningRepeatingTask | |
| virtual void | startChildRunnables () final |
| virtual void | stopChildRunnables () final |
| virtual void | startChildTasks () |
| virtual void | stopChildTasks () |
Protected Attributes inherited from SWE4211RPi::RunnableClass | |
| std::thread * | myThread = NULL |
| pthread_t | executingThread = 0 |
| pid_t | myOSThreadID = 0 |
| std::string | myName |
| std::atomic< bool > | keepGoing {true} |
| std::atomic< bool > | runCompleted {false} |
| std::atomic< bool > | runStarted {false} |
| int | priority = -1 |
Static Protected Attributes inherited from SWE4211RPi::RunnableClass | |
| static std::list< RunnableClass * > | runningThreads |
| NewCamera::NewCamera | ( | int | width, |
| int | height, | ||
| std::string | threadName | ||
| ) |
Construct a new instance of the camera class.
| width | This is the width of the natively captured images. This is the resolution the camera generates. |
| height | This is the height of the natively captured images. This is the resolution the camera generates. |
| threadName | This is the name of the thread that is to be used to run the image capture. |
Start by instantiating a VideoCapture object which will grab the images from the camera.
Next, set the width, height, frames per second (FPS), and buffersize parameters of the capture. The buffersize should always be 1.
Instantiate a new matrix that will hold the last frame.
Check to see that the capture is opened. If if isn't,
|
virtual |
This is the destructor for the camera. It will delete all dynamically allocated objects.
Release the camera.
Delete all allocated objects.
| Mat * NewCamera::takePicture | ( | ) |
This method will request that the camera thread decode the next frame, and then return a copy of the frame decoded in response to the previous request. It does not wait for the camera. The caller is responsible for deleting the returned matrix.
Request that the camera thread decode the next frame it grabs. That frame will be returned by the next call.
Lock the mutex so that the camera thread cannot replace the last frame while it is being copied.

|
virtual |
This is the main thread for the camera. It will grab the next frame from the camera and, if a frame has been requested, decode it and make it available as the last frame.
This is the task method for the camera. It will grab every frame from the camera hardware, so that the camera's buffer always holds the newest frame, but it only pays the cost of decoding a frame when one has been requested by takePicture(). Because this runs on the camera's own thread, the decoding is kept out of the calling task.
If the grab succeeded and a frame has been requested, decode the grabbed frame into the working frame and then clear the request. This is done without holding the mutex, as the working frame is only used by this thread.
If the decode succeeds, lock the mutex and swap the working frame with the last frame, making the new frame available without copying the pixel data.
If the decode fails, restore the request so that the next grabbed frame is decoded instead.
Implements SWE4211RPi::FreeRunningRepeatingTask.
|
private |
The video capture is an instance of the OpenCV Image capture class. It is instantiated in the constructor and used to capture images.
|
private |
This is the working frame that the camera thread decodes into. It is only used by the camera thread, so decoding can happen without holding the mutex.
|
private |
This flag is set by takePicture() to request that the camera thread decode the next frame it grabs. The camera thread clears it once it has taken on the request.
|
private |
This is the last frame that was captured by the camera. It is in an OpenCV Matrix format. It is shared between the camera thread and the callers of takePicture(), so it must only be accessed while holding mtx.
|
private |
This is a mutex within the camera class that prevents race conditions as the images are manipulated. It protects lastFrame as it is handed from the camera thread to the callers of takePicture().
|
private |
This variable will determine if the startup is done or not. Startup basically means that the buffer is fully emptied.