Base class of the CAVAPA calculations. More...
#include <analysiscontroller.h>
Signals | |
void | calculationComplete () |
Signals that calculation has ended. More... | |
void | error (const std::string &message, ErrorLevel level) |
Signals that something went wrong during the calculation. More... | |
void | updated (const std::vector< FrameCapture > &frames, const FrameStats &statistics) |
It signals frame updates or calculation updates. More... | |
Public Member Functions | |
AnalysisController () | |
Creates the CAVAPA object. | |
DISALLOW_COPY_AND_ASSIGN (AnalysisController) | |
Copy and assign of the class is not allowed. | |
SourceID | addSource (const std::string &path, SourceID id=UNDEFINED_SOURCE, FrameTime start_point=0) |
Adds a custom video source. More... | |
bool | addSource (const std::vector< std::string > &paths, SourceID id=UNDEFINED_SOURCE, FrameTime start_point=0) |
Adds a custom source with multiple files and a fixed ID number. More... | |
bool | canChangeSourceResolution (SourceID id) const |
Checks if the source resolution can be changed. More... | |
bool | canPause () const |
Indicates if the running calculation can be paused. More... | |
int | countAvailableCameras () const |
Counts the available connected hardware cameras. More... | |
bool | exportResults (const ExportOptions &options) const |
Exports the current Results to the CSV File. More... | |
double | getCalculationFPS () const |
Retrieves the calculation framerate. More... | |
std::string | getLastError () const |
Retrieves the last error that occured. More... | |
std::vector< FrameStats > | getResults (FrameTime start, FrameTime stop, int points) const |
Returns calculation results from a given period. More... | |
int | getSourceCount () const |
Retrieves the total count of sources. More... | |
std::string | getSourceDescription (SourceID id) const |
Returns the description of the source. More... | |
std::vector< cv::Rect > | getSourceExcludes (SourceID id) const |
Returns the currently excluded rectangles from the source. More... | |
std::vector< std::string > | getSourceFilenames (SourceID id) const |
Returns the list of the files associated with the source. More... | |
std::vector< SourceID > | getSourceListing () const |
Returns a list of all sources in the class. More... | |
FrameTime | getSourcePosition (SourceID id) const |
Retrieves the current time position of a source. More... | |
cv::Size | getSourceResolution (SourceID id) const |
Retrieves the source's frame resolution. More... | |
SourceStats | getSourceStats (SourceID id) const |
Retrieves the source's current statistics. More... | |
SourceType | getSourceType (SourceID id) const |
Returns the type of the selected source. More... | |
FrameTime | getVideoLength (SourceID id) const |
Retrieves the length of the video source. More... | |
int | initCameras (int max_loops=10) |
Initializes the hardware cameras. More... | |
bool | isPaused () const |
Retrieves the current pause status. More... | |
bool | isRunning () const |
Retrieves the current status of the calculation. More... | |
bool | load (const std::string &path="results.cpa") |
Loads the calculation results and recorded file information. More... | |
bool | pause () |
Pauses or unpauses the calculation. More... | |
bool | removeSource (SourceID id) |
Removes the source. More... | |
bool | reset () |
Resets the calculation results. More... | |
bool | save (const std::string &path="results.cpa") |
Saves the calculation results and sightings. More... | |
bool | setCameraFPS (double fps) |
Sets the default FPS for camera sources. More... | |
void | setHighlight (bool highlight) |
Sets the individual sighting rectangle highlights. More... | |
void | setHighlightColor (const cv::Scalar &color) |
Sets the sighting's highlighting color. More... | |
bool | setPosition (FrameTime pos) |
Sets the current time position of all the sources. More... | |
bool | setRecorderCodec (const std::string &codec, const std::string &extension="avi") |
Sets the default camera recorder codec. More... | |
void | setRecordTimeLimit (unsigned int length) |
Sets the maximum length of one recording. More... | |
bool | setSourceBarrelCorrection (SourceID id, double amount) |
Sets the barrel correction on a source. More... | |
void | setSourceExcludes (SourceID id, const std::vector< cv::Rect > &rects) |
Sets the excluded rectangles for a source. More... | |
bool | setSourceResolution (SourceID id, const cv::Size &new_size) |
Sets the source resolution. More... | |
bool | setVideoSpeed (double ratio=1.0) |
Sets the video source speed. More... | |
void | setWorkDirectory (const std::string &path) |
Sets the path for the calculation directory. More... | |
bool | sourceCanRecord (SourceID id) const |
Checks if the source is capable of recording. More... | |
bool | sourcePlay (SourceID id) |
Starts playing a video source. More... | |
bool | sourceSeek (SourceID id, FrameTime position) |
Seeks the video source to a specific time. More... | |
bool | sourceStepBackward (SourceID id) |
Steps the source one frame back. More... | |
bool | sourceStepForward (SourceID id) |
Steps the source one frame forward. More... | |
bool | sourceStop (SourceID id) |
Stops playing the video source. More... | |
bool | start (const std::vector< SourceID > &calc_sources, const std::vector< cavapa::CameraSettings > &settings, const std::vector< cavapa::CalibrationPoint > &points, bool record=false, int calc_time=0) |
Starts the CAVAPA calculation. More... | |
void | stop () |
Stops the current CAVAPA calculation. More... | |
Base class of the CAVAPA calculations.
The class is the heart of the CAVAPA calculation handling. Its purpose is to retrieve frames from the sources and pass them to the CAVAPA algorithm. It also stores the calculation results and includes the frame update timer.
The class can detect connected hardware cameras with initCameras() but any other video source must be manually added with addSource(). Once the sources are selected the calculation can be started with start().
During the calculation the class sends signals updated() on each frame. The calculation can then be stopped with stop() or if the calculation terminates on its own signal calculationComplete() is sent. Any errors during the calculation can be catched from the signal error().
User can select the calculation framerate with setCameraFPS when cameras are used as a source. When video files are used the framerate cannot be selected. The individual sources can be played and altered when the calculation is not running.
SourceID cavapa_gui::AnalysisController::addSource | ( | const std::string & | path, |
SourceID | id = UNDEFINED_SOURCE , |
||
FrameTime | start_point = 0 |
||
) |
Adds a custom video source.
Network cameras or video files need to be added with the method. The base recognizes automatically only hardware cameras.
path | The video source path can be url or video file. |
id | The desired ID number of the new source. This source ID must not exist. Use UNDEFINED_SOURCE to get a new unique ID. |
start_point | Source start point will be used as the initial position of the source. All calls to setPosition() will use this as base. This is not used for sourceSeek() or other methods. It also has no effect on any other than video files. |
bool cavapa_gui::AnalysisController::addSource | ( | const std::vector< std::string > & | paths, |
SourceID | id = UNDEFINED_SOURCE , |
||
FrameTime | start_point = 0 |
||
) |
Adds a custom source with multiple files and a fixed ID number.
It can be used to play existing results from video files.
paths | The ordered list of the video filenames. |
id | The desired ID number of the new source. The source ID must not exist. Use UNDEFINED_SOURCE to get a new unique ID. |
start_point | The source start point. Will be used as the initial position of the source. All calls to setPosition() will use this as base. This is not used for sourceSeek() or other methods. It also has no effect on any other than video files. |
|
signal |
bool cavapa_gui::AnalysisController::canChangeSourceResolution | ( | SourceID | id | ) | const |
Checks if the source resolution can be changed.
id | The source ID number. |
bool cavapa_gui::AnalysisController::canPause | ( | ) | const |
Indicates if the running calculation can be paused.
int cavapa_gui::AnalysisController::countAvailableCameras | ( | ) | const |
Counts the available connected hardware cameras.
The method only recognizes USB and other cameras. No network streams or other sources are counted. This will not re-attempt to open already open HW-devices.
|
signal |
Signals that something went wrong during the calculation.
It is used when there is no other way to indicate an error.
message | The error message. |
level | The error level. |
|
inline |
Exports the current Results to the CSV File.
options | The parameters for export. |
|
inline |
Retrieves the calculation framerate.
It retrieves only the current running calculation framerate. It may not be what was given with setFPS() as it is adjusted to match the selected source framerates.
|
inline |
Retrieves the last error that occured.
Some of the class methods return failure values and this method can be used to retrieve more detailed information on what happened.
|
inline |
Returns calculation results from a given period.
It can be used to return frame results from a certain period. Average values are calculated automatically from the returned period points.
start | The period start time. If 0, the period will start from the first possible frame. |
stop | The period end time. If 0, the period will end at the last possible frame. |
points | The number of points to return from the specified period. |
|
inline |
Retrieves the total count of sources.
It just sums up all the sources in the class, similarly as retrieving the source listing with getSourceListing() and checking its size.
string cavapa_gui::AnalysisController::getSourceDescription | ( | SourceID | id | ) | const |
Returns the description of the source.
id | The source ID number. |
std::vector<cv::Rect> cavapa_gui::AnalysisController::getSourceExcludes | ( | SourceID | id | ) | const |
Returns the currently excluded rectangles from the source.
id | The source ID number. |
vector< string > cavapa_gui::AnalysisController::getSourceFilenames | ( | SourceID | id | ) | const |
Returns the list of the files associated with the source.
With the cameras these will be the names of the files that were recorded.
id | The source ID number. |
vector< SourceID > cavapa_gui::AnalysisController::getSourceListing | ( | ) | const |
Returns a list of all sources in the class.
Retrieves the current time position of a source.
This will be the current time on the video files. Cameras and other sources will always return 0.
id | The source ID number. |
Size cavapa_gui::AnalysisController::getSourceResolution | ( | SourceID | id | ) | const |
Retrieves the source's frame resolution.
id | The source ID number. |
SourceStats cavapa_gui::AnalysisController::getSourceStats | ( | SourceID | id | ) | const |
Retrieves the source's current statistics.
The statistics can be used to get information on the missed, recorded etc. frames, and can provide insight on possible source lag or other problems. This is also the way to know how many frames a video file has.
id | The source ID number. |
SourceType cavapa_gui::AnalysisController::getSourceType | ( | SourceID | id | ) | const |
Returns the type of the selected source.
id | The source ID number. |
Retrieves the length of the video source.
id | The source ID number. |
int cavapa_gui::AnalysisController::initCameras | ( | int | max_loops = 10 | ) |
Initializes the hardware cameras.
max_loops | The maximum number of the devices to be checked for HW cameras. This should always be more than the actual number of cameras that are expected to be connected. |
|
inline |
Retrieves the current pause status.
|
inline |
Retrieves the current status of the calculation.
bool cavapa_gui::AnalysisController::load | ( | const std::string & | path = "results.cpa" | ) |
Loads the calculation results and recorded file information.
It loads existing results from a file. Once a result file has been opened, you cannot modify the sources. You can only play the recorded calculation and observe the results. You need to call reset() to be able to start a new calculation or add sources.
path | The path of the results file. |
bool cavapa_gui::AnalysisController::pause | ( | ) |
Pauses or unpauses the calculation.
bool cavapa_gui::AnalysisController::removeSource | ( | SourceID | id | ) |
Removes the source.
id | The source ID number. |
bool cavapa_gui::AnalysisController::reset | ( | ) |
Resets the calculation results.
After this call, all the saved results are entirely gone.
bool cavapa_gui::AnalysisController::save | ( | const std::string & | path = "results.cpa" | ) |
Saves the calculation results and sightings.
It saves the current CAVAPA calculation into a file. It does not save recorded filenames or any information on the sources.
path | The path of the results file. |
bool cavapa_gui::AnalysisController::setCameraFPS | ( | double | fps | ) |
Sets the default FPS for camera sources.
It will not have any effect if there are any cameras in the calculation that report a lower framerate than what has been set manually. Only HW cameras are able to report framerates. FPS can only be changed when calculation is not running.
fps | The framerate to be set. |
|
inline |
Sets the individual sighting rectangle highlights.
This will affect all incoming source frames. The detected sightings will be highlighted with a rectangle.
highlight | True if the sightings should be highlighted or false if they should not. |
|
inline |
Sets the sighting's highlighting color.
The color is used in the rectangles that are drawn around detected individuals on source frames.
color | The color in BGR value (not RGB!). |
bool cavapa_gui::AnalysisController::setPosition | ( | FrameTime | pos | ) |
Sets the current time position of all the sources.
The purpose of the method is to seek the calculation result point for every video source. Video sources will use their initialized start point as a base for the time seek. The position can only be changed when the calculation is not running.
pos | Desired time position. |
bool cavapa_gui::AnalysisController::setRecorderCodec | ( | const std::string & | codec, |
const std::string & | extension = "avi" |
||
) |
Sets the default camera recorder codec.
It only affects new recordings, not the ones that are already running.
codec | The 4 character code for the video (FourCC). See http://www.fourcc.org/codecs.php |
extension | The file extension that is used for new recordings. It MUST match the codec, otherwise files will fail to load. |
|
inline |
Sets the maximum length of one recording.
length | The length of the recording in seconds or 0 if no limit. |
bool cavapa_gui::AnalysisController::setSourceBarrelCorrection | ( | SourceID | id, |
double | amount | ||
) |
Sets the barrel correction on a source.
It will add the given effect on all frames returned from the source from now on. These frames will also be passed on the calculation.
id | The source ID number. |
amount | The amount of barrel correction to be applied. 0.0 means no effect. Positive values increase the effect. Amount can't be negative. |
void cavapa_gui::AnalysisController::setSourceExcludes | ( | SourceID | id, |
const std::vector< cv::Rect > & | rects | ||
) |
Sets the excluded rectangles for a source.
The given rectangles will be drawn black on all frames that the source produces. These are used to exclude specific areas from the source frame. The rectangles are always drawn on the frame before analysing them, but after they are written to a file.
id | The source ID number. |
rects | The rectangles to be excluded. |
bool cavapa_gui::AnalysisController::setSourceResolution | ( | SourceID | id, |
const cv::Size & | new_size | ||
) |
Sets the source resolution.
id | The source ID number. |
new_size | The desired size. |
bool cavapa_gui::AnalysisController::setVideoSpeed | ( | double | ratio = 1.0 | ) |
Sets the video source speed.
If all the sources are video files this will multiply the framerate, otherwise this has no effect.
ratio | The desired video speed ratio. Negative or 0.0 will indicate as fast as possible. |
void cavapa_gui::AnalysisController::setWorkDirectory | ( | const std::string & | path | ) |
Sets the path for the calculation directory.
The directory will be used to store recordings, calculation results etc.
path | The directory path. |
bool cavapa_gui::AnalysisController::sourceCanRecord | ( | SourceID | id | ) | const |
Checks if the source is capable of recording.
id | The source ID number. |
bool cavapa_gui::AnalysisController::sourcePlay | ( | SourceID | id | ) |
Starts playing a video source.
id | The source ID number. |
Seeks the video source to a specific time.
id | The source ID number. |
position | The time position of the video. |
|
inline |
Steps the source one frame back.
id | Source ID number. |
|
inline |
Steps the source one frame forward.
id | The source ID number. |
bool cavapa_gui::AnalysisController::sourceStop | ( | SourceID | id | ) |
Stops playing the video source.
id | The source ID number. |
bool cavapa_gui::AnalysisController::start | ( | const std::vector< SourceID > & | calc_sources, |
const std::vector< cavapa::CameraSettings > & | settings, | ||
const std::vector< cavapa::CalibrationPoint > & | points, | ||
bool | record = false , |
||
int | calc_time = 0 |
||
) |
Starts the CAVAPA calculation.
calc_sources | The sources to be included in the calculation. |
settings | The source settings. The resolution and the barrel values have no effect as AnalysisController will fill them in automatically. |
points | Calibration points. |
record | If the video sources should be recorded or not. |
calc_time | Maximum runtime in seconds. Infinite if 0. |
void cavapa_gui::AnalysisController::stop | ( | ) |
Stops the current CAVAPA calculation.
|
signal |
It signals frame updates or calculation updates.
When the calculation is in progress, only the sources selected to the calculation will perform frame updates. When the calculation is not in progress, all the sources will return the current frame.
frames | The current frames of the video sources. |
statistics | Holds the frame statistics. |