问题描述
我正在 AS3 中寻找一种相当简单的图像比较方法.我从网络摄像头(没有主题)拍摄了一张图像并将其传递给位图数据,然后拍摄了第二张图像(这次是主题)来比较这些数据,我想从这两个图像中创建一个蒙版从在两个位图上匹配的像素.我一直在挠头一段时间,我并没有真正取得任何进展.任何人都可以指出像素比较方法的正确方向,例如 getPixel32()
I am looking for a fairly simple image comparison method in AS3. I have taken an image from a web cam (with no subject) passed it in to bitmap data, then a second image is taken (this time with a subject) to compare this data, from these two images I would like to create a mask from the pixels that match on both bitmaps. I have been scratching my head for a while, and I am not really making any progress. Could any one point me in the right direction for pixel comparison method, something like getPixel32()
干杯
乔诺
推荐答案
use 比较 以创建两者之间的差异,然后使用 treshold 提取您感兴趣的部分.
use compare to create a difference between the two and then use treshold to extract the parts that interest you.
实际上它非常简单.诀窍是使用掩码参数为每个通道多次应用阈值(否则比较没有意义,因为 0x010000
(几乎是黑色)被认为大于 0x0000FF
(不是黑色的)).方法如下:
edit: actually it is pretty straight forward. the trick is to apply the threshold multiple times per channel using the mask parameter (otherwise the comparison only makes little sense, since 0x010000
(which is almost black) is consider greater than 0x0000FF
(which is anything but black)). here's how:
var dif:BitmapData;//your original bitmapdata
var mask:BitmapData = new BitmapData(dif.width, dif.height, true, 0);
const threshold:uint = 0x20;
for (var i:int = 0; i < 3; i++)
mask.threshold(dif, dif.rect, new Point(), ">", threshold << (i * 8), 0xFF000000, 0xFF << (i * 8));
这会创建一个透明的蒙版.然后将阈值应用于所有三个通道,在通道值超过阈值的地方将 alpha 通道设置为完全不透明(您可能想降低它).
this creates a transparent mask. then the threshold is applied for all three channels, setting the alpha channel to fully opaque where the channels value exceeds the threshold value (you might wanna decrease it).
您可以通过 将 alpha 通道从蒙版复制到当前视频图像.
you can isolate the foreground object ("the guy in front of the webcam") by copying the alpha channel from the mask to the current video image.
这篇关于以像素为单位比较 AS3 像素中的位图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!