sgarizvi

Bayer Test

Dec 13th, 2023 (edited)
1,871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.17 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <opencv2/opencv.hpp>
  4. #include <cuvi.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void mainx()
  10. {
  11.     auto cap = cv::VideoCapture("rtsp://192.168.100.50/live/ch00_1");
  12.  
  13.     cv::Mat frame;
  14.     cv::Mat enhanced;
  15.  
  16.     string WINDOW_TITLE = "Comparison";
  17.  
  18.     cv::namedWindow(WINDOW_TITLE, cv::WINDOW_NORMAL);
  19.     cv::resizeWindow(WINDOW_TITLE, 3840, 1080);
  20.  
  21.    
  22.     cv::Mat canvas(1080, 3840, CV_8UC3);
  23.  
  24.     while (cap.isOpened())
  25.     {
  26.         cap.read(frame);
  27.         cv::detailEnhance(frame, enhanced);
  28.  
  29.         frame.copyTo(canvas(cv::Rect(0, 0, 1920, 1080)));
  30.         enhanced.copyTo(canvas(cv::Rect(1920, 0, 1920, 1080)));
  31.  
  32.         cout <<canvas.size()<<" : " << enhanced.size() << endl;
  33.  
  34.         cv::resizeWindow(WINDOW_TITLE, 3840, 1080);
  35.         cv::imshow(WINDOW_TITLE, canvas);
  36.         if(13 == cv::waitKey(10))
  37.         {
  38.             break;
  39.         }
  40.     }
  41. }
  42.  
  43. void cudaBootstrap()
  44. {
  45.     auto current = std::chrono::system_clock::now();
  46.     std::time_t current_time = std::chrono::system_clock::to_time_t(current);
  47.     std::cout << std::ctime(&current_time) << endl;
  48.     CuviDeviceProperties props;
  49.     int current_device = cuvi::device::getCurentDevice();
  50.     cuvi::device::getDeviceProperties(current_device, props);
  51.  
  52.     std::string name(props.deviceName);
  53.  
  54.     cout << "Device: " << name << endl;
  55.     cout << "Compute Capability: " << props.computeCapability << endl;
  56.     cout << "Total Memory : " << std::round(props.globalMemory/ (1024.0 * 1024.0 * 1024.0 ))<<" GB" << endl;
  57.     cout << "Available Memory : " << props.freeGlobalMemory / (1024.0 * 1024.0 * 1024.0) << " GB" << endl;
  58.    
  59.     CuviImage img = cuvi::io::loadImage("F:/datasets/images/bayer/mandi16.tif", CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH);
  60.     CuviImage dst;
  61.     cout << "BOOTSTRAP: " << cuvi::getStatusString(cuvi::colorOperations::demosaicDFPD(img, dst, CUVI_BAYER_BGGR, false)) << endl << endl;
  62.     img.release();
  63.     dst.release();
  64.     cout << "====================================================================================" << endl << endl;
  65. }
  66.  
  67.  
  68. void benchmarkDFPD(const int dataset_idx, const int iterations)
  69. {
  70.     const int N = 2;
  71.     CuviLoadType loadType[N] = { CUVI_LOAD_IMAGE_GRAYSCALE, CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH };
  72.     std::pair<std::string, CuviBayerSeq> dataset[] = { std::make_pair("F:/datasets/images/bayer/demosaic16.tif", CUVI_BAYER_RGGB), std::make_pair("F:/datasets/images/bayer/mandi16.tif", CUVI_BAYER_BGGR) };
  73.    
  74.     CuviStatus st;
  75.     for (int idx = 0; idx < N; idx++)
  76.     {
  77.         CuviImage img = cuvi::io::loadImage(dataset[dataset_idx].first, loadType[idx]);
  78.  
  79.         if (img.isInitialized())
  80.         {
  81.             cout << endl << "Image : [ " << img.width() << " x " << img.height() << " ] " << cuvi::getTypeString(img.type()) << endl;
  82.             CuviImage dst;
  83.  
  84.             CuviTimer t;
  85.             t.Start();
  86.             for (int i = 0; i < iterations; i++)
  87.             {
  88.                 st = cuvi::colorOperations::demosaicDFPD(img, dst, dataset[dataset_idx].second, false);
  89.                 if (CUVI_SUCCESS != st)
  90.                 {
  91.                     cout << cuvi::getStatusString(st) << endl;
  92.                 }
  93.             }
  94.             t.Stop();
  95.  
  96.             cout << "(DFPD) "<< cuvi::getTypeString(dst.type()) << " Mean Elapsed Time = " << (t.GetElapsedTime() * 1000000.0f) / iterations << " us" << endl;
  97.  
  98.             //dst.show(cuvi::getTypeString(dst.type()));
  99.             //cuvi::io::saveImage(dst, "F:/datasets/images/bayerReference/output_" + cuvi::getTypeString(dst.type()) + ".tif");
  100.  
  101.         }
  102.         else
  103.         {
  104.             cout << "Image Not Initialized" << endl;
  105.         }
  106.     }
  107. }
  108.  
  109. void benchmarkHQLI(const int dataset_idx, const int iterations)
  110. {
  111.     const int N = 2;
  112.     CuviLoadType loadType[N] = { CUVI_LOAD_IMAGE_GRAYSCALE, CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH };
  113.     std::pair<std::string, CuviBayerSeq> dataset[] = { std::make_pair("F:/datasets/images/bayer/demosaic16.tif", CUVI_BAYER_RGGB), std::make_pair("F:/datasets/images/bayer/mandi16.tif", CUVI_BAYER_BGGR) };
  114.    
  115.     const int filterSizes[] = { 5,7,9 };
  116.  
  117.     CuviStatus st;
  118.     for (int idx = 0; idx < N; idx++)
  119.     {
  120.         CuviImage img = cuvi::io::loadImage(dataset[dataset_idx].first, loadType[idx]);
  121.        
  122.         if (img.isInitialized())
  123.         {
  124.             cout << endl << "Image : [ " << img.width() << " x " << img.height() << " ] " << cuvi::getTypeString(img.type()) << endl;
  125.             for (int f = 0; f < 3; f++)
  126.             {
  127.                 int fsize = filterSizes[f];
  128.                 CuviImage dst;// (img.size(), img.depth(), 3);
  129.  
  130.                 CuviTimer t;
  131.                 t.Start();
  132.  
  133.                 for (int i = 0; i < iterations; i++)
  134.                 {
  135.                     st = cuvi::colorOperations::demosaicHQLI(img, dst, dataset[dataset_idx].second, fsize);
  136.                     if (CUVI_SUCCESS != st)
  137.                     {
  138.                         cout << cuvi::getStatusString(st) << endl;
  139.                     }
  140.                 }
  141.                 t.Stop();
  142.  
  143.                 cout << "(HQLI" << fsize << ") " << cuvi::getTypeString(dst.type()) << " Mean Elapsed Time = " << (t.GetElapsedTime() * 1000000.0f) / iterations << " us" << endl;
  144.  
  145.                 //dst.show(cuvi::getTypeString(dst.type()));
  146.                 //cuvi::io::saveImage(dst, "F:/datasets/images/bayerReference/output_" + cuvi::getTypeString(dst.type()) + ".tif");
  147.             }
  148.         }
  149.         else
  150.         {
  151.             cout << "Image Not Initialized" << endl;
  152.             return;
  153.         }
  154.         cout << endl;
  155.     }
  156. }
  157.  
  158. int main()
  159. {
  160.     cudaBootstrap();
  161.  
  162.     const int iterations = 500;
  163.     const int dataset_idx = 1;
  164.  
  165.     cout << "Starting benchmark with " << iterations << " iterations ..." << endl << endl;
  166.  
  167.     benchmarkDFPD(dataset_idx, iterations);
  168.     cout << endl;
  169.     benchmarkHQLI(dataset_idx, iterations);
  170.  
  171.     return 0;
  172. }
Advertisement