代码 1
template<typename T>
inline T* get_pointer(cv::Mat &src, int row)
{
return src.ptr<T>(row);
}
template<typename T>
inline T* get_pointer(cv::Mat &src, int row, int col)
{
return get_pointer<T>(src, row) + col * src.channels();
}
template<typename T>
inline T* get_pointer(cv::Mat &src, int row, int col, int channel)
{
return get_pointer<T>(src, row, col) + channel;
}
代码 2
cv::Mat input = //....
auto *input_ptr = get_pointer<float>(input, row, col);
//back to previous row
input_ptr = reinterpret_cast<float*>(reinterpret_cast<uchar*>(input_ptr) - input.steps);
他们安全吗?