Skip to content

Instantly share code, notes, and snippets.

@awesomebytes
Last active June 23, 2020 07:55
Show Gist options
  • Select an option

  • Save awesomebytes/92e6ba2e24bad4ce24898e9b9fc4d703 to your computer and use it in GitHub Desktop.

Select an option

Save awesomebytes/92e6ba2e24bad4ce24898e9b9fc4d703 to your computer and use it in GitHub Desktop.
Test TX2 OpenCV cuda support

Run the docker image with

docker run -it --runtime nvidia -e DISPLAY --privileged IMAGE_NAME /bin/bash

./test.sh

#include <iostream>
#include <ctime>
#include <cmath>
#include "bits/time.h"
//#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>
#define TestCUDA true
int main()
{
std::clock_t begin = std::clock();
try {
cv::Mat srcHost = cv::imread("image.png",CV_LOAD_IMAGE_GRAYSCALE);
for(int i=0; i<1000; i++) {
if(TestCUDA) {
cv::cuda::GpuMat dst, src;
src.upload(srcHost);
//cv::cuda::threshold(src,dst,128.0,255.0, CV_THRESH_BINARY);
cv::cuda::bilateralFilter(src,dst,3,1,1);
cv::Mat resultHost;
dst.download(resultHost);
} else {
cv::Mat dst;
cv::bilateralFilter(srcHost,dst,3,1,1);
}
}
//cv::imshow("Result",resultHost);
//cv::waitKey();
} catch(const cv::Exception& ex) {
std::cout << "Error: " << ex.what() << std::endl;
}
std::clock_t end = std::clock();
std::cout << double(end-begin) / CLOCKS_PER_SEC << std::endl;
}
#!/usr/bin/env bash
set -o xtrace
wget -O test.cpp https://gist.githubusercontent.com/awesomebytes/92e6ba2e24bad4ce24898e9b9fc4d703/raw/c54c2dd0e94155d242ddd5ea7188250a024ae8e7/test.cpp
wget -O image.png https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png
nvcc `pkg-config opencv --cflags --libs` -o test test.cpp
./test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment