-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepthAdaptiveSuperpixel.cpp
More file actions
44 lines (43 loc) · 1.54 KB
/
DepthAdaptiveSuperpixel.cpp
File metadata and controls
44 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "DepthAdaptiveSuperpixel.h"
#include <ctime>
DepthAdaptiveSuperpixel::DepthAdaptiveSuperpixel(int width, int height):
SuperpixelSegmentation(width, height),
Intrinsic_Device(cv::gpu::createContinuous(3, 3, CV_32F)){}
DepthAdaptiveSuperpixel::~DepthAdaptiveSuperpixel(){
cudaFree(superpixelCenters_Host);
cudaFree(superpixelCenters_Device);
}
void DepthAdaptiveSuperpixel::SetParametor(int rows, int cols, cv::Mat_<double> intrinsic){
//number of clusters
ClusterNum.x = cols;
ClusterNum.y = rows;
//grid(window) size
Window_Size.x = width/cols;
Window_Size.y = height/rows;
//Init GPU memory
initMemory();
//Random colors
for(int i=0; i<ClusterNum.x*ClusterNum.y; i++){
int3 tmp;
tmp.x = rand()%255;
tmp.y = rand()%255;
tmp.z = rand()%255;
RandomColors[i] = tmp;
}
////////////////////////////////Virtual//////////////////////////////////////////
//set intrinsic mat
cv::Mat_<float> intr;
intrinsic.convertTo(intr, CV_32F);
Intrinsic_Device.upload(intr);
}
void DepthAdaptiveSuperpixel::initMemory(){
//superpixel data
cudaMallocHost(&meanData_Host, sizeof(superpixel) * ClusterNum.x*ClusterNum.y);
cudaMalloc(&meanData_Device, sizeof(superpixel) * ClusterNum.x*ClusterNum.y);
//Random color
RandomColors = new int3[ClusterNum.x*ClusterNum.y];
/////////////////////////////////Virtual/////////////////////////////////////////
//superpixel centers
cudaMallocHost(&superpixelCenters_Host, sizeof(float3) * ClusterNum.x*ClusterNum.y);
cudaMalloc(&superpixelCenters_Device, sizeof(float3) * ClusterNum.x*ClusterNum.y);
}