Merge pull request #6762 from maff91:master
[platform/upstream/opencv.git] / samples / gpu / video_writer.cpp
index ce00675..80d2cfc 100644 (file)
@@ -1,11 +1,15 @@
 #include <iostream>
+
+#include "opencv2/opencv_modules.hpp"
+
+#if defined(HAVE_OPENCV_CUDACODEC) && defined(WIN32)
+
 #include <vector>
 #include <numeric>
 
-#include "opencv2/core/core.hpp"
-#include "opencv2/gpu/gpu.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/contrib/contrib.hpp"
+#include "opencv2/core.hpp"
+#include "opencv2/cudacodec.hpp"
+#include "opencv2/highgui.hpp"
 
 int main(int argc, const char* argv[])
 {
@@ -25,17 +29,17 @@ int main(int argc, const char* argv[])
         return -1;
     }
 
-    cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());
+    cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
 
     cv::VideoWriter writer;
-    cv::gpu::VideoWriter_GPU d_writer;
+    cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
 
     cv::Mat frame;
-    cv::gpu::GpuMat d_frame;
+    cv::cuda::GpuMat d_frame;
 
     std::vector<double> cpu_times;
     std::vector<double> gpu_times;
-    cv::TickMeter tm;
+    TickMeter tm;
 
     for (int i = 1;; ++i)
     {
@@ -55,16 +59,16 @@ int main(int argc, const char* argv[])
 
             std::cout << "Open CPU Writer" << std::endl;
 
-            if (!writer.open("output_cpu.avi", CV_FOURCC('X', 'V', 'I', 'D'), FPS, frame.size()))
+            if (!writer.open("output_cpu.avi", cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), FPS, frame.size()))
                 return -1;
         }
 
-        if (!d_writer.isOpened())
+        if (d_writer.empty())
         {
-            std::cout << "Open GPU Writer" << std::endl;
+            std::cout << "Open CUDA Writer" << std::endl;
 
             const cv::String outputFilename = "output_gpu.avi";
-            d_writer.open(outputFilename, frame.size(), FPS);
+            d_writer = cv::cudacodec::createVideoWriter(outputFilename, frame.size(), FPS);
         }
 
         d_frame.upload(frame);
@@ -77,7 +81,7 @@ int main(int argc, const char* argv[])
         cpu_times.push_back(tm.getTimeMilli());
 
         tm.reset(); tm.start();
-        d_writer.write(d_frame);
+        d_writer->write(d_frame);
         tm.stop();
         gpu_times.push_back(tm.getTimeMilli());
     }
@@ -95,3 +99,13 @@ int main(int argc, const char* argv[])
 
     return 0;
 }
+
+#else
+
+int main()
+{
+    std::cout << "OpenCV was built without CUDA Video encoding support\n" << std::endl;
+    return 0;
+}
+
+#endif