加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 设置cv :: Mat的深度

发布时间:2020-12-16 03:40:11 所属栏目:百科 来源:网络整理
导读:我想测试一个寻找特定垫深度amp ;;的功能.频道数量 它有一个测试…… if (image.channels() == 1 image.depth() == 8) ...else if (image.channels() == 1 image.depth() == 16) ...else if (image.channels() == 1 image.depth() == 32) ...else{ if ((imag
我想测试一个寻找特定垫深度&&amp ;;的功能.频道数量

它有一个测试……

if (image.channels() == 1 && image.depth() == 8) ...
else if (image.channels() == 1 && image.depth() == 16)  ...
else if (image.channels() == 1 && image.depth() == 32)  ...
else
{  
  if ((image.channels() != 3) || (image.depth() != 8)) 
  {printf("Expecting rgb24 input image"); return false;}
  ...
}

我更喜欢用化妆垫进行测试,以避免使用本地资源:

cv::Mat M(255,255,CV_8UC3,cv::Scalar(0,255));
printf("M: %d %d n",M.channels(),M.depth());
cv::Mat M1(255,CV_32F,255));
cv::Mat M2(255,CV_32FC3,CV_8SC3,255));

我已经尝试了各种组合,但如果我打印,我得到0深度.

我也尝试加载一个png或一个jpg文件 – 结果相同(我不喜欢使用外部文件……但我看不出为什么这不起作用)

cv::Mat M3 = cv::imread( "c:/my_image.png",CV_LOAD_IMAGE_COLOR );
cv::Mat M3 = cv::imread( "c:/my_image.jpg",CV_LOAD_IMAGE_COLOR );

它们似乎都有深度= 0?

我还有别的办法吗?我在文档中看不到任何内容……

谢谢

解决方法

在Mat上调用depth()时,它会返回下面定义的深度值而不是位数:
#define CV_8U   0
#define CV_8S   1
#define CV_16U  2
#define CV_16S  3
#define CV_32S  4
#define CV_32F  5
#define CV_64F  6

你可以使用cv :: DataDepth :: value来确定哪一个是哪一个.例如,

cv::DataDepth<unsigned char>::value == CV_8U;
cv::DataDepth<float>::value == CV_32F;

所以你应该在所有CV_8UCX矩阵上得到0,当你加载图像时,它通常被加载为CV_8UC3,所以你也会得到0.但我不知道你为什么在cv :: Mat M(255,CV_32FC3)上得到0,我在我的电脑上测试了它,它返回了5.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读