Skip to content

Instantly share code, notes, and snippets.

@mryssng
Last active September 16, 2022 04:27
Show Gist options
  • Save mryssng/f43c9ae4cae13b204855e108a004c73a to your computer and use it in GitHub Desktop.
Save mryssng/f43c9ae4cae13b204855e108a004c73a to your computer and use it in GitHub Desktop.
Convert cv::Mat to std::vector in OpenCV
// https://stackoverflow.com/questions/26681713/convert-mat-to-array-vector-in-opencv
std::vector<uchar> array;
if (mat.isContinuous()) {
array.assign((uchar*)mat.datastart, (uchar*)mat.dataend);
} else {
for (int i = 0; i < mat.rows; ++i) {
array.insert(array.end(), mat.ptr<uchar>(i), mat.ptr<uchar>(i)+mat.cols);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment