|
|
@ -51,11 +51,11 @@ using namespace ocl; |
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
namespace cv |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace ocl |
|
|
|
namespace ocl |
|
|
|
{ |
|
|
|
{ |
|
|
|
////////////////////////////////////OpenCL kernel strings//////////////////////////
|
|
|
|
////////////////////////////////////OpenCL kernel strings//////////////////////////
|
|
|
|
extern const char *kmeans_kernel; |
|
|
|
extern const char *kmeans_kernel; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void generateRandomCenter(const vector<Vec2f>& box, float* center, RNG& rng) |
|
|
|
static void generateRandomCenter(const vector<Vec2f>& box, float* center, RNG& rng) |
|
|
@ -169,7 +169,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void cv::ocl::DistanceComputer(oclMat &dists, oclMat &labels, const oclMat &src, const oclMat ¢ers) |
|
|
|
void cv::ocl::distanceToCenters(oclMat &dists, oclMat &labels, const oclMat &src, const oclMat ¢ers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F)
|
|
|
|
//if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F)
|
|
|
|
//{
|
|
|
|
//{
|
|
|
@ -179,7 +179,7 @@ void cv::ocl::DistanceComputer(oclMat &dists, oclMat &labels, const oclMat &src, |
|
|
|
|
|
|
|
|
|
|
|
Context *clCxt = src.clCxt; |
|
|
|
Context *clCxt = src.clCxt; |
|
|
|
int labels_step = (int)(labels.step/labels.elemSize()); |
|
|
|
int labels_step = (int)(labels.step/labels.elemSize()); |
|
|
|
string kernelname = "kmeansComputeDistance"; |
|
|
|
string kernelname = "distanceToCenters"; |
|
|
|
int threadNum = src.rows > 256 ? 256 : src.rows; |
|
|
|
int threadNum = src.rows > 256 ? 256 : src.rows; |
|
|
|
size_t localThreads[3] = {1, threadNum, 1}; |
|
|
|
size_t localThreads[3] = {1, threadNum, 1}; |
|
|
|
size_t globalThreads[3] = {1, src.rows, 1}; |
|
|
|
size_t globalThreads[3] = {1, src.rows, 1}; |
|
|
@ -307,7 +307,7 @@ double cv::ocl::kmeans(const oclMat &_src, int K, oclMat &_bestLabels, |
|
|
|
k = labels[i]; |
|
|
|
k = labels[i]; |
|
|
|
float* center = centers.ptr<float>(k); |
|
|
|
float* center = centers.ptr<float>(k); |
|
|
|
j=0; |
|
|
|
j=0; |
|
|
|
#if CV_ENABLE_UNROLLED |
|
|
|
#if CV_ENABLE_UNROLLED |
|
|
|
for(; j <= dims - 4; j += 4 ) |
|
|
|
for(; j <= dims - 4; j += 4 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float t0 = center[j] + sample[j]; |
|
|
|
float t0 = center[j] + sample[j]; |
|
|
@ -322,7 +322,7 @@ double cv::ocl::kmeans(const oclMat &_src, int K, oclMat &_bestLabels, |
|
|
|
center[j+2] = t0; |
|
|
|
center[j+2] = t0; |
|
|
|
center[j+3] = t1; |
|
|
|
center[j+3] = t1; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
for( ; j < dims; j++ ) |
|
|
|
for( ; j < dims; j++ ) |
|
|
|
center[j] += sample[j]; |
|
|
|
center[j] += sample[j]; |
|
|
|
counters[k]++; |
|
|
|
counters[k]++; |
|
|
@ -413,7 +413,7 @@ double cv::ocl::kmeans(const oclMat &_src, int K, oclMat &_bestLabels, |
|
|
|
|
|
|
|
|
|
|
|
_bestLabels.upload(_labels); |
|
|
|
_bestLabels.upload(_labels); |
|
|
|
_centers.upload(centers); |
|
|
|
_centers.upload(centers); |
|
|
|
DistanceComputer(_dists, _bestLabels, _src, _centers); |
|
|
|
distanceToCenters(_dists, _bestLabels, _src, _centers); |
|
|
|
|
|
|
|
|
|
|
|
Mat dists; |
|
|
|
Mat dists; |
|
|
|
_dists.download(dists); |
|
|
|
_dists.download(dists); |
|
|
|