Commit 087a8f65b824d3f14f38cbc39d8b9d3751a849ed
1 parent
5ea8591c
added dimension checking for PCA
Showing
2 changed files
with
8 additions
and
4 deletions
openbr/plugins/cuda/cudapca.cpp
| ... | ... | @@ -34,7 +34,7 @@ using namespace cv; |
| 34 | 34 | namespace br { namespace cuda { namespace pca { |
| 35 | 35 | void initializeWrapper(float* evPtr, int evRows, int evCols, float* meanPtr, int meanElems); |
| 36 | 36 | void trainWrapper(void* cudaSrc, float* dst, int rows, int cols); |
| 37 | - void wrapper(void* src, void** dst); | |
| 37 | + void wrapper(void* src, void** dst, int imgRows, int imgCols); | |
| 38 | 38 | }}} |
| 39 | 39 | |
| 40 | 40 | namespace br |
| ... | ... | @@ -136,7 +136,7 @@ private: |
| 136 | 136 | dstDataPtr[2] = srcDataPtr[2]; *((int*)dstDataPtr[2]) = keep; |
| 137 | 137 | dstDataPtr[3] = srcDataPtr[3]; |
| 138 | 138 | |
| 139 | - cuda::pca::wrapper(srcDataPtr[0], &dstDataPtr[0]); | |
| 139 | + cuda::pca::wrapper(srcDataPtr[0], &dstDataPtr[0], rows, cols); | |
| 140 | 140 | |
| 141 | 141 | dst = dstMat; |
| 142 | 142 | } |
| ... | ... | @@ -150,7 +150,6 @@ private: |
| 150 | 150 | { |
| 151 | 151 | stream >> keep >> drop >> whiten >> originalRows >> mean >> eVals >> eVecs; |
| 152 | 152 | |
| 153 | - // TODO(colin): use Eigen Map class to generate map files so we don't have to copy the data | |
| 154 | 153 | // serialize the eigenvectors |
| 155 | 154 | float* evBuffer = new float[eVecs.rows() * eVecs.cols()]; |
| 156 | 155 | for (int i=0; i < eVecs.rows(); i++) { | ... | ... |
openbr/plugins/cuda/cudapca.cu
| ... | ... | @@ -116,10 +116,15 @@ namespace br { namespace cuda { namespace pca { |
| 116 | 116 | CUDA_SAFE_MEMCPY(data, cudaSrc, rows*cols*sizeof(float), cudaMemcpyDeviceToHost, &err); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - void wrapper(void* src, void** dst) { | |
| 119 | + void wrapper(void* src, void** dst, int imgRows, int imgCols) { | |
| 120 | 120 | cudaError_t err; |
| 121 | 121 | CUDA_SAFE_MALLOC(dst, _evCols*sizeof(float), &err); |
| 122 | 122 | |
| 123 | + if (imgRows*imgCols != _evRows) { | |
| 124 | + cout << "ERR: Image dimension mismatch!" << endl; | |
| 125 | + throw 0; | |
| 126 | + } | |
| 127 | + | |
| 123 | 128 | // subtract out the mean of the image (mean is 1xpixels in size) |
| 124 | 129 | int threadsPerBlock = 64; |
| 125 | 130 | int numBlocks = _meanElems / threadsPerBlock + 1; | ... | ... |