Merge branch 'bgfg-gmg-gpu' into bgfg-gmg-merged
[profile/ivi/opencv.git] / modules / gpu / perf / perf_video.cpp
1 #include "perf_precomp.hpp"\r
2 \r
3 #ifdef HAVE_CUDA\r
4 \r
5 //////////////////////////////////////////////////////\r
6 // BroxOpticalFlow\r
7 \r
8 GPU_PERF_TEST_1(BroxOpticalFlow, cv::gpu::DeviceInfo)\r
9 {\r
10     cv::gpu::DeviceInfo devInfo = GetParam();\r
11     cv::gpu::setDevice(devInfo.deviceID());\r
12 \r
13     cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);\r
14     ASSERT_FALSE(frame0_host.empty());\r
15 \r
16     cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE);\r
17     ASSERT_FALSE(frame1_host.empty());\r
18 \r
19     frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0);\r
20     frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0);\r
21 \r
22     cv::gpu::GpuMat frame0(frame0_host);\r
23     cv::gpu::GpuMat frame1(frame1_host);\r
24     cv::gpu::GpuMat u;\r
25     cv::gpu::GpuMat v;\r
26 \r
27     cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,\r
28                                     10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);\r
29 \r
30     d_flow(frame0, frame1, u, v);\r
31 \r
32     declare.time(10);\r
33 \r
34     TEST_CYCLE()\r
35     {\r
36         d_flow(frame0, frame1, u, v);\r
37     }\r
38 }\r
39 \r
40 INSTANTIATE_TEST_CASE_P(Video, BroxOpticalFlow, ALL_DEVICES);\r
41 \r
42 //////////////////////////////////////////////////////\r
43 // InterpolateFrames\r
44 \r
45 GPU_PERF_TEST_1(InterpolateFrames, cv::gpu::DeviceInfo)\r
46 {\r
47     cv::gpu::DeviceInfo devInfo = GetParam();\r
48     cv::gpu::setDevice(devInfo.deviceID());\r
49 \r
50     cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);\r
51     ASSERT_FALSE(frame0_host.empty());\r
52 \r
53     cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE);\r
54     ASSERT_FALSE(frame1_host.empty());\r
55 \r
56     frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0);\r
57     frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0);\r
58 \r
59     cv::gpu::GpuMat frame0(frame0_host);\r
60     cv::gpu::GpuMat frame1(frame1_host);\r
61     cv::gpu::GpuMat fu, fv;\r
62     cv::gpu::GpuMat bu, bv;\r
63 \r
64     cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,\r
65                                     10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);\r
66 \r
67     d_flow(frame0, frame1, fu, fv);\r
68     d_flow(frame1, frame0, bu, bv);\r
69 \r
70     cv::gpu::GpuMat newFrame;\r
71     cv::gpu::GpuMat buf;\r
72 \r
73     cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf);\r
74 \r
75     TEST_CYCLE()\r
76     {\r
77         cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf);\r
78     }\r
79 }\r
80 \r
81 INSTANTIATE_TEST_CASE_P(Video, InterpolateFrames, ALL_DEVICES);\r
82 \r
83 //////////////////////////////////////////////////////\r
84 // CreateOpticalFlowNeedleMap\r
85 \r
86 GPU_PERF_TEST_1(CreateOpticalFlowNeedleMap, cv::gpu::DeviceInfo)\r
87 {\r
88     cv::gpu::DeviceInfo devInfo = GetParam();\r
89     cv::gpu::setDevice(devInfo.deviceID());\r
90 \r
91     cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);\r
92     ASSERT_FALSE(frame0_host.empty());\r
93 \r
94     cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE);\r
95     ASSERT_FALSE(frame1_host.empty());\r
96 \r
97     frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0);\r
98     frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0);\r
99 \r
100     cv::gpu::GpuMat frame0(frame0_host);\r
101     cv::gpu::GpuMat frame1(frame1_host);\r
102     cv::gpu::GpuMat u, v;\r
103 \r
104     cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,\r
105                                     10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);\r
106 \r
107     d_flow(frame0, frame1, u, v);\r
108 \r
109     cv::gpu::GpuMat vertex, colors;\r
110 \r
111     cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors);\r
112 \r
113     TEST_CYCLE()\r
114     {\r
115         cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors);\r
116     }\r
117 }\r
118 \r
119 INSTANTIATE_TEST_CASE_P(Video, CreateOpticalFlowNeedleMap, ALL_DEVICES);\r
120 \r
121 //////////////////////////////////////////////////////\r
122 // GoodFeaturesToTrack\r
123 \r
124 IMPLEMENT_PARAM_CLASS(MinDistance, double)\r
125 \r
126 GPU_PERF_TEST(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance)\r
127 {\r
128     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
129     cv::gpu::setDevice(devInfo.deviceID());\r
130 \r
131     double minDistance = GET_PARAM(1);\r
132 \r
133     cv::Mat image_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);\r
134     ASSERT_FALSE(image_host.empty());\r
135 \r
136     cv::gpu::GoodFeaturesToTrackDetector_GPU detector(8000, 0.01, minDistance);\r
137 \r
138     cv::gpu::GpuMat image(image_host);\r
139     cv::gpu::GpuMat pts;\r
140 \r
141     detector(image, pts);\r
142 \r
143     TEST_CYCLE()\r
144     {\r
145         detector(image, pts);\r
146     }\r
147 }\r
148 \r
149 INSTANTIATE_TEST_CASE_P(Video, GoodFeaturesToTrack, testing::Combine(\r
150     ALL_DEVICES,\r
151     testing::Values(MinDistance(0.0), MinDistance(3.0))));\r
152 \r
153 //////////////////////////////////////////////////////\r
154 // PyrLKOpticalFlowSparse\r
155 \r
156 IMPLEMENT_PARAM_CLASS(GraySource, bool)\r
157 IMPLEMENT_PARAM_CLASS(Points, int)\r
158 IMPLEMENT_PARAM_CLASS(WinSize, int)\r
159 IMPLEMENT_PARAM_CLASS(Levels, int)\r
160 IMPLEMENT_PARAM_CLASS(Iters, int)\r
161 \r
162 GPU_PERF_TEST(PyrLKOpticalFlowSparse, cv::gpu::DeviceInfo, GraySource, Points, WinSize, Levels, Iters)\r
163 {\r
164     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
165     cv::gpu::setDevice(devInfo.deviceID());\r
166 \r
167     bool useGray = GET_PARAM(1);\r
168     int points = GET_PARAM(2);\r
169     int winSize = GET_PARAM(3);\r
170     int levels = GET_PARAM(4);\r
171     int iters = GET_PARAM(5);\r
172 \r
173     cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);\r
174     ASSERT_FALSE(frame0_host.empty());\r
175 \r
176     cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);\r
177     ASSERT_FALSE(frame1_host.empty());\r
178 \r
179     cv::Mat gray_frame;\r
180     if (useGray)\r
181         gray_frame = frame0_host;\r
182     else\r
183         cv::cvtColor(frame0_host, gray_frame, cv::COLOR_BGR2GRAY);\r
184 \r
185     cv::gpu::GpuMat pts;\r
186 \r
187     cv::gpu::GoodFeaturesToTrackDetector_GPU detector(points, 0.01, 0.0);\r
188     detector(cv::gpu::GpuMat(gray_frame), pts);\r
189 \r
190     cv::gpu::PyrLKOpticalFlow pyrLK;\r
191     pyrLK.winSize = cv::Size(winSize, winSize);\r
192     pyrLK.maxLevel = levels - 1;\r
193     pyrLK.iters = iters;\r
194 \r
195     cv::gpu::GpuMat frame0(frame0_host);\r
196     cv::gpu::GpuMat frame1(frame1_host);\r
197     cv::gpu::GpuMat nextPts;\r
198     cv::gpu::GpuMat status;\r
199 \r
200     pyrLK.sparse(frame0, frame1, pts, nextPts, status);\r
201 \r
202     TEST_CYCLE()\r
203     {\r
204         pyrLK.sparse(frame0, frame1, pts, nextPts, status);\r
205     }\r
206 }\r
207 \r
208 INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowSparse, testing::Combine(\r
209     ALL_DEVICES,\r
210     testing::Values(GraySource(true), GraySource(false)),\r
211     testing::Values(Points(1000), Points(2000), Points(4000), Points(8000)),\r
212     testing::Values(WinSize(9), WinSize(13), WinSize(17), WinSize(21)),\r
213     testing::Values(Levels(1), Levels(2), Levels(3)),\r
214     testing::Values(Iters(1), Iters(10), Iters(30))));\r
215 \r
216 //////////////////////////////////////////////////////\r
217 // PyrLKOpticalFlowDense\r
218 \r
219 GPU_PERF_TEST(PyrLKOpticalFlowDense, cv::gpu::DeviceInfo, WinSize, Levels, Iters)\r
220 {\r
221     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
222     cv::gpu::setDevice(devInfo.deviceID());\r
223 \r
224     int winSize = GET_PARAM(1);\r
225     int levels = GET_PARAM(2);\r
226     int iters = GET_PARAM(3);\r
227 \r
228     cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);\r
229     ASSERT_FALSE(frame0_host.empty());\r
230 \r
231     cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE);\r
232     ASSERT_FALSE(frame1_host.empty());\r
233 \r
234     cv::gpu::GpuMat frame0(frame0_host);\r
235     cv::gpu::GpuMat frame1(frame1_host);\r
236     cv::gpu::GpuMat u;\r
237     cv::gpu::GpuMat v;\r
238 \r
239     cv::gpu::PyrLKOpticalFlow pyrLK;\r
240 \r
241     pyrLK.winSize = cv::Size(winSize, winSize);\r
242     pyrLK.maxLevel = levels - 1;\r
243     pyrLK.iters = iters;\r
244 \r
245     pyrLK.dense(frame0, frame1, u, v);\r
246 \r
247     declare.time(30);\r
248 \r
249     TEST_CYCLE()\r
250     {\r
251         pyrLK.dense(frame0, frame1, u, v);\r
252     }\r
253 }\r
254 \r
255 INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowDense, testing::Combine(\r
256     ALL_DEVICES,\r
257     testing::Values(WinSize(3), WinSize(5), WinSize(7), WinSize(9), WinSize(13), WinSize(17), WinSize(21)),\r
258     testing::Values(Levels(1), Levels(2), Levels(3)),\r
259     testing::Values(Iters(1), Iters(10))));\r
260 \r
261 //////////////////////////////////////////////////////\r
262 // FarnebackOpticalFlowTest\r
263 \r
264 GPU_PERF_TEST_1(FarnebackOpticalFlowTest, cv::gpu::DeviceInfo)\r
265 {\r
266     cv::gpu::DeviceInfo devInfo = GetParam();\r
267     cv::gpu::setDevice(devInfo.deviceID());\r
268 \r
269     cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);\r
270     ASSERT_FALSE(frame0_host.empty());\r
271 \r
272     cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE);\r
273     ASSERT_FALSE(frame1_host.empty());\r
274 \r
275     cv::gpu::GpuMat frame0(frame0_host);\r
276     cv::gpu::GpuMat frame1(frame1_host);\r
277     cv::gpu::GpuMat u;\r
278     cv::gpu::GpuMat v;\r
279 \r
280     cv::gpu::FarnebackOpticalFlow farneback;\r
281 \r
282     farneback(frame0, frame1, u, v);\r
283 \r
284     declare.time(10);\r
285 \r
286     TEST_CYCLE()\r
287     {\r
288         farneback(frame0, frame1, u, v);\r
289     }\r
290 }\r
291 \r
292 INSTANTIATE_TEST_CASE_P(Video, FarnebackOpticalFlowTest, ALL_DEVICES);\r
293 \r
294 //////////////////////////////////////////////////////\r
295 // FGDStatModel\r
296 \r
297 GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string)\r
298 {\r
299     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
300     cv::gpu::setDevice(devInfo.deviceID());\r
301 \r
302     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
303 \r
304     cv::VideoCapture cap(inputFile);\r
305     ASSERT_TRUE(cap.isOpened());\r
306 \r
307     cv::Mat frame;\r
308     cap >> frame;\r
309     ASSERT_FALSE(frame.empty());\r
310 \r
311     cv::gpu::GpuMat d_frame(frame);\r
312     cv::gpu::FGDStatModel d_model(4);\r
313     d_model.create(d_frame);\r
314 \r
315     declare.time(10);\r
316 \r
317     for (int i = 0; i < 10; ++i)\r
318     {\r
319         cap >> frame;\r
320         ASSERT_FALSE(frame.empty());\r
321 \r
322         d_frame.upload(frame);\r
323 \r
324         startTimer(); next();\r
325         d_model.update(d_frame);\r
326         stopTimer();\r
327     }\r
328 }\r
329 \r
330 INSTANTIATE_TEST_CASE_P(Video, FGDStatModel, testing::Combine(\r
331     ALL_DEVICES,\r
332     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));\r
333 \r
334 //////////////////////////////////////////////////////\r
335 // MOG\r
336 \r
337 IMPLEMENT_PARAM_CLASS(LearningRate, double)\r
338 \r
339 GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate)\r
340 {\r
341     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
342     cv::gpu::setDevice(devInfo.deviceID());\r
343 \r
344     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
345     int cn = GET_PARAM(2);\r
346     double learningRate = GET_PARAM(3);\r
347 \r
348     cv::VideoCapture cap(inputFile);\r
349     ASSERT_TRUE(cap.isOpened());\r
350 \r
351     cv::Mat frame;\r
352 \r
353     cv::gpu::GpuMat d_frame;\r
354     cv::gpu::MOG_GPU mog;\r
355     cv::gpu::GpuMat foreground;\r
356 \r
357     cap >> frame;\r
358     ASSERT_FALSE(frame.empty());\r
359 \r
360     if (cn != 3)\r
361     {\r
362         cv::Mat temp;\r
363         if (cn == 1)\r
364             cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
365         else\r
366             cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
367         cv::swap(temp, frame);\r
368     }\r
369 \r
370     d_frame.upload(frame);\r
371 \r
372     mog(d_frame, foreground, learningRate);\r
373 \r
374     for (int i = 0; i < 10; ++i)\r
375     {\r
376         cap >> frame;\r
377         ASSERT_FALSE(frame.empty());\r
378 \r
379         if (cn != 3)\r
380         {\r
381             cv::Mat temp;\r
382             if (cn == 1)\r
383                 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
384             else\r
385                 cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
386             cv::swap(temp, frame);\r
387         }\r
388 \r
389         d_frame.upload(frame);\r
390 \r
391         startTimer(); next();\r
392         mog(d_frame, foreground, learningRate);\r
393         stopTimer();\r
394     }\r
395 }\r
396 \r
397 INSTANTIATE_TEST_CASE_P(Video, MOG, testing::Combine(\r
398     ALL_DEVICES,\r
399     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),\r
400     testing::Values(Channels(1), Channels(3), Channels(4)),\r
401     testing::Values(LearningRate(0.0), LearningRate(0.01))));\r
402 \r
403 //////////////////////////////////////////////////////\r
404 // MOG2\r
405 \r
406 GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels)\r
407 {\r
408     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
409     cv::gpu::setDevice(devInfo.deviceID());\r
410 \r
411     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
412     int cn = GET_PARAM(2);\r
413 \r
414     cv::VideoCapture cap(inputFile);\r
415     ASSERT_TRUE(cap.isOpened());\r
416 \r
417     cv::Mat frame;\r
418 \r
419     cv::gpu::GpuMat d_frame;\r
420     cv::gpu::MOG2_GPU mog2;\r
421     cv::gpu::GpuMat foreground;\r
422 \r
423     cap >> frame;\r
424     ASSERT_FALSE(frame.empty());\r
425 \r
426     if (cn != 3)\r
427     {\r
428         cv::Mat temp;\r
429         if (cn == 1)\r
430             cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
431         else\r
432             cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
433         cv::swap(temp, frame);\r
434     }\r
435 \r
436     d_frame.upload(frame);\r
437 \r
438     mog2(d_frame, foreground);\r
439 \r
440     for (int i = 0; i < 10; ++i)\r
441     {\r
442         cap >> frame;\r
443         ASSERT_FALSE(frame.empty());\r
444 \r
445         if (cn != 3)\r
446         {\r
447             cv::Mat temp;\r
448             if (cn == 1)\r
449                 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
450             else\r
451                 cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
452             cv::swap(temp, frame);\r
453         }\r
454 \r
455         d_frame.upload(frame);\r
456 \r
457         startTimer(); next();\r
458         mog2(d_frame, foreground);\r
459         stopTimer();\r
460     }\r
461 }\r
462 \r
463 INSTANTIATE_TEST_CASE_P(Video, MOG2_update, testing::Combine(\r
464     ALL_DEVICES,\r
465     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),\r
466     testing::Values(Channels(1), Channels(3), Channels(4))));\r
467 \r
468 GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channels)\r
469 {\r
470     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
471     cv::gpu::setDevice(devInfo.deviceID());\r
472 \r
473     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
474     int cn = GET_PARAM(2);\r
475 \r
476     cv::VideoCapture cap(inputFile);\r
477     ASSERT_TRUE(cap.isOpened());\r
478 \r
479     cv::Mat frame;\r
480 \r
481     cv::gpu::GpuMat d_frame;\r
482     cv::gpu::MOG2_GPU mog2;\r
483     cv::gpu::GpuMat foreground;\r
484 \r
485     for (int i = 0; i < 10; ++i)\r
486     {\r
487         cap >> frame;\r
488         ASSERT_FALSE(frame.empty());\r
489 \r
490         if (cn != 3)\r
491         {\r
492             cv::Mat temp;\r
493             if (cn == 1)\r
494                 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
495             else\r
496                 cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
497             cv::swap(temp, frame);\r
498         }\r
499 \r
500         d_frame.upload(frame);\r
501 \r
502         mog2(d_frame, foreground);\r
503     }\r
504 \r
505     cv::gpu::GpuMat background;\r
506     mog2.getBackgroundImage(background);\r
507 \r
508     TEST_CYCLE()\r
509     {\r
510         mog2.getBackgroundImage(background);\r
511     }\r
512 }\r
513 \r
514 INSTANTIATE_TEST_CASE_P(Video, MOG2_getBackgroundImage, testing::Combine(\r
515     ALL_DEVICES,\r
516     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),\r
517     testing::Values(Channels(1), Channels(3), Channels(4))));\r
518 \r
519 //////////////////////////////////////////////////////\r
520 // VIBE\r
521 \r
522 GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels)\r
523 {\r
524     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
525     cv::gpu::setDevice(devInfo.deviceID());\r
526 \r
527     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
528     int cn = GET_PARAM(2);\r
529 \r
530     cv::VideoCapture cap(inputFile);\r
531     ASSERT_TRUE(cap.isOpened());\r
532 \r
533     cv::Mat frame;\r
534     cap >> frame;\r
535     ASSERT_FALSE(frame.empty());\r
536 \r
537     if (cn != 3)\r
538     {\r
539         cv::Mat temp;\r
540         if (cn == 1)\r
541             cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
542         else\r
543             cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
544         cv::swap(temp, frame);\r
545     }\r
546 \r
547     cv::gpu::GpuMat d_frame(frame);\r
548     cv::gpu::VIBE_GPU vibe;\r
549     cv::gpu::GpuMat foreground;\r
550 \r
551     vibe(d_frame, foreground);\r
552 \r
553     for (int i = 0; i < 10; ++i)\r
554     {\r
555         cap >> frame;\r
556         ASSERT_FALSE(frame.empty());\r
557 \r
558         if (cn != 3)\r
559         {\r
560             cv::Mat temp;\r
561             if (cn == 1)\r
562                 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
563             else\r
564                 cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
565             cv::swap(temp, frame);\r
566         }\r
567 \r
568         d_frame.upload(frame);\r
569 \r
570         startTimer(); next();\r
571         vibe(d_frame, foreground);\r
572         stopTimer();\r
573     }\r
574 }\r
575 \r
576 INSTANTIATE_TEST_CASE_P(Video, VIBE, testing::Combine(\r
577     ALL_DEVICES,\r
578     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),\r
579     testing::Values(Channels(1), Channels(3), Channels(4))));\r
580 \r
581 //////////////////////////////////////////////////////\r
582 // GMG\r
583 \r
584 IMPLEMENT_PARAM_CLASS(MaxFeatures, int)\r
585 \r
586 GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures)\r
587 {\r
588     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
589     cv::gpu::setDevice(devInfo.deviceID());\r
590     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
591     int cn = GET_PARAM(2);\r
592     int maxFeatures = GET_PARAM(3);\r
593 \r
594     cv::VideoCapture cap(inputFile);\r
595     ASSERT_TRUE(cap.isOpened());\r
596 \r
597     cv::Mat frame;\r
598     cap >> frame;\r
599     ASSERT_FALSE(frame.empty());\r
600 \r
601     if (cn != 3)\r
602     {\r
603         cv::Mat temp;\r
604         if (cn == 1)\r
605             cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
606         else\r
607             cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
608         cv::swap(temp, frame);\r
609     }\r
610 \r
611     cv::gpu::GpuMat d_frame(frame);\r
612     cv::gpu::GpuMat d_fgmask;\r
613 \r
614     cv::gpu::GMG_GPU gmg;\r
615     gmg.maxFeatures = maxFeatures;\r
616 \r
617     gmg(d_frame, d_fgmask);\r
618 \r
619     for (int i = 0; i < 150; ++i)\r
620     {\r
621         cap >> frame;\r
622         if (frame.empty())\r
623         {\r
624             cap.open(inputFile);\r
625             cap >> frame;\r
626         }\r
627 \r
628         if (cn != 3)\r
629         {\r
630             cv::Mat temp;\r
631             if (cn == 1)\r
632                 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);\r
633             else\r
634                 cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);\r
635             cv::swap(temp, frame);\r
636         }\r
637 \r
638         d_frame.upload(frame);\r
639 \r
640         startTimer(); next();\r
641         gmg(d_frame, d_fgmask);\r
642         stopTimer();\r
643     }\r
644 }\r
645 \r
646 INSTANTIATE_TEST_CASE_P(Video, GMG, testing::Combine(\r
647     ALL_DEVICES,\r
648     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),\r
649     testing::Values(Channels(1), Channels(3), Channels(4)),\r
650     testing::Values(MaxFeatures(20), MaxFeatures(40), MaxFeatures(60))));\r
651 \r
652 //////////////////////////////////////////////////////\r
653 // VideoWriter\r
654 \r
655 #ifdef WIN32\r
656 \r
657 GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string)\r
658 {\r
659     const double FPS = 25.0;\r
660 \r
661     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
662     cv::gpu::setDevice(devInfo.deviceID());\r
663 \r
664     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
665     std::string outputFile = cv::tempfile(".avi");\r
666 \r
667     cv::VideoCapture reader(inputFile);\r
668     ASSERT_TRUE( reader.isOpened() );\r
669 \r
670     cv::gpu::VideoWriter_GPU d_writer;\r
671 \r
672     cv::Mat frame;\r
673     cv::gpu::GpuMat d_frame;\r
674 \r
675     declare.time(10);\r
676 \r
677     for (int i = 0; i < 10; ++i)\r
678     {\r
679         reader >> frame;\r
680         ASSERT_FALSE(frame.empty());\r
681 \r
682         d_frame.upload(frame);\r
683 \r
684         if (!d_writer.isOpened())\r
685             d_writer.open(outputFile, frame.size(), FPS);\r
686 \r
687         startTimer(); next();\r
688         d_writer.write(d_frame);\r
689         stopTimer();\r
690     }\r
691 }\r
692 \r
693 INSTANTIATE_TEST_CASE_P(Video, VideoWriter, testing::Combine(\r
694     ALL_DEVICES,\r
695     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));\r
696 \r
697 #endif // WIN32\r
698 \r
699 //////////////////////////////////////////////////////\r
700 // VideoReader\r
701 \r
702 GPU_PERF_TEST(VideoReader, cv::gpu::DeviceInfo, std::string)\r
703 {\r
704     cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
705     cv::gpu::setDevice(devInfo.deviceID());\r
706 \r
707     std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));\r
708 \r
709     cv::gpu::VideoReader_GPU reader(inputFile);\r
710     ASSERT_TRUE( reader.isOpened() );\r
711 \r
712     cv::gpu::GpuMat frame;\r
713 \r
714     reader.read(frame);\r
715 \r
716     declare.time(20);\r
717 \r
718     TEST_CYCLE_N(10)\r
719     {\r
720         reader.read(frame);\r
721     }\r
722 }\r
723 \r
724 INSTANTIATE_TEST_CASE_P(Video, VideoReader, testing::Combine(\r
725     ALL_DEVICES,\r
726     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));\r
727 \r
728 #endif\r