PiImageStreamer
Loading...
Searching...
No Matches
SWE4211RPi::AbstractImageCapturer Class Referenceabstract

#include <AbstractImageCapturer.h>

Inheritance diagram for SWE4211RPi::AbstractImageCapturer:
Collaboration diagram for SWE4211RPi::AbstractImageCapturer:

Public Member Functions

virtual void taskMethod ()=0
 
void printVideoStreamMetrics ()
 
void addOverlay (std::shared_ptr< AbstractImageOverlay > overlay)
 
void removeOverlay (std::shared_ptr< AbstractImageOverlay > overlay)
 
- Public Member Functions inherited from SWE4211RPi::PeriodicTask
 PeriodicTask (std::string threadName, uint32_t period, int priority=1)
 
virtual ~PeriodicTask ()
 
virtual void setTaskPeriod (uint32_t period) final
 
virtual uint32_t getTaskPeriod () final
 
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 ()
 

Protected Member Functions

 AbstractImageCapturer (SWE4211RPi::NewCamera &referencedCamera, AbstractImageTransmitter &trans, int width, int height, std::string threadName, uint32_t period)
 
virtual ~AbstractImageCapturer ()
 
void printFrameTiming ()
 
void resetMetricsOnNewConnection ()
 
void applyOverlays (cv::Mat *image)
 
- Protected Member Functions inherited from SWE4211RPi::PeriodicTask
virtual void startChildRunnables () final
 
virtual void stopChildRunnables () final
 
virtual void startChildTasks ()
 
virtual void stopChildTasks ()
 

Static Protected Member Functions

static std::chrono::microseconds getThreadCpuTime ()
 

Protected Attributes

SWE4211RPi::NewCamera & myCamera
 
AbstractImageTransmitter & myTrans
 
int imageWidth
 
int imageHeight
 
cv::Size * size
 
cv::Mat resizedImage
 
int count = 0
 
int xmitTimeDeadlineMissCount =0
 
std::chrono::microseconds totalGrab {0}
 
std::chrono::microseconds totalResize {0}
 
std::chrono::microseconds totalTransmit {0}
 
long framesTransmitted = 0
 
std::chrono::microseconds grabTime {0}
 
std::chrono::microseconds resizeTime {0}
 
std::chrono::microseconds transmitTime {0}
 
std::chrono::microseconds delayTime {0}
 
int lastConnectionNumber = 0
 
std::list< std::shared_ptr< AbstractImageOverlay > > overlays
 
- Protected Attributes inherited from SWE4211RPi::PeriodicTask
uint32_t taskPeriod = 100000
 
- 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
 

Additional Inherited Members

- Static Public Member Functions inherited from SWE4211RPi::RunnableClass
static void printThreads ()
 
static void resetAllThreadInformation ()
 
- Static Protected Attributes inherited from SWE4211RPi::RunnableClass
static std::list< RunnableClass * > runningThreads
 

Detailed Description

This is the abstract base class for all image capturers.

Constructor & Destructor Documentation

◆ AbstractImageCapturer()

AbstractImageCapturer::AbstractImageCapturer ( SWE4211RPi::NewCamera &  referencedCamera,
AbstractImageTransmitter &  trans,
int  width,
int  height,
std::string  threadName,
uint32_t  period 
)
protected

Construct a new instance of the image capturer. It will instantiate an instance of the Size class and allocate the resize buffer.

Parameters
referencedCameraThis is the camera that is referenced.
transThis is the image transmitter that is to send the given image across the network.
widthThis is the width of the image that is to be sent in pixels.
heightThis is the height of the image that is to be sent in pixels.
threadNameThis is the name of the thread that is to execute.
periodThis is the period for the task, given in microseconds.
  1. Store the width and height of the image to be transmitted, and create a Size object with them.

  2. Allocate the resize buffer once, at the transmitted size, as a 3 channel (BGR) color image.

◆ ~AbstractImageCapturer()

AbstractImageCapturer::~AbstractImageCapturer ( )
protectedvirtual

This is the destructor for the class.

This is the destructor. It frees the Size object and restores the terminal's normal scrolling.

Member Function Documentation

◆ addOverlay()

void AbstractImageCapturer::addOverlay ( std::shared_ptr< AbstractImageOverlay >  overlay)

This method will add an overlay to the list of overlays that are to be applied to the image that has been captured.

Parameters
overlayThis is the overlay to apply.

◆ applyOverlays()

void AbstractImageCapturer::applyOverlays ( cv::Mat *  image)
protected

This method will apply the active overlays to a given image.

Parameters
imageThis is the image that the overlays are to be applied to.
Here is the caller graph for this function:

◆ getThreadCpuTime()

std::chrono::microseconds AbstractImageCapturer::getThreadCpuTime ( )
staticprotected

