PageRenderTime 63ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/testing/ipl.cpp

https://github.com/rodrigob/cudatemplates
C++ | 68 lines | 26 code | 11 blank | 31 comment | 0 complexity | 2dd7ea4341a989ea2960ac84e879cb77 MD5 | raw file
  1. /*
  2. Cuda Templates.
  3. Copyright (C) 2008 Institute for Computer Graphics and Vision,
  4. Graz University of Technology
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <iostream>
  17. #include "highgui.h"
  18. #include <cudatemplates/copy.hpp>
  19. #include <cudatemplates/iplreference.hpp>
  20. #include <cudatemplates/devicememorylinear.hpp>
  21. typedef unsigned char PixelType;
  22. /**
  23. Unlike e.g. ITK, OpenCV does not take care of handling the image
  24. data with e.g. shared pointers and there the user has to be sure to
  25. delete the constructed IplImage and the cudatemplates
  26. representation of it in the right order.
  27. */
  28. int
  29. main()
  30. {
  31. try {
  32. // read test input image (grayscale mode)
  33. IplImage* image_input = cvLoadImage( "cameraman.png", 0);
  34. // create reference to IplImage for use with CUDA classes:
  35. Cuda::IplReference<PixelType, 2> host_image_input(image_input);
  36. // create empty Ipl output image:
  37. IplImage* image_output = cvCreateImage( cvGetSize(image_input) , image_input->depth,
  38. image_input->nChannels );
  39. // create reference to Ipl output image and initialize with same size as input image:
  40. Cuda::IplReference<PixelType, 2> host_image_output(host_image_input.size, image_output);
  41. // copy input image to GPU and back to output image (i.e., CPU/GPU roundtrip):
  42. Cuda::DeviceMemoryPitched<PixelType, 2> device_image(host_image_input.size);
  43. Cuda::copy(device_image, host_image_input);
  44. Cuda::copy(host_image_output, device_image);
  45. // write output image:
  46. cvSaveImage( "cameraman_ipl_out.png", image_output );
  47. }
  48. catch(const std::exception &e) {
  49. std::cerr << e.what() << std::endl;
  50. return 1;
  51. }
  52. return 0;
  53. }