Signapse
PreProcessor.cpp
Go to the documentation of this file.
1#include <opencv2/opencv.hpp>
2#include <opencv2/imgproc.hpp>
3
4#include "PreProcessor.h"
5
11 cv::Size sz = scene.frame.size();
12 scene.regionOfInterest = BoundingBox((int)(sz.width * settings.relativeBoundingBox[0]),
13 (int)(sz.height * settings.relativeBoundingBox[1]),
14 (int)(sz.width * settings.relativeBoundingBox[2]),
15 (int)(sz.height * settings.relativeBoundingBox[3]));
16 Scene out = switchRGB2BGR(scene);
17 out = drawBox(scene);
18 if(!sceneCallback) return;
20}
26
31
37Scene PreProcessor::switchRGB2BGR(Scene s) {
38 cv::Mat temp = s.frame;
39 cv::cvtColor(temp, s.frame, cv::COLOR_BGR2RGB);
40 return s;
41}
42
43
49Scene PreProcessor::drawBox(Scene s) {
50 cv::Mat temp = s.frame;
52 int width = s.regionOfInterest.LowerRight.x - x;
53 int height = s.regionOfInterest.LowerRight.y - y;
54 cv::Rect rect(x, y, width, height);
55 cv::rectangle(temp, rect, cv::Scalar(0,255,0));
56 Scene ret = s;
57 s.frame = temp;
58 return s;
59}
60
68void PreProcessor::SetBoundingBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) {
69 settings.relativeBoundingBox[0] = upperLeftX;
70 settings.relativeBoundingBox[1] = upperLeftY;
71 settings.relativeBoundingBox[2] = lowerRightX;
72 settings.relativeBoundingBox[3] = lowerRightY;
73 for(int i = 0; i < 4; i++){
74 float val = settings.relativeBoundingBox[i];
75 if(val > 1.0f){
76 settings.relativeBoundingBox[i] = 1.0f;
77 }
78 else if (val < 0.0f){
79 settings.relativeBoundingBox[i] = 0.0f;
80 }
81 }
82}
void SetBoundingBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY)
void NextScene(Scene scene)
virtual void NextScene(Scene next)=0
Struct BoundingBox.
Definition: Scene.h:23
Point LowerRight
Definition: Scene.h:25
Point UpperLeft
Definition: Scene.h:24
int y
Definition: Scene.h:13
int x
Definition: Scene.h:13
Struct Scene.
Definition: Scene.h:36
cv::Mat frame
Member variable.
Definition: Scene.h:42
BoundingBox regionOfInterest
Member variable.
Definition: Scene.h:52