src/python/dbow.cc
// Allows float32 or uint8. Zero copy.
Allows float32 or uint8. Zero copy.
Allows float32 or uint8 . Zero copy .
cv::Mat buf2mat(const py::buffer &b) {
  auto info = b.request();
  int rows = info.ndim == 1 ? 1 : info.shape[0];
  int cols = info.ndim > 1 ? info.shape[1]
                           : info.shape[0]; 
  assert(info.format == py::format_descriptor<float>::format() or
         info.format == py::format_descriptor<uint8_t>::format());
  auto type =
      info.format == py::format_descriptor<float>::format() ? CV_32F : CV_8U;
  cv::Mat buf(rows, cols, type, info.ptr);
  return buf;
}
cv :: Mat buf2mat ( const py :: buffer & b ) { auto info = b . request ( ) ; int rows = info . ndim == 1 ? 1 : info . shape [ 0 ] ; int cols = info . ndim > 1 ? info . shape [ 1 ] : info . shape [ 0 ] ; assert ( info . format == py :: format_descriptor < float > :: format ( ) or info . format == py :: format_descriptor < uint8_t > :: format ( ) ) ; auto type = info . format == py :: format_descriptor < float > :: format ( ) ? CV_32F : CV_8U ; cv :: Mat buf ( rows , cols , type , info . ptr ) ; return buf ; }
Allows float32 or uint8.
Allows float32 or uint8 .
// 1d input is a row vector. // std::cout << " making mat: " << buf.rows << " " << buf.cols << " " << // buf.type() << "\n";