Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / BilatTools_OpenCV / src / core / viewer / sequence / SequenceViewerCV.cpp
1 #include "SequenceViewerCV.h"
2 #include "ImageViewerCV.h"
3 #include <iostream>
4 #include <omp.h>
5
6 using std::cout;
7 using std::endl;
8
9 /*----------------------------------------------------------------------*\
10 |* Declaration *|
11 \*---------------------------------------------------------------------*/
12
13 /*--------------------------------------*\
14 |* Public *|
15 \*-------------------------------------*/
16
17 /*--------------------------------------*\
18 |* Private *|
19 \*-------------------------------------*/
20
21 /*----------------------------------------------------------------------*\
22 |* Implementation *|
23 \*---------------------------------------------------------------------*/
24
25 /*--------------------------------------*\
26 |* Public *|
27 \*-------------------------------------*/
28
29 SequenceVieverCV::SequenceVieverCV(Capture_A* ptrCaptureur)
30 {
31 cout<<"[SequenceViever] : SequenceViever"<<endl;
32 this->ptrCaptureur = ptrCaptureur;
33 this->isStart = false;
34 }
35
36 SequenceVieverCV::~SequenceVieverCV(void)
37 {
38 // rien
39 }
40
41 void SequenceVieverCV::run()
42 {
43 cout<<"[SequenceViever] : run"<<endl;
44
45 if (!isStart)
46 {
47 isStart = true;
48
49 Mat image = ptrCaptureur->capturer();
50 ptrCaptureur->printInfo();
51
52 string titleFrame = ptrCaptureur->getTitle() + "[q to quit]";
53 ImageVieverCV imageViever(titleFrame);
54
55 Chronos chrono;
56 char key = 'a'; //disons
57 while (key != 'q')
58 {
59 imageViever.show(&image);
60 image = ptrCaptureur->capturer();
61
62 int timetoWaitYetMS = timeToWaitMS(&chrono); // FIXME
63 key = cvWaitKey(max(1, timetoWaitYetMS)); // attention 1 min, pour respecter cadence original
64
65 if (ptrCaptureur->nbCapture() % 60 == 0) //disons
66 {
67 cout << "[SequenceViewer] : fps = " << ptrCaptureur->fpsCapture() << endl;
68 // ptrCaptureur->printInfo();
69 }
70 }
71
72 isStart = false;
73 }
74 }
75
76 int SequenceVieverCV::fps()
77 {
78 return ptrCaptureur->fpsCapture();
79 }
80
81 /*--------------------------------------*\
82 |* Private *|
83 \*-------------------------------------*/
84
85 int SequenceVieverCV::timeToWaitMS(Chronos* ptrChrono) // TODO BUG play trop vite why?
86 {
87 double timeElapseS = ptrChrono->stop();
88 ptrChrono->start();
89
90 int timeElapseMS = (int) (timeElapseS * 1000);
91 int timeToWaitTheoriqueMS = ptrCaptureur->dtOriginalMS();
92
93 int timetoWaitYetMS = timeToWaitTheoriqueMS - timeElapseMS;
94 timetoWaitYetMS = max(0, timetoWaitYetMS); // 0 si negatif
95
96 // debug
97 // {
98 // cout << endl;
99 // cout << "timeToWaitTheorique (MS) = " << timeToWaitTheoriqueMS << endl;
100 // cout << "timeElapse (MS) = " << timeElapseMS << endl;
101 // cout << "timetoWaitYet (MS) = " << timetoWaitYetMS << endl;
102 // cout << endl;
103 // }
104
105 return timetoWaitYetMS;
106 }
107
108 /*----------------------------------------------------------------------*\
109 |* End *|
110 \*---------------------------------------------------------------------*/
111