简体   繁体   English

OpenCV空二进制图像C ++

[英]OpenCV Empty Binary Image C++

I'm looking to create a binary image in OpenCV where all the values are initialised to 0. I want it to have dimensions 2000x800. 我想在OpenCV中创建一个二进制图像,其中所有值都初始化为0.我希望它的尺寸​​为2000x800。

So far I have: 到目前为止,我有:

Mat canvas(2000, 800, 1)

But I want it so that the values of each pixel can only be a zero or a one. 但我想要它,以便每个像素的值只能是零或一个。

Regards. 问候。

OpenCV does not support bitfields ie Mat's of depth 1 bit. OpenCV不支持位域,即深度为1位的Mat。 There is sound reasoning in this; 这有合理的推理; operating on bitfields is markedly slower because a bit is not an intrinsic operating type for the hardware. 在位域上操作明显较慢,因为位不是硬件的固有操作类型。 Getpixel and setpixel would therefore need extra operations. 因此,getpixel和setpixel需要额外的操作。

Mat canvas = Mat::zeros(800,600,CV_8UC1);

Will create a zero-initialized image of depth 8 bits; 将创建深度为8位的零初始化图像; 7 bits will be wasted. 将浪费7位。

From its documentation , you can declare: 从其文档中 ,您可以声明:

Mat canvas(2000, 800, 1, Scalar(0));

to initiate and fill the canvas with 0. 使用0启动并填充画布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM