8 //http://docs.opencv.org/doc/tutorials/highgui/video-input-psnr-ssim/video-input-psnr-ssim.html
10 /*----------------------------------------------------------------------*\
12 \*---------------------------------------------------------------------*/
14 /*--------------------------------------*\
16 \*-------------------------------------*/
18 /*--------------------------------------*\
20 \*-------------------------------------*/
22 /*----------------------------------------------------------------------*\
24 \*---------------------------------------------------------------------*/
26 /*--------------------------------------*\
28 \*-------------------------------------*/
30 /*------------------*\
37 * Use pinned memory in host side
38 * Give this area to openCV
40 * size_t sizeOctets=w*h*sizeof(uchar4);
41 * uchar4* ptrHostMemory;
42 * HANDLE_ERROR( cudaHostAlloc ((void**) &ptrHostMemory, sizeOctets,cudaHostAllocDefault ) );
45 * CaptureVideo captureur(pathToVideo, titre);
46 * Mat matImage=captureur.capturer(); // capture une image seulement ( à utiliser en boucle!)
47 * uchar4* image= CaptureVideo::castToUChar4(&matImage); // format cuda
49 Capture_A::Capture_A(VideoCapture
* ptrCaptureStream
, const string
& title
, uchar4
* ptrHostMemory
):chrono()
51 // cout << "[Capture_A] : Capture_A" << endl;
54 this->compteurCapture
= 0;
55 this->ptrCaptureStream
= ptrCaptureStream
;
57 this->w
= (int) ptrCaptureStream
->get(CV_CAP_PROP_FRAME_WIDTH
);
58 this->h
= (int) ptrCaptureStream
->get(CV_CAP_PROP_FRAME_HEIGHT
);
62 if(ptrHostMemory
!=NULL
)
64 matCaptureSrc
=Mat(w
,h
,CV_BGR2RGBA
,ptrHostMemory
); // Ecrase ancienne
68 Capture_A::~Capture_A(void)
70 if (ptrCaptureStream
!= NULL
)
72 delete ptrCaptureStream
;
73 ptrCaptureStream
= NULL
;
77 /*------------------*\
81 Mat
Capture_A::capturer(void)
83 //cout << "[Capture_A] : capturer" << endl;
87 //(*ptrCaptureStream) >> matCaptureSrc; // plante en fin de video
88 readStream(this->ptrCaptureStream
, &this->matCaptureSrc
); // methode virtuelle : au lieu de ci-dessous, plus robuste
98 // CV_8U CV_ => BVRA et non RVBA => demande correction TODO Mieux?
100 // int nbChannel = 4; // 0 keep same chanel // 4 permet par exemple d'ajouter la couche alpha à rvb (pour une video ou webcam)
101 // cvtColor(matCaptureSrc, matCaptureDest, CV_8U, nbChannel);
106 // http://siggiorn.com/wp-content/uploads/libraries/opencv-java/docs/sj/opencv/Constants.ColorConversion.html
107 //int colorConversion=CV_BGR2GRAY; // ok
108 //int colorConversion=CV_BGR2RGBA ; // ko
109 int colorConversion
= CV_BGR2BGRA
; // ok
110 cvtColor(matCaptureSrc
, matCaptureDest
, colorConversion
);
113 return matCaptureDest
; //castToUChar4(matCapture.data);
116 void Capture_A::printInfo(void)
118 cout
<< "[Capture_A] : Capture Info :" << endl
;
119 cout
<< "\t(w,h) = (" << w
<< "," << h
<< ")" << endl
;
120 cout
<< "\ttitle = " << title
<< endl
;
121 cout
<< "\tnbChannel = " << matCaptureSrc
.channels() << endl
;
122 cout
<< "\ttype = " << matCaptureSrc
.type() << endl
;
123 cout
<< "\tisEmpty = " << matCaptureSrc
.empty() << endl
;
124 cout
<< "\tdtMS(source) = " << dtOriginalMS() << endl
;
126 if (compteurCapture
>= 2)
128 cout
<< "\tfps(capture) = " << fpsCapture() << endl
;
131 cout
<< "\tchrono = " << chrono
.timeFlight() << " (s)"<< endl
;
132 cout
<< "\t#image = " << compteurCapture
<< endl
;
135 int Capture_A::nbOctetImage()
137 return w
* h
* sizeof(uchar4
);
140 int Capture_A::fpsCapture()
142 double timeS
= chrono
.timeFlight();
143 double fps
= compteurCapture
/ timeS
;
148 /*------------------*\
150 \*-----------------*/
152 bool Capture_A::isOpened(void)
154 return ptrCaptureStream
->isOpened();
157 /*------------------*\
159 \*-----------------*/
161 VideoCapture
* Capture_A::getVideoCapture()
163 return ptrCaptureStream
;
166 int Capture_A::getW(void)
171 int Capture_A::getH(void)
176 int Capture_A::dtOriginalMS()
181 long Capture_A::nbCapture()
183 return compteurCapture
;
186 string
Capture_A::getTitle()
191 Chronos
Capture_A::getChronos()
196 /*--------------------------------------*\
198 \*-------------------------------------*/
201 * uchar = unsigned char
202 * uchar4 = 4 char sequentiel
204 uchar4
* Capture_A::castToUChar4(uchar
* ptrTab
)
206 return (uchar4
*) ptrTab
;
210 * uchar = unsigned char
211 * uchar4 = 4 char sequentiel
213 uchar4
* Capture_A::castToUChar4(Mat
* ptrMap
)
215 return castToUChar4(ptrMap
->data
);
218 /*--------------------------------------*\
220 \*-------------------------------------*/
222 // http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html#cv-videocapture-get
223 // TODO: fixme marche pas trop bien
224 // capture.set(CV_CAP_PROP_FRAME_WIDTH,1280);
225 // capture.set(CV_CAP_PROP_FRAME_HEIGHT ,720);
226 //capture.set(CV_CAP_PROP_EXPOSURE,0);
227 // int n = matCapture.rows;
228 // int m = matCapture.cols;
230 //uchar* ptr=matCapture.data;
231 // unsigned char* ptr4=(unsigned char*)ptr;
232 // cout<<"size uchar = "<<sizeof(uchar)<<endl;
233 // cout<<"size unsigned char = "<<sizeof(unsigned char)<<endl;
234 // cout<<"size uchar4 = "<<sizeof(uchar4)<<endl;
235 // cout<<"n= "<<n<<endl;
236 // cout<<"m= "<<m<<endl;
237 // uchar* ptrCopy=new uchar[n*m];
238 // uchar* ptrAgain=ptrCopy;
239 // for(int i=1;i<=n*m*4;i++)
243 //cout<<"i"<<i<<endl;
249 //// //*ptrCopy=*ptr4;
253 //// //*ptrCopy=*ptr4;
257 //// //*ptrCopy=*ptr4;
266 //// for(int i=1;i<=n*m;i++)
268 //// //cout<<"i"<<i<<"\t";
269 //// assert(ptr[i-1]==ptrAgain[i-1]);
272 // CV_16U : [0,65535]
273 // CV_32F : [0,1] in R
274 //cvtColor(matCapture, matCapture, CV_8U,0); // 0 keep same chanel
275 // cvtColor(matCapture, matCapture, CV_8U,4); // 0 keep same chanel // 4 permet par exemple d'ajouter la couche alpha à rvb (pour une video ou webcam)
276 /*----------------------------------------------------------------------*\
278 \*---------------------------------------------------------------------*/