This method will return the amount of CPU time that the calling thread has used so far. Unlike a wall clock, this only advances while the thread is actually running on a CPU, so time spent preempted by other threads or blocked waiting is not counted. Both user and kernel (system call) time are included.

Returns
The CPU time used by the calling thread, in us.
Here is the caller graph for this function:

◆ printFrameTiming()

void AbstractImageCapturer::printFrameTiming ( )
protected

This method will print the timing for the most recently transmitted frame, as well as the running averages, to the console. Before printing, the metrics are reset if a new connection has started.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printVideoStreamMetrics()

void AbstractImageCapturer::printVideoStreamMetrics ( )

This method will print metrics out to the console about the image stream.

◆ removeOverlay()

void AbstractImageCapturer::removeOverlay ( std::shared_ptr< AbstractImageOverlay >  overlay)

This method will remove an overlay from the list of overlays that are to be applied to the image that has been captured.

Parameters
overlayThis is the overlay to remove.

This method will remove an overlay to the list of overlays that are to be applied to the image that has been captured.

Parameters
overlayThis is the overlay to remove.

◆ resetMetricsOnNewConnection()

void AbstractImageCapturer::resetMetricsOnNewConnection ( )
protected

This method will reset the metrics if a new connection has started since the last frame, so that the counts and averages only cover the current connection. The current frame's measurements are kept as the first frame of the new connection.

  1. If the transmitter's connection number has changed, a new connection has started.

    1. Remember the new connection number.
    2. Restart the totals from this frame's measurements, and count this frame as the first frame transmitted.
    3. Restart the missed deadline count, counting this frame if it missed its deadline.
    4. Reset the displayed count to 0, which also causes the table to be redrawn.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ taskMethod()

virtual void SWE4211RPi::AbstractImageCapturer::taskMethod ( )
pure virtual

This is the taskMethod that will run once each period. It must be implemented by the derived class to capture, process, and transmit one image.

Implements SWE4211RPi::PeriodicTask.

Implemented in SWE4211RPi::CompressedImageCapturer.

Member Data Documentation

◆ count

int SWE4211RPi::AbstractImageCapturer::count = 0
protected

This is the frame count shown in the console table. It increments each time a frame's timing is printed, and is reset to 0 when a new connection starts, which causes the table to be redrawn.

◆ framesTransmitted

long SWE4211RPi::AbstractImageCapturer::framesTransmitted = 0
protected

This is the number of frames that have been transmitted on the current connection. It is used to calculate the averages.

◆ grabTime

std::chrono::microseconds SWE4211RPi::AbstractImageCapturer::grabTime {0}
protected

These are the timing measurements, in us, for the most recently transmitted frame. The grab, resize, and transmit times are CPU times for this thread. The delay time is a wall clock time.

◆ imageHeight

int SWE4211RPi::AbstractImageCapturer::imageHeight
protected

This is the height of the image that is to be transmitted in pixels. It may or may not be the same as the height captured by the camera.

◆ imageWidth

int SWE4211RPi::AbstractImageCapturer::imageWidth
protected

This is the width of the image that is to be transmitted in pixels. It may or may not be the same as the width captured by the camera.

◆ lastConnectionNumber

int SWE4211RPi::AbstractImageCapturer::lastConnectionNumber = 0
protected

This is the transmitter's connection number as of the last frame. When the transmitter's connection number no longer matches, a new connection has started and the metrics are reset.

◆ myCamera

SWE4211RPi::NewCamera& SWE4211RPi::AbstractImageCapturer::myCamera
protected

This is a reference to the camera that is going to be used to capture the images.

◆ myTrans

AbstractImageTransmitter& SWE4211RPi::AbstractImageCapturer::myTrans
protected

This is a reference to the image transmitter that will transmit the image to the other device.

◆ overlays

std::list<std::shared_ptr<AbstractImageOverlay> > SWE4211RPi::AbstractImageCapturer::overlays
protected

This variable keeps track of the list of overlays that are to be applied to the image before streaming.

◆ resizedImage

cv::Mat SWE4211RPi::AbstractImageCapturer::resizedImage
protected

This is the fixed buffer that the resized image is written into. It is allocated once, at the transmitted size, in the constructor and reused for every frame, so that resizing does not allocate a new image each time.

◆ size

cv::Size* SWE4211RPi::AbstractImageCapturer::size
protected

This is the size of the image that is to be transmitted. It is an openCV Size type.

◆ totalGrab

std::chrono::microseconds SWE4211RPi::AbstractImageCapturer::totalGrab {0}
protected

These are the running totals, in us of CPU time, for each step. They are divided by framesTransmitted to give the averages.

◆ xmitTimeDeadlineMissCount

int SWE4211RPi::AbstractImageCapturer::xmitTimeDeadlineMissCount =0
protected

This variable will keep track of how many times the image has failed to transmit in an appropriate amount of time (i.e. we have not transmitted fast enough.)


The documentation for this class was generated from the following files: