-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimageprocesser.cpp
63 lines (49 loc) · 1.93 KB
/
imageprocesser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
#include "imageprocesser.h"
ImageProcesser::ImageProcesser(cv::Size camsize)
{
SizeOfCamera = camsize;
IsFirst = true;
BSubLeft.set("nmixtures",3);
BSubLeft.set("detectShadows", false);
BSubRight.set("nmixtures",3);
BSubRight.set("detectShadows", false);
LeftROI = cv::Rect(0, 10, 110, 130);
RightROI = cv::Rect(250,0,102,130);
}
void ImageProcesser::setCamSize(cv::Size camsize)
{
SizeOfCamera = camsize;
}
int ImageProcesser::getMove(cv::Mat CapturedImage)
{
if(CapturedImage.empty()) {std::cout << "Baj van..." << std::endl; return 0;}
ProcessingTimer.start();
CapturedImage.copyTo(OutImage);
/*
*Cropping the hands
*/
LeftHand = OutImage(LeftROI);
//cv::imshow("LeftHand",LeftHand);
RightHand = OutImage(RightROI);
//cv::imshow("RightHand",RightHand);
/*
*Background subtraction
*/
//Left hand
BSubLeft.operator ()(LeftHand,ForeGroundLeft);
cv::GaussianBlur(ForeGroundLeft, ForeGroundLeft,cv::Size(9,9),5,5);
cv::threshold(ForeGroundLeft,ForeGroundLeft,100,255,cv::THRESH_BINARY);
cv::adaptiveThreshold(ForeGroundLeft,ForeGroundLeft,255,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,7,0.1);
// cv::imshow("Left",ForeGroundLeft);
//Right hand
BSubRight.operator ()(RightHand,ForeGroundRight);
cv::GaussianBlur(ForeGroundRight, ForeGroundRight,cv::Size(9,9),5,5);
cv::threshold(ForeGroundRight,ForeGroundRight,100,255,cv::THRESH_BINARY);
cv::adaptiveThreshold(ForeGroundRight,ForeGroundRight,255,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,7,0.1);
// cv::imshow("Right",ForeGroundRight);
// std::cerr << "Nonzero: " << cv::countNonZero(ForeGroundRight) << std::endl;
// std::cerr << "Elapsed processer time: "<< ProcessingTimer.elapsed() << " msec" <<std::endl;
if(14300 - cv::countNonZero(ForeGroundLeft) > 1000) return -1;
if(13260 - cv::countNonZero(ForeGroundRight) > 900) return 1;
return 0;
}