0

所以这可能有点麻烦......我正在尝试使用名为 FLARToolkit 的 Flash 插件在增强现实中播放视频剪辑。我有一个绿屏视频,我需要在飞机上播放视频。我目前正在使用 MovieClipMaterial 将视频放置在显示平面上。我想遍历显示平面中的像素并更改与绿屏中的绿色匹配的像素,并将这些像素设置为透明的色度键控。可能有一种更有效的方法可以做到这一点,我愿意接受建议。

我还研究了 ColorMatrixFilters,但我无法设计一种使其具有选择性的方法,而不是过滤掉剪辑中的所有绿色。

这是我现在的代码:

[SWF(width='640', height='480', backgroundColor='#000000', frameRate='40')]

public class HelloFLAR extends Sprite
{
    private var fm:FLARManager;
    private var scene:Scene3D;
    private var view:Viewport3D;
    private var camera:FLARCamera3D;
    private var bre:BasicRenderEngine;
    private var lre:LazyRenderEngine;
    private var p:Plane;
    private var con:DisplayObject3D;
    private var marker:FLARMarker;
    private var v:Vid;
    private var mat:MovieMaterial
    private var bmd:BitmapData;
    private var videoStream:NetStream;
    private var container:FLARBaseNode;
    private var RGBRaster:FLARRgbRaster_BitmapData;

    public function HelloFLAR()
    {
        initFLAR();
        v = new Vid();
        //source for displayed video
        v.vid.source = "Reuters.m4v";
        v.vid.stop();

    }

    private function initFLAR():void
    {
        fm = new FLARManager("flarConfig.xml");
        fm.addEventListener(FLARMarkerEvent.MARKER_ADDED, onAdded);
        fm.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onRemoved);
        fm.addEventListener(Event.INIT, init3D);
        addChild(Sprite(fm.flarSource));


    }

    private function onAdded(e:FLARMarkerEvent):void
    {
        marker = e.marker;
        p.visible = true;
        v.vid.play();
    }

    private function onRemoved(e:FLARMarkerEvent):void
    {
        marker = null;
        p.visible = false;
        v.vid.stop();
    }

    private function init3D(e:Event):void
    {
        scene = new Scene3D();
        camera = new FLARCamera3D(fm.cameraParams);
        camera.z = -30;
        view = new Viewport3D(640, 480, true);
        lre = new LazyRenderEngine(scene,camera,view);


        //Display plane and Videp material
        mat = new MovieMaterial(v, false, true);
        p = new Plane(mat, 320, 240, 2, 2);
        mat.doubleSided = true;
        p.rotationZ = 90;
        p.visible = true;


        //Green Leech from video plane (Attempt at chromakeying)
        var matrix:Array = new Array();         
        matrix = matrix.concat([1,0,0,0,0]); //Red
        matrix = matrix.concat([0,1,0,0,0]); //Green
        matrix = matrix.concat([0,0,1,0,0]); //Blue
        matrix = matrix.concat([0,-1,0,0,0]); //Alpha

        var color_filter:ColorMatrixFilter = new ColorMatrixFilter(matrix);;
        v.filters = [color_filter];

        //container for display Plane
        con = new DisplayObject3D();
        con.addChild(p);


        //Add plane container to scene
        scene.addChild(con);
        addChild(view);
        addChild(new FramerateDisplay());

        addEventListener(Event.ENTER_FRAME, loop);
        //addEventListener(Event.ENTER_FRAME, pixelCheck);

    }

    private function loop(e:Event):void
    {
        if(marker != null)
        {
            con.transform = FLARPVGeomUtils.convertFLARMatrixToPVMatrix(marker.transformMatrix);
        }
        lre.render();
    }

我似乎无法访问视频的像素。我尝试通过平面和 MovieClipMaterial 访问像素,但没有成功。

任何帮助将不胜感激!

修会

4

2 回答 2

1

是的,你可以这么做;

  1. 创建透明背景视频 创建透明背景视频,使用绿屏背景素材,在 Adob​​e Afters Effects 或 Premiere 或 Final Cut 上移除绿色背景或..在导出或渲染设置更改为 RGB + Alpha,然后导出

  2. 在您的代码中;

    mat = new MovieMaterial(v, false, true);
    mat = new MovieMaterial(v, true, true);
    
于 2012-10-04T13:11:17.790 回答
0

抱歉,我忘记了,透明视频格式应该是flv. 因为一些格式可以携带透明度信息。可以使用River FLV 播放器进行测试。

于 2012-10-05T12:29:25.207 回答