sgarizvi icon

Bayer Test

sgarizvi | PRO | 12/13/23 08:31:26 AM UTC (Edited) | 0 ⭐ | 11735 👁️ | Never ⏰ | []
C++ |

5.17 KB

|

Source Code

|

0 👍

/

0 👎

#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <cuvi.h>
 
using namespace std;
 
 
void mainx()
{
    auto cap = cv::VideoCapture("rtsp://192.168.100.50/live/ch00_1");
 
    cv::Mat frame;
    cv::Mat enhanced;
 
    string WINDOW_TITLE = "Comparison";
 
    cv::namedWindow(WINDOW_TITLE, cv::WINDOW_NORMAL);
    cv::resizeWindow(WINDOW_TITLE, 3840, 1080);
 
    
    cv::Mat canvas(1080, 3840, CV_8UC3);
 
    while (cap.isOpened())
    {
        cap.read(frame);
        cv::detailEnhance(frame, enhanced);
 
        frame.copyTo(canvas(cv::Rect(0, 0, 1920, 1080)));
        enhanced.copyTo(canvas(cv::Rect(1920, 0, 1920, 1080)));
 
        cout <<canvas.size()<<" : " << enhanced.size() << endl;
 
        cv::resizeWindow(WINDOW_TITLE, 3840, 1080);
        cv::imshow(WINDOW_TITLE, canvas);
        if(13 == cv::waitKey(10))
        {
            break;
        }
    }
}
 
void cudaBootstrap()
{
    auto current = std::chrono::system_clock::now();
    std::time_t current_time = std::chrono::system_clock::to_time_t(current);
    std::cout << std::ctime(&current_time) << endl;
    CuviDeviceProperties props;
    int current_device = cuvi::device::getCurentDevice();
    cuvi::device::getDeviceProperties(current_device, props);
 
    std::string name(props.deviceName);
 
    cout << "Device: " << name << endl;
    cout << "Compute Capability: " << props.computeCapability << endl;
    cout << "Total Memory : " << std::round(props.globalMemory/ (1024.0 * 1024.0 * 1024.0 ))<<" GB" << endl;
    cout << "Available Memory : " << props.freeGlobalMemory / (1024.0 * 1024.0 * 1024.0) << " GB" << endl;
    
    CuviImage img = cuvi::io::loadImage("F:/datasets/images/bayer/mandi16.tif", CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH);
    CuviImage dst;
    cout << "BOOTSTRAP: " << cuvi::getStatusString(cuvi::colorOperations::demosaicDFPD(img, dst, CUVI_BAYER_BGGR, false)) << endl << endl;
    img.release();
    dst.release();
    cout << "====================================================================================" << endl << endl;
}
 
 
void benchmarkDFPD(const int dataset_idx, const int iterations)
{
    const int N = 2;
    CuviLoadType loadType[N] = { CUVI_LOAD_IMAGE_GRAYSCALE, CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH };
    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) };
    
    CuviStatus st;
    for (int idx = 0; idx < N; idx++)
    {
        CuviImage img = cuvi::io::loadImage(dataset[dataset_idx].first, loadType[idx]);
 
        if (img.isInitialized())
        {
            cout << endl << "Image : [ " << img.width() << " x " << img.height() << " ] " << cuvi::getTypeString(img.type()) << endl;
            CuviImage dst;
 
            CuviTimer t;
            t.Start();
            for (int i = 0; i < iterations; i++)
            {
                st = cuvi::colorOperations::demosaicDFPD(img, dst, dataset[dataset_idx].second, false);
                if (CUVI_SUCCESS != st)
                {
                    cout << cuvi::getStatusString(st) << endl;
                }
            }
            t.Stop();
 
            cout << "(DFPD) "<< cuvi::getTypeString(dst.type()) << " Mean Elapsed Time = " << (t.GetElapsedTime() * 1000000.0f) / iterations << " us" << endl;
 
            //dst.show(cuvi::getTypeString(dst.type()));
            //cuvi::io::saveImage(dst, "F:/datasets/images/bayerReference/output_" + cuvi::getTypeString(dst.type()) + ".tif");
 
        }
        else
        {
            cout << "Image Not Initialized" << endl;
        }
    }
}
 
void benchmarkHQLI(const int dataset_idx, const int iterations)
{
    const int N = 2;
    CuviLoadType loadType[N] = { CUVI_LOAD_IMAGE_GRAYSCALE, CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH };
    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) };
    
    const int filterSizes[] = { 5,7,9 };
 
    CuviStatus st;
    for (int idx = 0; idx < N; idx++)
    {
        CuviImage img = cuvi::io::loadImage(dataset[dataset_idx].first, loadType[idx]);
        
        if (img.isInitialized())
        {
            cout << endl << "Image : [ " << img.width() << " x " << img.height() << " ] " << cuvi::getTypeString(img.type()) << endl;
            for (int f = 0; f < 3; f++)
            {
                int fsize = filterSizes[f];
                CuviImage dst;// (img.size(), img.depth(), 3);
 
                CuviTimer t;
                t.Start();
 
                for (int i = 0; i < iterations; i++)
                {
                    st = cuvi::colorOperations::demosaicHQLI(img, dst, dataset[dataset_idx].second, fsize);
                    if (CUVI_SUCCESS != st)
                    {
                        cout << cuvi::getStatusString(st) << endl;
                    }
                }
                t.Stop();
 
                cout << "(HQLI" << fsize << ") " << cuvi::getTypeString(dst.type()) << " Mean Elapsed Time = " << (t.GetElapsedTime() * 1000000.0f) / iterations << " us" << endl;
 
                //dst.show(cuvi::getTypeString(dst.type()));
                //cuvi::io::saveImage(dst, "F:/datasets/images/bayerReference/output_" + cuvi::getTypeString(dst.type()) + ".tif");
            }
        }
        else
        {
            cout << "Image Not Initialized" << endl;
            return;
        }
        cout << endl;
    }
}
 
int main()
{
    cudaBootstrap();
 
    const int iterations = 500;
    const int dataset_idx = 1;
 
    cout << "Starting benchmark with " << iterations << " iterations ..." << endl << endl;
 
    benchmarkDFPD(dataset_idx, iterations);
    cout << endl;
    benchmarkHQLI(dataset_idx, iterations);
 
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