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
| #include <iostream>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
#define PI 3,14159265
int main(int argc, char** argv)
{
//déclaration de plusieurs variables utiles
//la capture vidéo
VideoCapture cap;
cap.open(0);
char key = 'a';
//les images
Mat image;
Mat fond;
Mat diff;
//les fenêtres
namedWindow("Projet - image",CV_WINDOW_AUTOSIZE);
namedWindow("Projet - fond",CV_WINDOW_AUTOSIZE);
namedWindow("Projet - travail",CV_WINDOW_AUTOSIZE);
//boucle pour permettre la mise au point de l'objectif
for(int i=0; i<10; i++)
cap >> fond;
flip(fond,fond,1);
while(key != 'Q' && key != 'q' && key != 27)
{
//on prend l'image de la webcam
cap >> image;
flip(image,image,1);
//on compare les deux images
compare(fond,image,diff,CMP_NE);
//affichage
imshow("Projet - image",image);
imshow("Projet - travail",diff);
imshow("Projet - fond",fond);
//tempo
key = waitKey(10);
}
return 0;
} |
Partager