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
| int main()
{
int lowH = 40; //couleur verte
int highH = 70;
int lowS = 230;
int highS = 255;
int lowV = 230; //brillance de la lumiere
int highV = 255;
int tolerance = 10;
Mat inputFrame, hsvFrame, outputFrame;
VideoCapture camCapture(0); // on recupere le flux vidéo de ma webcam
cvNamedWindow("Stream cam input", CV_WINDOW_NORMAL);
cvNamedWindow("Stream cam hsv", CV_WINDOW_NORMAL);
cvNamedWindow("Stream cam output", CV_WINDOW_NORMAL);
if (!camCapture.isOpened()) std::cout << "error cam stream" << std::endl;
while (1)
{
camCapture.read(inputFrame); // je recupere une image du flux de ma cam
cvtColor(inputFrame, hsvFrame, CV_BGR2HSV); //je convertie en HSV pour limiter les variations de couleur avec les variations de lumiere
cv::inRange(hsvFrame, cv::Scalar(lowH - tolerance, lowS - tolerance, lowV), cv::Scalar(highH + tolerance, highS + tolerance, highV), outputFrame);
keyboard = waitKey(30);
if (keyboard == 27) break;
imshow("Stream cam input", inputFrame);
imshow("Stream cam hsv", hsvFrame);
imshow("Stream cam output", outputFrame);
}
cvDestroyWindow("Stream cam input");
cvDestroyWindow("Stream cam hsv");
cvDestroyWindow("Stream cam output");
} |
Partager