Comparing two BitmapData in ActionScript 3

烂漫一生 提交于 2019-12-12 03:23:36

问题


I'd like to know if there's anyway I can compare two BitmapData and get a "similarity percentage" (knowing how look-alike they are). I've done a bit of research and came across bitmapData.compare(otherBmd), but that only returns if they differ in size, or pixel, and not how much they differ.

The point of this was to compare some Bmd obtained through a camera with a library image (so this is what I got so far):

import flash.display.Bitmap;
import flash.display.BitmapData;

var img1:BitmapData = new monaLisa(); 

var cam:Camera = Camera.getCamera();
var video:Video = new Video(camMock.width,camMock.height);
video.attachCamera(cam);
video.x=camMock.x;
video.y=camMock.y;
addChild(video);

var pic:BitmapData = new BitmapData(video.width,video.height);

var picBmp:Bitmap = new Bitmap(pic);
picBmp.x = camMock.x;
picBmp.y = camMock.y;

captureCam.buttonMode = true;
captureCam.addEventListener(MouseEvent.CLICK,captureImage);

function captureImage(e:MouseEvent):void {
    pic.draw(video);
    trace(pic.compare(img1));
    //compare two bmd
        //do x
}

回答1:


Not a percentage but it should return a new BitMapData objec that you could assign as an image.
BitMapData.compare( )

Returns Object — If the two BitmapData objects have the same dimensions (width and height), the method returns a new BitmapData object that has the difference between the two objects (see the main discussion). If the BitmapData objects are equivalent, the method returns the number 0. If the widths of the BitmapData objects are not equal, the method returns the number -3. If the heights of the BitmapData objects are not equal, the method returns the number -4.



来源:https://stackoverflow.com/questions/9136048/comparing-two-bitmapdata-in-actionscript-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!