【发布时间】:2015-05-26 01:03:13
【问题描述】:
以下代码是来自 PCL(点云)库的 sn-p。它计算图像的积分和。
template <class DataType, unsigned Dimension> class IntegralImage2D
{
public:
static const unsigned dim_fst = Dimension;
typedef cv::Vec<typename TypeTraits<DataType>::IntegralType, dim_fst> FirstType;
std::vector<FirstType> img_fst;
//.... lots of methods missing here that actually calculate the integral sum
/** \brief Compute the first order sum within a given rectangle
* \param[in] start_x x position of rectangle
* \param[in] start_y y position of rectangle
* \param[in] width width of rectangle
* \param[in] height height of rectangle
*/
inline FirstType getFirstOrderSum(unsigned start_x, unsigned start_y, unsigned width, unsigned height) const
{
const unsigned upper_left_idx = start_y * (wdt + 1) + start_x;
const unsigned upper_right_idx = upper_left_idx + width;
const unsigned lower_left_idx =(start_y + height) * (wdt + 1) + start_x;
const unsigned lower_right_idx = lower_left_idx + width;
return(img_fst[lower_right_idx] + img_fst[upper_left_idx] - img_fst[upper_right_idx] - img_fst[lower_left_idx]);
}
目前使用以下代码获取结果:
IntegralImage2D<float,3> iim_xyz;
IntegralImage2D<float, 3>::FirstType fo_elements;
IntegralImage2D<float, 3>::SecondType so_elements;
fo_elements = iim_xyz.getFirstOrderSum(pos_x - rec_wdt_2, pos_y - rec_hgt_2, rec_wdt, rec_hgt);
so_elements = iim_xyz.getSecondOrderSum(pos_x - rec_wdt_2, pos_y - rec_hgt_2, rec_wdt, rec_hgt);
但是我正在尝试并行化代码(将 getFirstOrderSum 编写为 CUDA 设备函数)。由于 CUDA 无法识别这些 FirstType 和 SecondType 对象(或任何与之相关的 opencv 对象),我正在努力(我是 C++ 新手)从模板中提取原始数据。
如果可能的话,我想将 img_fst 对象转换为可以在 cuda 内核上分配的某种向量或数组。
img_fst 的类型似乎是std::vector<cv::Matx<double,3,1>
【问题讨论】:
-
可能与您的问题没有直接关系,但npp library 提供了计算积分图像的方法。
-
您似乎在寻找
Mat::ptr。 -
@Jarod42:你能详细说明一下吗?那是 mat 而不是 vec 对吧?
-
我读到,
Vec是Mat的别名,Mat有ptr,这似乎相当于std::vector::data(),它返回指向包含数据的连续内存的指针。 -
是的,但在这种情况下,它是 Matx 的别名,遗憾的是没有提供这样的指针