Example #1
0
void game::loadDepth(std::string filename)
{
    wxImage depthimage(filename, wxBITMAP_TYPE_PNG);
    oceandepthbuffer = new float[2048];
    for (unsigned i = 0; i < 2048; i++)
    {
        float xpos = i / 16.f;
        oceandepthbuffer[i] = depthimage.GetRed(floorf(xpos), 0) * (floorf(xpos) - xpos) + depthimage.GetRed(ceilf(xpos), 0) * (1 - (floorf(xpos) - xpos))
                            ;//+ depthimage.GetGreen(i % 256, 0) * 0.0625f;
        oceandepthbuffer[i] = oceandepthbuffer[i] * 1.f - 180.f;
    }
}
Example #2
0
SceneGraph::DepthImageNode *GuiNodeFactory::createDepthImageNode(const QString &filename, SceneGraph::Node *parent)
{
    if(!parent) return NULL;

    Plugins::ImageIOInterface* imageio_plugin =  mainapplication_.getPluginManager()->getImportImagePluginByFilename(filename);
    if(!imageio_plugin) return NULL;
    std::shared_ptr<DepthImage> depthimage(new DepthImage());
    if(imageio_plugin->importDepthImage(filename,depthimage))
    {
        depthimage->normalize();
        SceneGraph::DepthImageNode* pPointer = new SceneGraph::DepthImageNode(depthimage,parent);
        pPointer->nodeUpdated(Totally_Dirty);
        return pPointer;
    }
    return NULL;
}
Example #3
0
//---------------------------------------------------------------
void testApp::update() {
	ofBackground(100, 100, 100);
	NUI_IMAGE_FRAME pImageFrame = {0};
	NUI_LOCKED_RECT locked_rect = {0};
	if(bKinectInitSucessful)
	{
		HRESULT hr=m_nui->NuiImageStreamGetNextFrame(depthStreamHandle,0,&pImageFrame);
		if (SUCCEEDED(hr))
		{
			hr=pImageFrame.pFrameTexture->LockRect(0,&locked_rect,NULL,0);
				if(locked_rect.Pitch!=0) {

				// 将数据存入Mat中
				cv::Mat depthimage(KINECT_HEIGHT,KINECT_WIDTH,CV_8UC1);
				//cv::Mat depthimage2(KINECT_HEIGHT,KINECT_WIDTH,CV_8UC1);
				if(test)
				{
					for (int i=0; i<depthimage.rows; i++) 
					{
						uchar *ptr = depthimage.ptr<uchar>(i);  //第i行的指针
						//uchar *ptr2 = depthimage2.ptr<uchar>(i);
						uchar *pBufferRun = (uchar*)(locked_rect.pBits) + i * locked_rect.Pitch;
						USHORT *pBuffer = (USHORT*) pBufferRun;					 
						for (int j=0; j<depthimage.cols; j++) 
						{
							pBuffer[j]=pBuffer[j]>>3;
							ptr[j]=(uchar)(256*pBuffer[j]/0x0fff); //直接将数据归一化处理
							//ptr2[j]=(uchar)(256*depth_float[i*depthimage.cols+j]/0x0fff);
						} 
					}
				//test=false;
				}		
				cv::imshow("orginal",depthimage);
				//cv::imshow("sss",depthimage2);			
				cv::Mat depthimage_filter = depthimage.clone();
			
				// 读取照片		
	            #if 0
				const int photonumMax = 1;
				if(photonum < photonumMax)
				{
					char namebuffer[20];
					sprintf(namebuffer,"%d.jpg",photonum);
					string name = namebuffer;
					depthimage_filter = cv::imread(name,CV_LOAD_IMAGE_GRAYSCALE);
					++photonum;
				}
	            #endif

				// 滤波 双边滤波效果没出现(?)
				//cv::medianBlur(depthimage,depthimage_filter,5);
				//clock_t t1=clock();
				cv::bilateralFilter(depthimage,depthimage_filter,11,20,20);
				//clock_t t2=clock();
				//double ti=(double)(t2-t1)/CLOCKS_PER_SEC;
				//cout<<ti<<endl;
				//cv::GaussianBlur(depthimage,depthimage_filter,cv::Size(5,5),0,0);
				//cv::imshow("filter",depthimage_filter);

				// 保存照片
	            #if 0 
				if(photonum < photonumMax)
				{
					char namebuffer[20];
					sprintf(namebuffer,"%d.jpg",photonum);
					string name = namebuffer;
					cv::imwrite(name,depthimage);
					++photonum;
				}
	            #endif

				// pyramid creat 高斯降采 论文中提到避免边界被平滑未处理(?)
		
				//cv::Mat downmap1;
				//cv::pyrDown(depthimage_filter,downmap1,cv::Size(depthimage_filter.cols/2,depthimage_filter.rows/2));
				//cv::imshow("downonce",downmap1);
				//cv::Mat downmap2;
				//cv::pyrDown(downmap1,downmap2,cv::Size(downmap1.cols/2,downmap1.rows/2));
				//cv::imshow("downtwice",downmap2);
		
				// 滤波后深度数据提取与单位转换
			
				//ofstream out;
				//if(photonum < photonumMax&&test3)
				//{
				//	char namebuffer[10];
				//	sprintf(namebuffer,"%d.txt",photonum);
				//	out.open(namebuffer,ios::trunc);
				//}
				for (int i=0; i<depthimage_filter.rows; i++) 
				{
					uchar *ptr = depthimage_filter.ptr<uchar>(i);  //第i行的指针			 
					for (int j=0; j<depthimage_filter.cols; j++) 
					{
						float s = (float)(ptr[j]*0x0fff)/256;
						//if(s>2500&&s<2600)
						//{
						//	cout<<s<<endl;
						//}
						depth_float[i*depthimage_filter.cols+j] = s/1000;//显示点云用,计算时要除1000,化为米单位
						//if(test3)
						//	out<<s<<" ";				
					}
				}
				//out.close();
				test3 = false;

				// 试验区
				ofMatrix4x4 tk=ofMatrix4x4(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1);
				ofMatrix4x4 tk_next = tk;
				ofVec4f camp = ofVec4f(0,0,0,1);
				int size_g = TSDF_SIZE;
				const int maxcountnum = 3;
				if(countnum < maxcountnum)
				{
					//compute_tsdf(tk,depthimage,size_g,camp);
					++ countnum;
					if(countnum == maxcountnum)
						test2 = true;
				//}
				//if(test2)
				//{
					//cv::imwrite("original.jpg",depthimage_filter);
					//cout<<tk<<endl;
					clock_t t1=clock();
					compute_points(depthimage_filter,depthimage_filter.rows,depthimage_filter.cols,pointsmap_orignal);
					compute_tsdf(tk_next,depthimage,size_g,camp);
					compute_raycast(tk_next);
					compute_normal(pointsmap_orignal,depthimage_filter.rows,depthimage_filter.cols,normalmap_orignal);
					//compute_normal(pointsmap_final,depthimage_filter.rows,depthimage_filter.cols,normalmap_final);

					for(int i = 0;i < 10; ++ i)
					{
						compute_pda(tk,i,tk_next);
					}
					camp = tk_next * camp;
					tk = tk_next;
					//changePosition(tk_next,pointsmap_orignal,normalmap_orignal);
					clock_t t2=clock();
					double ti=(double)(t2-t1)/CLOCKS_PER_SEC;
					std::cout<<ti<<endl;
					//test2=false;
				}

				// 转换坐标系为摄像机坐标系与法向

				//changeType(depthimage_filter,depthimage_filter.rows,depthimage_filter.cols);//无用了
				//compute_points(depthimage_filter,depthimage_filter.rows,depthimage_filter.cols,pointsmap_orignal);
				//compute_points(downmap1,downmap1.rows,downmap1.cols,pointsmap_downonce);
				//compute_points(downmap2,downmap2.rows,downmap2.cols,pointsmap_downtwice);
				//
				//compute_normal(pointsmap_orignal,depthimage_filter.rows,depthimage_filter.cols,normalmap_orignal);
				//compute_normal(pointsmap_downonce,downmap1.rows,downmap1.cols,normalmap_downonce);
				//compute_normal(pointsmap_downtwice,downmap2.rows,downmap2.cols,normalmap_downtwice);

				if(bThreshWithOpenCV) { 
				} else {
				}
			}
			m_nui->NuiImageStreamReleaseFrame(depthStreamHandle,&pImageFrame);
		}
	}