OpenCV空二进制图像C ++ [英] OpenCV Empty Binary Image C++
问题描述
我想在OpenCV中创建一个二进制图像,所有的值都初始化为0.我想要它的尺寸为2000x800。
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.
到目前为止,我有:
Mat canvas(2000, 800, 1)
但我想要的是,每个像素的值只能是零或一个。
But I want it so that the values of each pixel can only be a zero or a one.
推荐答案
OpenCV不支持位域,即深度为1位的Mat。这里有正确的推理;对位域的操作明显较慢,因为位不是硬件的固有操作类型。因此,Getpixel和setpixel需要额外的操作。
OpenCV does not support bitfields i.e. Mat's of depth 1 bit. 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.
Mat canvas = Mat::zeros(800,600,CV_8UC1);
将创建深度为8位的零初始化图像; 7位将被浪费。
Will create a zero-initialized image of depth 8 bits; 7 bits will be wasted.
这篇关于OpenCV空二进制图像C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!