Commit e5a544f0fb25f32f0baadc80036cf4739c089c36

Authored by boolli
1 parent 4417e084

Finish CUDARGB2GrayScale plugin

openbr/plugins/cuda/copyto.cpp
@@ -26,9 +26,6 @@ private: @@ -26,9 +26,6 @@ private:
26 const Mat& srcMat = src.m(); 26 const Mat& srcMat = src.m();
27 const int rows = srcMat.rows; 27 const int rows = srcMat.rows;
28 const int cols = srcMat.cols; 28 const int cols = srcMat.cols;
29 -std::cout << "CopyTo" << std::endl;  
30 - std::cout << "rows: " << rows << std::endl;  
31 - std::cout << "cols: " << cols << std::endl;  
32 29
33 // output will be a single pointer to graphics card memory 30 // output will be a single pointer to graphics card memory
34 Mat dstMat = Mat(4, 1, DataType<void*>::type); 31 Mat dstMat = Mat(4, 1, DataType<void*>::type);
openbr/plugins/cuda/cudadefines.hpp
@@ -16,7 +16,7 @@ using namespace std; @@ -16,7 +16,7 @@ using namespace std;
16 cout << pthread_self() << ": CUDA Malloc Error(" << *errPtr << "): " << cudaGetErrorString(*errPtr) << endl; \ 16 cout << pthread_self() << ": CUDA Malloc Error(" << *errPtr << "): " << cudaGetErrorString(*errPtr) << endl; \
17 throw 0; \ 17 throw 0; \
18 } \ 18 } \
19 - cout << pthread_self() << ": CUDA Malloc: " << (void*)*(int**)cudaPtrPtr << endl; 19 + //cout << pthread_self() << ": CUDA Malloc: " << (void*)*(int**)cudaPtrPtr << endl;
20 20
21 #define CUDA_SAFE_MEMCPY(dstPtr, srcPtr, count, kind, errPtr) \ 21 #define CUDA_SAFE_MEMCPY(dstPtr, srcPtr, count, kind, errPtr) \
22 *errPtr = cudaMemcpy(dstPtr, srcPtr, count, kind); \ 22 *errPtr = cudaMemcpy(dstPtr, srcPtr, count, kind); \
openbr/plugins/cuda/cudacvt.cpp renamed to openbr/plugins/cuda/cudargb2grayscale.cpp
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 using namespace cv; 26 using namespace cv;
27 27
28 namespace br { namespace cuda{ 28 namespace br { namespace cuda{
29 - void cudacvt_wrapper(void* srcPtr, void**dstPtr, int rows, int cols); 29 + void cudargb2grayscale_wrapper(void* srcPtr, void**dstPtr, int rows, int cols);
30 }} 30 }}
31 31
32 namespace br 32 namespace br
@@ -37,38 +37,19 @@ namespace br @@ -37,38 +37,19 @@ namespace br
37 * \brief Colorspace conversion. 37 * \brief Colorspace conversion.
38 * \author Li Li \cite Josh Klontz \cite jklontz 38 * \author Li Li \cite Josh Klontz \cite jklontz
39 */ 39 */
40 -class CUDACvtTransform : public UntrainableTransform 40 +class CUDARGB2GrayScaleTransform : public UntrainableTransform
41 { 41 {
42 Q_OBJECT 42 Q_OBJECT
43 - Q_ENUMS(ColorSpace)  
44 - Q_PROPERTY(ColorSpace colorSpace READ get_colorSpace WRITE set_colorSpace RESET reset_colorSpace STORED false)  
45 - Q_PROPERTY(int channel READ get_channel WRITE set_channel RESET reset_channel STORED false)  
46 43
47 public: 44 public:
48 - enum ColorSpace { Gray = CV_BGR2GRAY,  
49 - RGBGray = CV_RGB2GRAY,  
50 - HLS = CV_BGR2HLS,  
51 - HSV = CV_BGR2HSV,  
52 - Lab = CV_BGR2Lab,  
53 - Luv = CV_BGR2Luv,  
54 - RGB = CV_BGR2RGB,  
55 - XYZ = CV_BGR2XYZ,  
56 - YCrCb = CV_BGR2YCrCb,  
57 - Color = CV_GRAY2BGR };  
58 45
59 private: 46 private:
60 - BR_PROPERTY(ColorSpace, colorSpace, Gray)  
61 - BR_PROPERTY(int, channel, -1)  
62 -  
63 void project(const Template &src, Template &dst) const 47 void project(const Template &src, Template &dst) const
64 { 48 {
65 void* const* srcDataPtr = src.m().ptr<void*>(); 49 void* const* srcDataPtr = src.m().ptr<void*>();
66 int rows = *((int*) srcDataPtr[1]); 50 int rows = *((int*) srcDataPtr[1]);
67 int cols = *((int*) srcDataPtr[2]); 51 int cols = *((int*) srcDataPtr[2]);
68 int type = *((int*) srcDataPtr[3]); 52 int type = *((int*) srcDataPtr[3]);
69 - std::cout << "CVT" << std::endl;  
70 - std::cout << "rows: " << rows << std::endl;  
71 - std::cout << "cols: " << cols << std::endl;  
72 53
73 Mat dstMat = Mat(src.m().rows, src.m().cols, src.m().type()); 54 Mat dstMat = Mat(src.m().rows, src.m().cols, src.m().type());
74 void** dstDataPtr = dstMat.ptr<void*>(); 55 void** dstDataPtr = dstMat.ptr<void*>();
@@ -77,7 +58,7 @@ private: @@ -77,7 +58,7 @@ private:
77 dstDataPtr[3] = srcDataPtr[3]; 58 dstDataPtr[3] = srcDataPtr[3];
78 *((int*)dstDataPtr[3]) = CV_8UC1; // not sure if the type of the new mat is the same 59 *((int*)dstDataPtr[3]) = CV_8UC1; // not sure if the type of the new mat is the same
79 60
80 - br::cuda::cudacvt_wrapper(srcDataPtr[0], &dstDataPtr[0], rows, cols); 61 + br::cuda::cudargb2grayscale_wrapper(srcDataPtr[0], &dstDataPtr[0], rows, cols);
81 dst = dstMat; 62 dst = dstMat;
82 63
83 /* 64 /*
@@ -92,8 +73,8 @@ private: @@ -92,8 +73,8 @@ private:
92 } 73 }
93 }; 74 };
94 75
95 -BR_REGISTER(Transform, CUDACvtTransform) 76 +BR_REGISTER(Transform, CUDARGB2GrayScaleTransform)
96 77
97 } // namespace br 78 } // namespace br
98 79
99 -#include "imgproc/cudacvt.moc" 80 +#include "imgproc/cudargb2grayscale.moc"
openbr/plugins/cuda/cudacvt.cu renamed to openbr/plugins/cuda/cudargb2grayscale.cu
@@ -14,7 +14,7 @@ using namespace cv::gpu; @@ -14,7 +14,7 @@ using namespace cv::gpu;
14 14
15 namespace br{ namespace cuda { 15 namespace br{ namespace cuda {
16 16
17 - __global__ void cudacvt_kernel(uint8_t* srcPtr, uint8_t* dstPtr, int rows, int cols) 17 + __global__ void cudargb2grayscale_kernel(uint8_t* srcPtr, uint8_t* dstPtr, int rows, int cols)
18 { 18 {
19 int rowInd = blockIdx.y*blockDim.y+threadIdx.y; 19 int rowInd = blockIdx.y*blockDim.y+threadIdx.y;
20 int colInd = blockIdx.x*blockDim.x+threadIdx.x; 20 int colInd = blockIdx.x*blockDim.x+threadIdx.x;
@@ -31,17 +31,15 @@ namespace br{ namespace cuda { @@ -31,17 +31,15 @@ namespace br{ namespace cuda {
31 return; 31 return;
32 } 32 }
33 33
34 - void cudacvt_wrapper(void* srcPtr, void** dstPtr, int rows, int cols) 34 + void cudargb2grayscale_wrapper(void* srcPtr, void** dstPtr, int rows, int cols)
35 { 35 {
36 cudaError_t err; 36 cudaError_t err;
37 dim3 threadsPerBlock(8, 8); 37 dim3 threadsPerBlock(8, 8);
38 dim3 numBlocks(cols/threadsPerBlock.x + 1, 38 dim3 numBlocks(cols/threadsPerBlock.x + 1,
39 rows/threadsPerBlock.y + 1); 39 rows/threadsPerBlock.y + 1);
40 - std::cout << "Before malloc" << std::endl;  
41 CUDA_SAFE_MALLOC(dstPtr, rows*cols*sizeof(uint8_t), &err); 40 CUDA_SAFE_MALLOC(dstPtr, rows*cols*sizeof(uint8_t), &err);
42 - std::cout << "After malloc" << std::endl;  
43 41
44 - cudacvt_kernel<<<numBlocks, threadsPerBlock>>>((uint8_t*)srcPtr, (uint8_t*) (*dstPtr), rows, cols); 42 + cudargb2grayscale_kernel<<<numBlocks, threadsPerBlock>>>((uint8_t*)srcPtr, (uint8_t*) (*dstPtr), rows, cols);
45 CUDA_KERNEL_ERR_CHK(&err); 43 CUDA_KERNEL_ERR_CHK(&err);
46 CUDA_SAFE_FREE(srcPtr, &err); 44 CUDA_SAFE_FREE(srcPtr, &err);
47 } 45 }