Chroma使用FLARToolkit以编程方式键入视频

时间:2012-08-27 18:53:47

标签: augmented-reality flartoolkit

所以这将是一个多愁善感,也许......我正在尝试使用名为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访问像素而没有运气。

非常感谢任何帮助!

Adeptatus

2 个答案:

答案 0 :(得分:1)

是的,你可以这样做;

  1. 制作透明的背景视频  使用绿色屏幕背景素材创建透明背景视频,删除Adobe Afters Effects或Premiere或Final Cut上的绿色背景或..   在导出或渲染设置中更改为RGB + Alpha,然后导出

  2. 代码中的
  3. ;

    mat = new MovieMaterial(v, false, true);
    mat = new MovieMaterial(v, true, true);
    

答案 1 :(得分:0)

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