Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. // ***********************************************************************
  2. //
  3. // Demo program for education in subject
  4. // Computer Architectures and Parallel Systems.
  5. // Petr Olivka, dep. of Computer Science, FEI, VSB-TU Ostrava
  6. // email:petr.olivka@vsb.cz
  7. //
  8. // Example of CUDA Technology Usage with unified memory.
  9. //
  10. // Image transformation from RGB to BW schema.
  11. // Image manipulation is performed by OpenCV library.
  12. //
  13. // ***********************************************************************
  14.  
  15. #include <stdio.h>
  16. #include <cuda_device_runtime_api.h>
  17. #include <cuda_runtime.h>
  18. #include <opencv2/opencv.hpp>
  19. #include <opencv2/core/matx.hpp>
  20. #include "uni_mem_allocator.h"
  21. #include "pic_type.h"
  22.  
  23.  
  24. // Function prototype from .cu file
  25. void cu_create_chessboard( CudaPic t_pic, int t_square_size );
  26. void cu_create_alphaimg( CudaPic t_pic, uchar3 t_color );
  27. void cu_insertimage( CudaPic t_big_pic, CudaPic t_small_pic, int2 t_position );
  28. void cu_create_Circles(CudaPic, int);
  29. int main( int t_numarg, char **t_arg )
  30. {
  31. // Uniform Memory allocator for Mat
  32. UniformAllocator allocator;
  33. cv::Mat::setDefaultAllocator( &allocator );
  34.  
  35. cv::Mat l_cv_chessboard( 511, 515, CV_8UC3 );
  36. cv::Mat l_cv_kruh(500, 500, CV_8UC3);
  37. CudaPic l_pic_terc(l_cv_kruh);
  38.  
  39. CudaPic l_pic_chessboard(l_cv_chessboard);
  40. //l_pic_chessboard.m_size.x = l_cv_chessboard.cols;
  41. //l_pic_chessboard.m_size.y = l_cv_chessboard.rows;
  42. //l_pic_chessboard.m_p_uchar3 = ( uchar3 * ) l_cv_chessboard.data;
  43.  
  44. cu_create_chessboard( l_pic_chessboard, 21 );
  45.  
  46. //cv::imshow( "Chess Board", l_cv_chessboard );
  47.  
  48. cv::Mat l_cv_alphaimg( 211, 191, CV_8UC4 );
  49.  
  50. CudaPic l_pic_alphaimg(l_cv_alphaimg);
  51. //l_pic_alphaimg.m_size.x = l_cv_alphaimg.cols;
  52. //l_pic_alphaimg.m_size.y = l_cv_alphaimg.rows;
  53. //l_pic_alphaimg.m_p_uchar4 = ( uchar4 * ) l_cv_alphaimg.data;
  54.  
  55. cu_create_alphaimg( l_pic_alphaimg, { 0, 0, 255 } );
  56.  
  57. //cv::imshow( "Alpha channel", l_cv_alphaimg );
  58.  
  59. cu_insertimage( l_pic_chessboard, l_pic_alphaimg, { 11, 23 } );
  60. // cu_create_Circles(l_cv_chessboard);
  61.  
  62.  
  63. uint3 barvy = { 255,0,0 };
  64. cu_create_Circles(l_cv_kruh, 50);
  65. cv::imshow( "Result I", l_cv_kruh );
  66.  
  67. // some argument?
  68. if ( t_numarg > 1 )
  69. {
  70. // Load image
  71. cv::Mat l_cv_img = cv::imread( t_arg[ 1 ], CV_LOAD_IMAGE_UNCHANGED );
  72.  
  73. if ( !l_cv_img.data )
  74. printf( "Unable to read file '%s'\n", t_arg[ 1 ] );
  75.  
  76. else if ( l_cv_img.channels() != 4 )
  77. printf( "Image does not contain alpha channel!\n" );
  78.  
  79. else
  80. {
  81. // insert loaded image
  82. CudaPic l_pic_img;
  83. l_pic_img.m_size.x = l_cv_img.cols;
  84. l_pic_img.m_size.y = l_cv_img.rows;
  85. l_pic_img.m_p_uchar4 = ( uchar4 * ) l_cv_img.data;
  86.  
  87. cu_insertimage( l_pic_chessboard, l_pic_img, { ( int ) l_pic_chessboard.m_size.x / 2, ( int ) l_pic_chessboard.m_size.y / 2 } );
  88.  
  89. cv::imshow( "Result II", l_cv_chessboard );
  90. }
  91. }
  92.  
  93. cv::waitKey( 0 );
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement