void HybKinectfu::copyFrameToGPU(const DepthFrameData& depth_frame,const ColorFrameData& color_frame) { cv::Mat mat_depth=depth_frame.mat(); int rows=mat_depth.rows,cols=mat_depth.cols; DepthfMap2D depth_data_cpu(CPU,cols,rows); depth_data_cpu.clearData(); for(int row=0;row<rows;row++) { for(int col=0;col<cols;col++) { float v=mat_depth.at<unsigned short>(row,col)*0.001;//millimeter to meters depth_data_cpu.at(col,row)=v; } } CudaDeviceDataMan::instance()->raw_depth.copyDataFrom(depth_data_cpu); if(AppParams::instance()->_switch_params.useRGBData) { cv::Mat mat_rgb=color_frame.mat(); rows=color_frame.mat().rows,cols=color_frame.mat().cols; Color3uMap2D rgb_data_cpu(CPU,cols,rows); rgb_data_cpu.clearData(); for(int row=0;row<rows;row++) { for(int col=0;col<cols;col++) { cv::Vec3b v=mat_rgb.at<cv::Vec3b>(row,col); rgb_data_cpu.at(col,row)=make_uchar3(v[0],v[1],v[2]); } } CudaDeviceDataMan::instance()->raw_rgb.copyDataFrom(rgb_data_cpu); } }
static inline __host__ __device__ uchar3 _pixMake(Ncv8u x, Ncv8u y, Ncv8u z) {return make_uchar3(x,y,z);}
template<> inline __host__ __device__ uchar3 _pixMakeZero<uchar3>() {return make_uchar3(0,0,0);}
int main(int argc, char** argv) { std::cout << "Starting iu_image_cpu_unittest ..." << std::endl; // test image size IuSize sz(79,63); iu::ImageCpu_8u_C1 im_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 im_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 im_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 im_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 im_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 im_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 im_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 im_cpu_32f_C4(sz); unsigned char set_value_8u_C1 = 1; uchar2 set_value_8u_C2 = make_uchar2(2,2); uchar3 set_value_8u_C3 = make_uchar3(3,3,3); uchar4 set_value_8u_C4 = make_uchar4(4,4,4,4); float set_value_32f_C1 = 1.1f; float2 set_value_32f_C2 = make_float2(2.2f); float3 set_value_32f_C3 = make_float3(3.3f); float4 set_value_32f_C4 = make_float4(4.4f); // set values test { std::cout << "testing setValue on cpu ..." << std::endl; iu::setValue(set_value_8u_C1, &im_cpu_8u_C1, im_cpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_cpu_8u_C2, im_cpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_cpu_8u_C3, im_cpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_cpu_8u_C4, im_cpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_cpu_32f_C1, im_cpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_cpu_32f_C2, im_cpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_cpu_32f_C3, im_cpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_cpu_32f_C4, im_cpu_32f_C4.roi()); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // copy test { std::cout << "testing copy cpu -> cpu ..." << std::endl; iu::ImageCpu_8u_C1 cp_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 cp_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 cp_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 cp_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 cp_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 cp_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 cp_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 cp_cpu_32f_C4(sz); iu::copy(&im_cpu_8u_C1, &cp_cpu_8u_C1); iu::copy(&im_cpu_8u_C2, &cp_cpu_8u_C2); iu::copy(&im_cpu_8u_C3, &cp_cpu_8u_C3); iu::copy(&im_cpu_8u_C4, &cp_cpu_8u_C4); iu::copy(&im_cpu_32f_C1, &cp_cpu_32f_C1); iu::copy(&im_cpu_32f_C2, &cp_cpu_32f_C2); iu::copy(&im_cpu_32f_C3, &cp_cpu_32f_C3); iu::copy(&im_cpu_32f_C4, &cp_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { if( *cp_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *cp_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *cp_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *cp_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; if( *cp_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *cp_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *cp_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *cp_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } std::cout << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << "* Everything seem to be ok. -- All assertions passed. *" << std::endl; std::cout << "* Look at the images and close the windows to derminate the unittests. *" << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << std::endl; return EXIT_SUCCESS; }
int main(int argc, char** argv) { std::cout << "Starting iu_image_gpu_unittest ..." << std::endl; // test image size IuSize sz(79,63); iu::ImageGpu_8u_C1 im_gpu_8u_C1(sz); iu::ImageGpu_8u_C2 im_gpu_8u_C2(sz); iu::ImageGpu_8u_C3 im_gpu_8u_C3(sz); iu::ImageGpu_8u_C4 im_gpu_8u_C4(sz); iu::ImageGpu_32f_C1 im_gpu_32f_C1(sz); iu::ImageGpu_32f_C2 im_gpu_32f_C2(sz); iu::ImageGpu_32f_C3 im_gpu_32f_C3(sz); iu::ImageGpu_32f_C4 im_gpu_32f_C4(sz); unsigned char set_value_8u_C1 = 1; uchar2 set_value_8u_C2 = make_uchar2(2,2); uchar3 set_value_8u_C3 = make_uchar3(3,3,3); uchar4 set_value_8u_C4 = make_uchar4(4,4,4,4); float set_value_32f_C1 = 1.1f; float2 set_value_32f_C2 = make_float2(2.2f); float3 set_value_32f_C3 = make_float3(3.3f); float4 set_value_32f_C4 = make_float4(4.4f); // copy values back to cpu to compare the set values iu::ImageCpu_8u_C1 im_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 im_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 im_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 im_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 im_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 im_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 im_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 im_cpu_32f_C4(sz); // set values on cpu and copy to gpu and back again { std::cout << "Testing copy. setValue on cpu (should work because of previous test) and copy forth and back" << std::endl; iu::setValue(set_value_8u_C1, &im_cpu_8u_C1, im_cpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_cpu_8u_C2, im_cpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_cpu_8u_C3, im_cpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_cpu_8u_C4, im_cpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_cpu_32f_C1, im_cpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_cpu_32f_C2, im_cpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_cpu_32f_C3, im_cpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_cpu_32f_C4, im_cpu_32f_C4.roi()); std::cout << " copy cpu -> gpu ..." << std::endl; iu::copy(&im_cpu_8u_C1, &im_gpu_8u_C1); iu::copy(&im_cpu_8u_C2, &im_gpu_8u_C2); iu::copy(&im_cpu_8u_C3, &im_gpu_8u_C3); iu::copy(&im_cpu_8u_C4, &im_gpu_8u_C4); iu::copy(&im_cpu_32f_C1, &im_gpu_32f_C1); iu::copy(&im_cpu_32f_C2, &im_gpu_32f_C2); iu::copy(&im_cpu_32f_C3, &im_gpu_32f_C3); iu::copy(&im_cpu_32f_C4, &im_gpu_32f_C4); std::cout << " copy gpu -> cpu ..." << std::endl; iu::copy(&im_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&im_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&im_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&im_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&im_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&im_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&im_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&im_gpu_32f_C4, &im_cpu_32f_C4); std::cout << " check copied values on cpu ..." << std::endl; // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // set values on gpu { std::cout << "Testing setValue on gpu (implecitely testing copy gpu->cpu) ..." << std::endl; iu::setValue(set_value_8u_C1, &im_gpu_8u_C1, im_gpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_gpu_8u_C2, im_gpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_gpu_8u_C3, im_gpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_gpu_8u_C4, im_gpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_gpu_32f_C1, im_gpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_gpu_32f_C2, im_gpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_gpu_32f_C3, im_gpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_gpu_32f_C4, im_gpu_32f_C4.roi()); std::cout << "Copy gpu images to cpu for checking the set values." << std::endl; iu::copy(&im_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&im_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&im_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&im_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&im_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&im_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&im_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&im_gpu_32f_C4, &im_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // copy gpu -> gpu test { std::cout << "testing copy gpu -> gpu ..." << std::endl; iu::ImageGpu_8u_C1 cp_gpu_8u_C1(sz); iu::ImageGpu_8u_C2 cp_gpu_8u_C2(sz); iu::ImageGpu_8u_C3 cp_gpu_8u_C3(sz); iu::ImageGpu_8u_C4 cp_gpu_8u_C4(sz); iu::ImageGpu_32f_C1 cp_gpu_32f_C1(sz); iu::ImageGpu_32f_C2 cp_gpu_32f_C2(sz); iu::ImageGpu_32f_C3 cp_gpu_32f_C3(sz); iu::ImageGpu_32f_C4 cp_gpu_32f_C4(sz); iu::copy(&im_gpu_8u_C1, &cp_gpu_8u_C1); iu::copy(&im_gpu_8u_C2, &cp_gpu_8u_C2); iu::copy(&im_gpu_8u_C3, &cp_gpu_8u_C3); iu::copy(&im_gpu_8u_C4, &cp_gpu_8u_C4); iu::copy(&im_gpu_32f_C1, &cp_gpu_32f_C1); iu::copy(&im_gpu_32f_C2, &cp_gpu_32f_C2); iu::copy(&im_gpu_32f_C3, &cp_gpu_32f_C3); iu::copy(&im_gpu_32f_C4, &cp_gpu_32f_C4); iu::copy(&cp_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&cp_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&cp_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&cp_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&cp_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&cp_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&cp_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&cp_gpu_32f_C4, &im_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } std::cout << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << "* Everything seem to be ok. -- All assertions passed. *" << std::endl; std::cout << "* Look at the images and close the windows to derminate the unittests. *" << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << std::endl; return EXIT_SUCCESS; }