Skip to content

Instantly share code, notes, and snippets.

@JinhaiZ
Last active February 8, 2018 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JinhaiZ/59404ae850c668bff5d8bf1a680f53da to your computer and use it in GitHub Desktop.
Save JinhaiZ/59404ae850c668bff5d8bf1a680f53da to your computer and use it in GitHub Desktop.
c++ opencv manipulation
  1. get the size of a multi-dimensional cv::Mat
std::cout << "cvMat.dims = " << cvMat.dims << "cvMat.size = [";
for(int i = 0; i < cvMat.dims; ++i) {
    if(i) std::cout << " X ";
    std::cout << cvMat.size[i];
}
std::cout << "] cvMat.channels = " << cvMat.channels() << std::endl;
  1. save cv::Mat to bmp
std::ostringstream filename;
filename << "./save/pic-" << sequence++ << ".bmp";
std::string fileName = filename.str();
imwrite(fileName, cvMat);

std::ostringstream debug;
debug << "saved: " << filename.str() << "\n";
std::cout << debug.str();
  1. print uchar array as int
  for (int i = 0; i < 4800; i++) {
    printf("%u ", (unsigned) buffer[i]);
    if (i%80 == 0) {
      printf("\n");
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment