深度图像帧差法处理以及CV16UC1深度图像的存储方式

最近为了拾取桌面上的任务目标,采用了实时图像与背景图像相减的方法来进行,因为采用彩色图像相减会有影子的干扰,所以采用了深度图像。

但是深度图像的Mat是CV16UC1格式的,矩阵内部数据采用uint_16格式存储,开始我用imwrite保存了png格式的深度图像并读取,但是在后续处理中发现没有起到差值的效果,经过各种折腾,终于发现问题在于png格式最多就是uint_8的数据存储格式,所以导致读取的深度图像值不正确。因此我把深度图像保存为xml格式,再读取,问题解决。

附上深度图像保存为xml格式的代码:

cv::FileStorage fs("./depth.xml", cv::FileStorage::WRITE);  
 fs<<"vocabulary"<<depth;  
 fs.release();  

读取xml的代码:

 cv::FileStorage fs("//catkin_ws//depth.xml", cv::FileStorage::READ);  
     Mat pre_de;  
     fs["vocabulary"] >> pre_de;  

此处参考自:https://blog.csdn.net/qq_29573053/article/details/79010420

另外附上帧差法的处理代码,通过指针进行处理:

 for(int r = 0; r < depth.rows; ++r)
	  {
		  const uint16_t *itI1 = depth.ptr<uint16_t>(r); //实时深度图像depth
		  const uint16_t *itI2 = pre_de.ptr<uint16_t>(r);//背景图像pre_de
		  uint8_t *itO = deff_de.ptr<uint8_t>(r);
		  for(int c = 0; c <depth.cols; ++c, ++itI1, ++itI2,++itO)
		  {
			
				*itO = (uint8_t)abs(*itI1-*itI2);
		  }
	  }

猜你喜欢

转载自blog.csdn.net/qq_23670601/article/details/81452341
今日推荐