#ifndef FIFO_HPP #define FIFO_HPP #include #include #include /** * @class Fifo * * The purpose of this class is to create a templatized * software fifo that has blocking read/pop functionality * *...

1 answer below »
It should run on Centos Linux.Need it within 28 hours please.It is very urgent.Pseudocode and comments should be added.C++ codeMakefile should be included.



#ifndef FIFO_HPP #define FIFO_HPP #include #include #include /** * @class Fifo * * The purpose of this class is to create a templatized * software fifo that has blocking read/pop functionality * * Arbitrary objects can be placed in the FIFO in a thread safe * manner. They can also be removed in a thread safe way, and if * the fifo is empty, the pop will block until it has something to return * * The Fifo should function in a "by value" way. I.E. when items are added, * they are copied into the fifo. When they are popped, the item that is * popped is used to populate the passed in by ref object */ template class Fifo { public: /** * @brief Add Item to fifo * * @param item Object to be copied into FIFO */ void addItem(const T &item); /** * @brief Pop item from fifo * * @param item Object to be populated with the value * of the object being removed from the fifo */ void popItem(T &item); private: /** @brief Used to track/contain FIFO contents */ std::list m_items; /** @brief Needed to protect list and for use by m_cv */ std::mutex m_mtx; /** @brief Used to manage sleeping until FIFO not emtpy */ std::condition_variable m_cv; }; #endif /* FIFO_HPP */ LINKFLAGS = -pthread -lopencv_highgui -lopencv_imgproc -lopencv_core Programming Exercise #5 (Threading in C++) Overview In this programming exercise the coder will construct a pipeline of threads which process a video file. Each of these threads will accept an image matrix (one frame of the video), perform some transform on the image, pass it to the next pipeline stage, and then display the image at that stage of the pipeline, (one graphical window at each pipeline stage). The library package this PEX will utilize is called OpenCV (Open Computer Vision). It is a highly capable open source package, and this PEX merely scratches the surface of its functionality. Should this area of study interest you, further exploration will be rewarding. At the conclusion of this exercise, the coder will have completed a tool that will display a video in its original form in one window, a second window will show the video in black and white, and a third window will show the video after an edge detection algorithm has been executed. All windows will display simultaneously. Video Processing Architecture In this exercise, the coder will first construct a thread safe FIFO template class. This will allow the coder to pass arbitrary objects to other threads safely. Students should base their object FIFO template class on the well documented partial header provided in this package (i.e. Fifo.hpp). Remember that template method implementations must be included in the header because templates are always a compile time type of polymorphism. Therefore, students will have to add implementations to the header file, but they should not change the template class definition. The second phase of the exercise is to create the Transformer base class. The right most three threads in the figure 1 diagram inherit from this base class due to the common functionality. Each of them read a frame from the inbound FIFO. Then they execute a transform on the image and write it to the output FIFO. Finally, they display the image to a graphical window. The only difference between each of the threads is the action accomplished by the transform function. A well-documented header for this class has been provided as part of this PEX package. Read the in-line documentation closely; there are many hints contained there. Students should implement the Transformer base class with no modifications to the provided header. Next, the coder needs to implement three derived classes which inherit functionality from the Transformer class. The first does nothing, the second converts the image to black and white, and the last does a Canny image detection algorithm. For this piece, the code will have to look at documentation and examples for the OpenCV package. OpenCV provides function for both color conversion and edge detection. Students are encouraged to use these functions for their first attempt at this exercise. Once the PEX functions well with the provided functions, students may choose to write their own color conversion and edge detection algorithms (google Sobel edge detection). Extra credit will be awarded for self-implemented transform algorithms. Finally, students must create a main function to instantiate the correct objects, (Fifos and Transformers), and connect them together correctly. The coder must open a video file, read a number of frames, pass them through the pipeline, wait for all processing to complete, and then cleanly end the process/threads. It is this piece of code that must create an executable callback object that the Tranformer classes will use to display the frames. The imshow and waitKey OpenCV function do not appear to be thread safe. Make sure that you ensure only one thread is executing these particular API calls at any given time. Figure 1. Video Processing Architecture Programming Concepts This exercise covers many programming concepts including threads, reference counting pointers, templates, STL library, mutexes, condition variables, abstract classes and inheritance, dynamic linking, lambdas, closures, functors, and introductory computer vision. System Requirements The design must use the provided headers verbatim. This will allow automated testing of the design you produce. See grading rubric for specific system requirements and associated grade values. Grading Rubric attached below Grading Rubric Requirement / Criteria Available Points Student’s Score Correctly implemented thread safe FIFO template 20 Transformer correctly implements two constructors (The last pipeline stage has no output) 10 Transformer constructor starts the process thread 10 Transformer correctly reads/tranforms/writes/displays 10 Transformer wait functionality is correct 10 NOP transform function/class is correct 10 Black and white transform function/class is correct 10 Canny edge detect is correct 20 Main correctly instantiates and connects objects 20 Main correctly creates and passes display callback to Transform objects 10 Main correct displays frames and protects OpenCV API calls 10 Student implemented black/white transform 20 Student implemented edge detect algorithm 40 Total 140 · There should be three output videos: color, black and white, canny edge. · Should run on Centos Linux #ifndef TRANSFORMER_HPP #define TRANSFORMER_HPP //Stuff we wrote #include "Fifo.hpp" //library stuff #include #include #include #include #include #include /** * @class Transformer * * This class is an abstract base class that handles a number of frames. * Using a pipeline of classes derived from this abstract base class * allows the coder to start with an arbitrary video, modify it * frame by frame, and then display the modified frame at each step * in the pipeline. * * 1. Spawns a thread which: * a. Reads from the input fifo * b. Transforms the input image * c. Passes the transformed image to the next pipeline stage * d. displays the image * * 2. Has a callback to "display" the image * * 3. Proveds a wait method to block until all frames are handled */ class Transformer { public: /** * @brief Constructor * * The constructor accepts and stores references to the input and output * frame fifos. * * @param inFifo Input frame FIFO * @param outFifo Output frame FIFO * @param displayFunc Callback to display the modified frame * @param frameCount How many frames the thread should process before * exiting */ Transformer(Fifo<> > &inFifo, Fifo<> > &outFifo, std::function<>)> displayFunc, uint32_t frameCount); /** * @brief Constructor * * This constructor is the same as the first, but it is used in the case * that this trasformer is the last in the pipeline, (i.e. it has no * output fifo) * * @param inFifo Input frame FIFO * @param displayFunc Callback to display the modified frame * @param frameCount How many frames the thread should process before * exiting */ Transformer(Fifo<> > &inFifo, std::function<>)> displayFunc, uint32_t frameCount); /** * @brief Wait for thread * * This function should wait for the thread; join it. It * will be called from the main thread to block until this transformer * processes the correct number of frames */ void wait(); private: /** * @brief Process frames * * This function will process a number of frames by: * 1. Reading a frame from the input * 2. Transforming the frame * 3. Writing the frame to the next pipeline stage (if not last stage) * 4. Display the transformed frame by calling the display callback * * @Note: This is the function that needs to run as a thread; I would * suggest spawning it in the constructor of this object * * @param frameCount How many frames to process before exiting */ void process(uint32_t frameCount); /** * @brief Transform the image/frame * * This is an abstract function that will transform the
Answered Same DayDec 07, 2021

Answer To: #ifndef FIFO_HPP #define FIFO_HPP #include #include #include /** * @class Fifo * * The purpose of...

Aditi answered on Dec 08 2021
151 Votes
fifo.hpp
#ifndef FIFO_HPP
#define FIFO_HPP
#include
#include
#include
/**
* @class Fifo
*
* The purpose of this class is to create a templatized

* software fifo that has blocking read/pop functionality
*
* Arbitrary objects can be placed in the FIFO in a thread safe
* manner. They can also be removed in a thread safe way, and if
* the fifo is empty, the pop will block until it has something to return
*
* The Fifo should function in a "by value" way. I.E. when items are added,
* they are copied into the fifo. When they are popped, the item that is
* popped is used to populate the passed in by ref object
*/
template
class Fifo
{
public:
/**
* @brief Add Item to fifo
*
* @param item Object to be copied into FIFO
*/
void addItem(const T &item){
    m_items.push_back(item);
}
/**
* @brief Pop item from fifo
*
* @param item Object to be populated with the value
* of the object being removed from the fifo
*/
void popItem(T &item){
    if(!m_items.empty()){
        item = m_items.front();
        m_items.pop_front();
    }
}
private:
/** @brief Used to track/contain FIFO contents */
std::list m_items;
/** @brief Needed to protect list and for use by m_cv */
std::mutex m_mtx;
/** @brief Used to manage sleeping until FIFO not emtpy */
std::condition_variable m_cv;
};
#endif /* FIFO_HPP */
makefile.link
LINKFLAGS = -pthread -lopencv_highgui -lopencv_imgproc -lopencv_core
transformer.hpp
#ifndef TRANSFORMER_HPP
#define TRANSFORMER_HPP
//Stuff we wrote
#include "Fifo.hpp"
//library stuff
#include
#include
#include
#include
#include
#include
/**
* @class Transformer
*
* This class is an abstract base class that handles a number of...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here