深度图转激光原理
深度圖轉激光在ROS包depthimage_to_laserscan中實現,本篇講解其計算過程。關于點云轉激光數據的思路也是類似的,只需要將一定高度范圍內的數據進行投影即可。
1. 深度圖轉激光原理
原理如圖(1)所示。深度圖轉激光中,對任意給定的一個深度圖像點m(u,v,z),其轉換激光的步驟為:
a.將深度圖像的點m(u,v,z)轉換到深度相機坐標系下的坐標點M(x,y,z),具體求解過程請參考“深度圖轉點云的原理”;
b.計算直線AO和CO的夾角AOC,計算公式如下:
c.將角AOC影射到相應的激光數據槽中.已知激光的最小最大范圍[α,β],激光束共細分為N分,那么可用數組laser[N]表示激光數據。那么點M投影到數組laser中的索引值n可如下計算:
laser[n]的值為M在x軸上投影的點C到相機光心O的距離r,即?
?
?
2. 代碼
以下為添加注釋說明的實現代碼(另可參閱原始代碼),
/*** Converts the depth image to a laserscan using the DepthTraits to assist.* * This uses a method to inverse project each pixel into a LaserScan angular increment. This method first projects the pixel* forward into Cartesian coordinates, then calculates the range and angle for this point. When multiple points coorespond to* a specific angular measurement, then the shortest range is used.* * @param depth_msg The UInt16 or Float32 encoded depth message.* @param cam_model The image_geometry camera model for this image.* @param scan_msg The output LaserScan.* @param scan_height The number of vertical pixels to feed into each angular_measurement.* */template<typename T>void convert(const sensor_msgs::ImageConstPtr& depth_msg, const image_geometry::PinholeCameraModel& cam_model, const sensor_msgs::LaserScanPtr& scan_msg, const int& scan_height) const{// Use correct principal point from calibrationfloat center_x = cam_model.cx();//圖像中心位置xfloat center_y = cam_model.cy();//圖像中心位置y// Combine unit conversion (if necessary) with scaling by focal length for computing (X,Y)double unit_scaling = depthimage_to_laserscan::DepthTraits<T>::toMeters( T(1) );float constant_x = unit_scaling / cam_model.fx();float constant_y = unit_scaling / cam_model.fy();const T* depth_row = reinterpret_cast<const T*>(&depth_msg->data[0]);int row_step = depth_msg->step / sizeof(T);int offset = (int)(cam_model.cy()-scan_height/2);depth_row += offset*row_step; // Offset to center of imagefor(int v = offset; v < offset+scan_height_; v++, depth_row += row_step){for (int u = 0; u < (int)depth_msg->width; u++) // Loop over each pixel in row{ T depth = depth_row[u];double r = depth; // Assign to pass through NaNs and Infsdouble th = -atan2((double)(u - center_x) * constant_x, unit_scaling); // 計算夾角AOC,Atan2(x, z),實際上這里省略了深度值,因為分子分母都有,所以就略去了 but depth divides outint index = (th - scan_msg->angle_min) / scan_msg->angle_increment;//計算對應激光數據的索引if (depthimage_to_laserscan::DepthTraits<T>::valid(depth)){ // Not NaN or Inf// Calculate in XYZ,計算XYZdouble x = (u - center_x) * depth * constant_x;double z = depthimage_to_laserscan::DepthTraits<T>::toMeters(depth);// Calculate actual distance,計算激光的真實距離r = sqrt(pow(x, 2.0) + pow(z, 2.0));}// Determine if this point should be used.判斷激光距離是否超出預設的有效范圍if(use_point(r, scan_msg->ranges[index], scan_msg->range_min, scan_msg->range_max)){scan_msg->ranges[index] = r;}}}}image_geometry::PinholeCameraModel cam_model_; ///< image_geometry helper class for managing sensor_msgs/CameraInfo messages.float scan_time_; ///< Stores the time between scans.float range_min_; ///< Stores the current minimum range to use.float range_max_; ///< Stores the current maximum range to use.int scan_height_; ///< Number of pixel rows to use when producing a laserscan from an area.std::string output_frame_id_; ///< Output frame_id for each laserscan. This is likely NOT the camera's frame_id.};?
?
?
深圳辰視智能科技有限公司
?
深圳辰視智能科技有限公司是一家提供機器視覺、工業智能化設備的國家高新技術企業,是由中國科學院機器視覺技術研究團隊創立,公司擁有快速三維建模、機器人運動控制、工件目標的分類與6D識別等方面的核心技術。
公司的主要產品有:機器人三維視覺引導系統、深度學習分類與檢測系統、二維/三維視覺定位系統等,產品解決了機器人沒有視覺感知與目標識別功能,影響機器人便捷應用的關鍵問題;使機器人擁有“雙眼”和“大腦”。
目前,公司產品已廣泛應用到自動上下料、組裝、分類分揀、鑄造、噴涂與焊接引導等多種不同工業場景,極大地提高生產效果、節約人力成本。
深圳辰視智能科技有限公司專注于工業視覺應用領域,致力于技術的不斷研究、創新、突破,為合作伙伴提供全球領先的機器視覺產品及技術。
?
更多資訊, 聯系我們!
聯系方式:0755-26920296? ?199 2871 0160 /? 181 2401 9365
www.cosmosvisiontech.com
sales@cosmosai.cn
?
?
?
?
?
?
總結
- 上一篇: 医药板块走势强劲
- 下一篇: CF 472D Riverside Cu