Skip to content

Instantly share code, notes, and snippets.

@shimat
Created August 7, 2021 04:05
Show Gist options
  • Save shimat/cacf19ffb2ec3d64c20909f7799c4e35 to your computer and use it in GitHub Desktop.
Save shimat/cacf19ffb2ec3d64c20909f7799c4e35 to your computer and use it in GitHub Desktop.
OpenCV 空のMatに対するMat.cloneではdepthがセットされない
#include <iostream>
#include <opencv2/opencv.hpp>
int main()
{
{
cv::Mat src(0, 0, CV_32SC1);
auto dst = src.clone();
std::cout << "Mat" << std::endl
<< "src: depth=" << src.depth() << ", channels=" << src.channels() << std::endl
<< "dst: depth=" << dst.depth() << ", channels=" << dst.channels() << std::endl;
}
{
cv::Mat_<int> src(0, 0);
auto dst = src.clone();
std::cout << "Mat_<T>" << std::endl
<< "src: depth=" << src.depth() << ", channels=" << src.channels() << std::endl
<< "dst: depth=" << dst.depth() << ", channels=" << dst.channels() << std::endl;
}
return 0;
}
@shimat
Copy link
Author

shimat commented Aug 7, 2021

Mat
src: depth=4, channels=1
dst: depth=0, channels=1
Mat_<T>
src: depth=4, channels=1
dst: depth=4, channels=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment