#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0);
if(!cap.isOpened())
{
cerr << "Unable to open the webcam. Exiting!" << endl;
return -1;
}
Mat frame, hsvImage, mask, outputImage;
char ch;
float scalingFactor = 0.75;
while(true)
{
outputImage = Scalar(0,0,0);
cap >> frame;
if(frame.empty())
break;
resize(frame, frame, Size(), scalingFactor, scalingFactor, INTER_AREA);
cvtColor(frame, hsvImage, COLOR_BGR2HSV);
Scalar lowerLimit = Scalar(60,100,100);
Scalar upperLimit = Scalar(180,255,255);
inRange(hsvImage, lowerLimit, upperLimit, mask);
bitwise_and(frame, frame, outputImage, mask=mask);
medianBlur(outputImage, outputImage, 5);
imshow("Input", frame);
imshow("Output", outputImage);
ch = waitKey(30);
if (ch == 27) {
break;
}
}
return 0;
}