Last active
July 13, 2018 21:01
-
-
Save cactorium/9b8be98bcb488cbd6354e44e70d6b639 to your computer and use it in GitHub Desktop.
OpenCV texture test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <opencv2/imgproc/imgproc.hpp> | |
#include <opencv2/core/cuda.hpp> | |
#include <opencv2/core/cuda_stream_accessor.hpp> | |
#include <opencv2/cudev/ptr2d/glob.hpp> | |
void transfer_caller(cv::cudev::GlobPtrSz<float> in, cv::cudev::PtrStepSz<float> out); | |
int main() { | |
cv::Mat image = cv::imread("test1.png"); | |
cv::Mat imagef; | |
cv::cvtColor(image, image, CV_RGB2GRAY); | |
image.convertTo(imagef, CV_32F); | |
imagef *= 1./255.; | |
cv::cuda::GpuMat image_; | |
image_.upload(imagef); | |
cv::cuda::GpuMat out; | |
out.create(image_.rows, image_.cols, image_.type()); | |
transfer_caller(cv::cudev::globPtr<float>(image_), out); | |
cv::Mat out_; | |
out.download(out_); | |
cv::imshow("input", imagef); | |
cv::imshow("output", out_); | |
cv::waitKey(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// texture_test.cu | |
#include <opencv2/core/cuda.hpp> | |
#include <opencv2/cudev/ptr2d/glob.hpp> | |
#include <opencv2/cudev/ptr2d/texture.hpp> | |
__global__ void transfer(cv::cudev::TexturePtr<float> in, cv::cudev::PtrStep<float> out) { | |
float val = in(threadIdx.x, blockIdx.x); | |
out(threadIdx.x, blockIdx.x) = val; | |
} | |
void transfer_caller(cv::cudev::GlobPtrSz<float> in, cv::cudev::PtrStepSz<float> out) { | |
cv::cudev::Texture<float> tex(in); | |
transfer<<<out.cols, out.rows>>>(tex, out); | |
cudaError_t status = cudaDeviceSynchronize(); | |
if (cudaSuccess != status) { | |
fprintf(stderr, "returned 0x%x (%s)\n", status, cudaGetErrorString(status)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment