Last active
September 16, 2022 04:27
-
-
Save mryssng/f43c9ae4cae13b204855e108a004c73a to your computer and use it in GitHub Desktop.
Convert cv::Mat to std::vector in OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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