utility.h 3.05 KB
Newer Older
Matteo's avatar
update    
Matteo committed
1
2
3
4
5
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>

Nadir Dalla Pozza's avatar
Nadir Dalla Pozza committed
6
using namespace cv;
7
using namespace std;
8
namespace fs = std::filesystem;
9

Matteo's avatar
update    
Matteo committed
10
namespace utility {
Nadir Dalla Pozza's avatar
Nadir Dalla Pozza committed
11

Matteo's avatar
update    
Matteo committed
12
13
14
15
16
17
18
19
	class Frame : Mat {
	public:
		Frame() : Mat() {}
		Frame(const Mat& m) : Mat(m) {}
		Frame(const Frame& f) : Mat(f) {}
		Frame& operator=(const Mat& m) {
			Mat::operator=(m);
			return *this;
Nadir Dalla Pozza's avatar
Nadir Dalla Pozza committed
20
		}
Matteo's avatar
update    
Matteo committed
21
22
23
		Frame& operator=(const Frame& f) {
			Mat::operator=(f);
			return *this;
Nadir Dalla Pozza's avatar
Nadir Dalla Pozza committed
24
		}
Matteo's avatar
update    
Matteo committed
25
26
		Frame clone() const {
			return Frame(Mat::clone());
Nadir Dalla Pozza's avatar
Nadir Dalla Pozza committed
27
		}
Matteo's avatar
update    
Matteo committed
28
29
30
		Frame& downsample(int factor) {
			pyrDown(*this, *this, Size(size().width / factor, size().height / factor));
			return *this;
31
		}
Matteo's avatar
update    
Matteo committed
32
33
34
		Frame& convertColor(int code) {
			cv::cvtColor(*this, *this, code);
			return *this;
35
		}
Matteo's avatar
update    
Matteo committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	};

	/**
	 * @brief Detects a given shape in an image, using a the OpenCV algorithm GeneralizedHoughGuil.
	 *
	 * @param[in] alg the algorithm instance;
	 * @param[in] templateShape the shape to detect;
	 * @param[in] posThresh the position votes threshold;
	 * @param[out] positivePositions vector representing the position assigned to each found rectangle for positive angles;
	 * @param[out] positiveVotes vector representing the vote assigned to each found rectangle for positive angles;
	 * @param[out] negativePositions vector representing the position assigned to each found rectangle for negative angles;
	 * @param[out] negativeVotes vector representing the vote assigned to each found rectangle for negative angles;
	 * @param[in] processingArea the image to be processed.
	 */
	void detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh, vector<Vec4f> &positivePositions, Mat &positiveVotes, vector<Vec4f> &negativePositions, Mat &negativeVotes, Mat processingArea);

	/**
	 * @brief Draw rectangles on an image.
	 *
	 * @param frame Frame on which the rectangles will be drawn;
	 * @param positions The position of the rectangle;
	 * @param color The color of the rectangle;
	 * @param width The width of the rectangle;
	 * @param height The height of the rectangle;
	 * @param offsetX X offset on the position of the rectangle;
	 * @param offsetY Y offset on the position of the rectangle;
	 * @param processingScale Scaling factor, useful for downsizing.
	 * @return RotatedRect Object representing the drawn rectangle.
	 */
	RotatedRect drawShapes(Mat frame, Vec4f &positions, Scalar color, int width, int height, int offsetX, int offsetY, float processingScale);


	/**
	 * @brief Function to deinterlace the current image.
	 *
	 * @param[in] frame image to be processed;
	 * @param[out] odd_frame odd plane;
	 * @param[out] even_frame even plane.
	 */
	void separateFrame(cv::Mat frame, cv::Mat &odd_frame, cv::Mat &even_frame);


	/**
	 * @brief Compute the number of different pixels between two frames.
	 *
	 * @param prevFrame the first frame;
	 * @param currentFrame the second frame.
	 * @return cv::Mat A black and white frame, where black pixels represent a difference, while white pixels represent an equality.
	 */
	cv::Mat difference(cv::Mat &prevFrame, cv::Mat &currentFrame);
86
87

}