我正在尝试使用 opencv 创建一个遵循正态分布的 20X20 图像,我知道有一个 randn 函数可以让我做类似的事情,但是如果我打算的话,我应该如何去做呢在我尝试创建的图像数据中嵌入字符串?
最佳答案
在此处查看均匀到高斯随机数:http://www.design.caltech.edu/erik/Misc/Gaussian.html
如果您想将最后 2 个数据位(最低有效位)用于隐藏文本,则需要在噪声图像中将它们设置为零。
接下来,创建 3 个图像:
Image noise, mask, textimg
AddNoiseTo(noise) // any kind of noise you want
SetEveryPixel(mask,unsigned char, 255-3)
CvAnd(noise,mask,noise) // to remove noise from the last 2 bits
cvPutText(textimg,yourtext,white);
CvNot(mask,mask) // invert the mask to remove data from the first 6 bits
CvAnd(textimg,mask,textimg) // filter the text image so only last 2 bits are kept
CvOr(noise,textimg,outputimg) // this will merge the two images
如果您想要 7 个数据位(以便更容易用肉眼看到文本),请从掩码中减去 127(二进制为 7 个 1),而不是 3(二进制为 11)。
关于c++ - 使用 OpenCV C++ 创建遵循高斯分布的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14275939/