mirror of
https://github.com/opencv/opencv.git
synced 2025-07-26 23:27:01 +08:00

* G-API-NG/Streaming: Introduced a Streaming API Now a GComputation can be compiled in a special "streaming" way and then "played" on a video stream. Currently only VideoCapture is supported as an input source. * G-API-NG/Streaming: added threading & real streaming * G-API-NG/Streaming: Added tests & docs on Copy kernel - Added very simple pipeline tests, not all data types are covered yet (in fact, only GMat is tested now); - Started testing non-OCV backends in the streaming mode; - Added required fixes to Fluid backend, likely it works OK now; - Added required fixes to OCL backend, and now it is likely broken - Also added a UMat-based (OCL) version of Copy kernel * G-API-NG/Streaming: Added own concurrent queue class - Used only if TBB is not available * G-API-NG/Streaming: Fixing various issues - Added missing header to CMakeLists.txt - Fixed various CI issues and warnings * G-API-NG/Streaming: Fixed a compile-time GScalar queue deadlock - GStreamingExecutor blindly created island's input queues for compile-time (value-initialized) GScalars which didn't have any producers, making island actor threads wait there forever * G-API-NG/Streaming: Dropped own version of Copy kernel One was added into master already * G-API-NG/Streaming: Addressed GArray<T> review comments - Added tests on mov() - Removed unnecessary changes in garray.hpp * G-API-NG/Streaming: Added Doxygen comments to new public APIs Also fixed some other comments in the code * G-API-NG/Streaming: Removed debug info, added some comments & renamed vars * G-API-NG/Streaming: Fixed own-vs-cv abstraction leak - Now every island is triggered with own:: (instead of cv::) data objects as inputs; - Changes in Fluid backend required to support cv::Mat/Scalar were reverted; * G-API-NG/Streaming: use holds_alternative<> instead of index/index_of test - Also fixed regression test comments - Also added metadata check comments for GStreamingCompiled * G-API-NG/Streaming: Made start()/stop() more robust - Fixed various possible deadlocks - Unified the shutdown code - Added more tests covering different corner cases on start/stop * G-API-NG/Streaming: Finally fixed Windows crashes In fact the problem hasn't been Windows-only. Island thread popped data from queues without preserving the Cmd objects and without taking the ownership over data acquired so when islands started to process the data, this data may be already freed. Linux version worked only by occasion. * G-API-NG/Streaming: Fixed (I hope so) Windows warnings * G-API-NG/Streaming: fixed typos in internal comments - Also added some more explanation on Streaming/OpenCL status * G-API-NG/Streaming: Added more unit tests on streaming - Various start()/stop()/setSource() call flow combinations * G-API-NG/Streaming: Added tests on own concurrent bounded queue * G-API-NG/Streaming: Added more tests on various data types, + more - Vector/Scalar passed as input; - Vector/Scalar passed in-between islands; - Some more assertions; - Also fixed a deadlock problem when inputs are mixed (1 constant, 1 stream) * G-API-NG/Streaming: Added tests on output data types handling - Vector - Scalar * G-API-NG/Streaming: Fixed test issues with IE + Windows warnings * G-API-NG/Streaming: Decoupled G-API from videoio - Now the core G-API doesn't use a cv::VideoCapture directly, it comes in via an abstract interface; - Polished a little bit the setSource()/start()/stop() semantics, now setSource() is mandatory before ANY call to start(). * G-API-NG/Streaming: Fix STANDALONE build (errors brought by render)
232 lines
8.1 KiB
C++
232 lines
8.1 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
//
|
|
// Copyright (C) 2018 Intel Corporation
|
|
|
|
|
|
#ifndef OPENCV_GAPI_GSTREAMING_COMPILED_HPP
|
|
#define OPENCV_GAPI_GSTREAMING_COMPILED_HPP
|
|
|
|
#include <vector>
|
|
|
|
#include <opencv2/gapi/opencv_includes.hpp>
|
|
#include <opencv2/gapi/own/assert.hpp>
|
|
#include <opencv2/gapi/garg.hpp>
|
|
#include <opencv2/gapi/streaming/source.hpp>
|
|
|
|
namespace cv {
|
|
|
|
/**
|
|
* \addtogroup gapi_main_classes
|
|
* @{
|
|
*/
|
|
/**
|
|
* @brief Represents a computation (graph) compiled for streaming.
|
|
*
|
|
* This class represents a product of graph compilation (calling
|
|
* cv::GComputation::compileStreaming()). Objects of this class
|
|
* actually do stream processing, and the whole pipeline execution
|
|
* complexity is incapsulated into objects of this class. Execution
|
|
* model has two levels: at the very top, the execution of a
|
|
* heterogeneous graph is aggressively pipelined; at the very bottom
|
|
* the execution of every internal block is determined by its
|
|
* associated backend. Backends are selected based on kernel packages
|
|
* passed via compilation arguments ( see @ref gapi_compile_args,
|
|
* GNetworkPackage, GKernelPackage for details).
|
|
*
|
|
* GStreamingCompiled objects have a "player" semantics -- there are
|
|
* methods like start() and stop(). GStreamingCompiled has a full
|
|
* control over a videostream and so is stateful. You need to specify the
|
|
* input stream data using setSource() and then call start() to
|
|
* actually start processing. After that, use pull() or try_pull() to
|
|
* obtain next processed data frame from the graph in a blocking or
|
|
* non-blocking way, respectively.
|
|
*
|
|
* Currently a single GStreamingCompiled can process only one video
|
|
* streat at time. Produce multiple GStreamingCompiled objects to run the
|
|
* same graph on multiple video streams.
|
|
*
|
|
* @sa GCompiled
|
|
*/
|
|
class GAPI_EXPORTS GStreamingCompiled
|
|
{
|
|
public:
|
|
class GAPI_EXPORTS Priv;
|
|
GStreamingCompiled();
|
|
|
|
// FIXME: More overloads?
|
|
/**
|
|
* @brief Specify the input data to GStreamingCompiled for
|
|
* processing, a generic version.
|
|
*
|
|
* Use gin() to create an input parameter vector.
|
|
*
|
|
* Input vectors must have the same number of elements as defined
|
|
* in the cv::GComputation protocol (at the moment of its
|
|
* construction). Shapes of elements also must conform to protocol
|
|
* (e.g. cv::Mat needs to be passed where cv::GMat has been
|
|
* declared as input, and so on). Run-time exception is generated
|
|
* on type mismatch.
|
|
*
|
|
* In contrast with regular GCompiled, user can also pass an
|
|
* object of type GVideoCapture for a GMat parameter of the parent
|
|
* GComputation. The compiled pipeline will start fetching data
|
|
* from that GVideoCapture and feeding it into the
|
|
* pipeline. Pipeline stops when a GVideoCapture marks end of the
|
|
* stream (or when stop() is called).
|
|
*
|
|
* Passing a regular Mat for a GMat parameter makes it "infinite"
|
|
* source -- pipeline may run forever feeding with this Mat until
|
|
* stopped explicitly.
|
|
*
|
|
* Currently only a single GVideoCapture is supported as input. If
|
|
* the parent GComputation is declared with multiple input GMat's,
|
|
* one of those can be specified as GVideoCapture but all others
|
|
* must be regular Mat objects.
|
|
*
|
|
* Throws if pipeline is already running. Use stop() and then
|
|
* setSource() to run the graph on a new video stream.
|
|
*
|
|
* @note This method is not thread-safe (with respect to the user
|
|
* side) at the moment. Protect the access if
|
|
* start()/stop()/setSource() may be called on the same object in
|
|
* multiple threads in your application.
|
|
*
|
|
* @param ins vector of inputs to process.
|
|
* @sa gin
|
|
*/
|
|
void setSource(GRunArgs &&ins);
|
|
|
|
/**
|
|
* @brief Specify an input video stream for a single-input
|
|
* computation pipeline.
|
|
*
|
|
* Throws if pipeline is already running. Use stop() and then
|
|
* setSource() to run the graph on a new video stream.
|
|
*
|
|
* @overload
|
|
* @param s a shared pointer to IStreamSource representing the
|
|
* input video stream.
|
|
*/
|
|
void setSource(const gapi::wip::IStreamSource::Ptr& s);
|
|
|
|
/**
|
|
* @brief Start the pipeline execution.
|
|
*
|
|
* Use pull()/try_pull() to obtain data. Throws an exception if
|
|
* a video source was not specified.
|
|
*
|
|
* setSource() must be called first, even if the pipeline has been
|
|
* working already and then stopped (explicitly via stop() or due
|
|
* stream completion)
|
|
*
|
|
* @note This method is not thread-safe (with respect to the user
|
|
* side) at the moment. Protect the access if
|
|
* start()/stop()/setSource() may be called on the same object in
|
|
* multiple threads in your application.
|
|
*/
|
|
void start();
|
|
|
|
/**
|
|
* @brief Get the next processed frame from the pipeline.
|
|
*
|
|
* Use gout() to create an output parameter vector.
|
|
*
|
|
* Output vectors must have the same number of elements as defined
|
|
* in the cv::GComputation protocol (at the moment of its
|
|
* construction). Shapes of elements also must conform to protocol
|
|
* (e.g. cv::Mat needs to be passed where cv::GMat has been
|
|
* declared as output, and so on). Run-time exception is generated
|
|
* on type mismatch.
|
|
*
|
|
* This method writes new data into objects passed via output
|
|
* vector. If there is no data ready yet, this method blocks. Use
|
|
* try_pull() if you need a non-blocking version.
|
|
*
|
|
* @param outs vector of output parameters to obtain.
|
|
* @return true if next result has been obtained,
|
|
* false marks end of the stream.
|
|
*/
|
|
bool pull(cv::GRunArgsP &&outs);
|
|
|
|
/**
|
|
* @brief Try to get the next processed frame from the pipeline.
|
|
*
|
|
* Use gout() to create an output parameter vector.
|
|
*
|
|
* This method writes new data into objects passed via output
|
|
* vector. If there is no data ready yet, the output vector
|
|
* remains unchanged and false is returned.
|
|
*
|
|
* @return true if data has been obtained, and false if it was
|
|
* not. Note: false here doesn't mark the end of the stream.
|
|
*/
|
|
bool try_pull(cv::GRunArgsP &&outs);
|
|
|
|
/**
|
|
* @brief Stop (abort) processing the pipeline.
|
|
*
|
|
* Note - it is not pause but a complete stop. Calling start()
|
|
* will cause G-API to start processing the stream from the early beginning.
|
|
*
|
|
* Throws if the pipeline is not running.
|
|
*/
|
|
void stop();
|
|
|
|
/**
|
|
* @brief Test if the pipeline is running.
|
|
*
|
|
* @note This method is not thread-safe (with respect to the user
|
|
* side) at the moment. Protect the access if
|
|
* start()/stop()/setSource() may be called on the same object in
|
|
* multiple threads in your application.
|
|
*
|
|
* @return true if the current stream is not over yet.
|
|
*/
|
|
bool running() const;
|
|
|
|
/// @private
|
|
Priv& priv();
|
|
|
|
/**
|
|
* @brief Check if compiled object is valid (non-empty)
|
|
*
|
|
* @return true if the object is runnable (valid), false otherwise
|
|
*/
|
|
explicit operator bool () const;
|
|
|
|
/**
|
|
* @brief Vector of metadata this graph was compiled for.
|
|
*
|
|
* @return Unless _reshape_ is not supported, return value is the
|
|
* same vector which was passed to cv::GComputation::compile() to
|
|
* produce this compiled object. Otherwise, it is the latest
|
|
* metadata vector passed to reshape() (if that call was
|
|
* successful).
|
|
*/
|
|
const GMetaArgs& metas() const; // Meta passed to compile()
|
|
|
|
/**
|
|
* @brief Vector of metadata descriptions of graph outputs
|
|
*
|
|
* @return vector with formats/resolutions of graph's output
|
|
* objects, auto-inferred from input metadata vector by
|
|
* operations which form this computation.
|
|
*
|
|
* @note GCompiled objects produced from the same
|
|
* cv::GComputiation graph with different input metas may return
|
|
* different values in this vector.
|
|
*/
|
|
const GMetaArgs& outMetas() const;
|
|
|
|
protected:
|
|
/// @private
|
|
std::shared_ptr<Priv> m_priv;
|
|
};
|
|
/** @} */
|
|
|
|
}
|
|
|
|
#endif // OPENCV_GAPI_GSTREAMING_COMPILED_HPP
|