返回列表 回复 发帖

[教程] 译文:FLARtoolkit技巧:使用彩色marker

这个是经过修改的版本,感谢psychedelico指出之前翻译的错误

第一次做翻译,呵呵!!希望对大家有用。如果翻译不当,欢迎指出。原文地址:
http://blog.onthewings.net/2009/05/23/flartoolkit-trick-use-a-colored-marker/
FLARtoolkit trick: use a colored markerFLARtoolkit技巧:使用彩色marker


Reasons why should we use colored marker instead of standard black and white only marker Using a black and white only marker is boringThere are more and more AR applications in the world, but seems everybody use only the black square marker. May be the public is not yet bored by the black square yet, but if can use other color for the square, we can integrate the marker into real-life objects more beautifully and more flexible.为什么我们要用彩色marker——黑白marker太单调了
越来越多的AR程序出现了,但似乎所有人都在用黑白marker。也许大众还没厌倦黑白方格,但如果能用其他颜色,我们就可以把现实中更漂亮、更灵活的物体作为marker。



Increase marker detection performanceThe internal algorithm of AR marker detection has a characteristic that, the less pixels’ color is the same of the marker, faster the detection can be done. When we use black square marker, the detector will waste a lot of time to process non-marker pixels as you can imagine that it is common to have black objects in real-life (especially we the Chinese people have black hair). So if we target less common color, the detector will be able to ignore most of the non-marker area.
提高marker识别的性能
内置的marker识别算法有个特征,屏幕中跟marker颜色相同部分的像素越少,识别越快。我们用黑marker的时候,识别程序会浪费很多时间处理非marker部分的像素。如你所能想到的,现实中黑色物体是很普遍的(特别是我们有黑头发的中国人)。因此,如果marker少用跟现实物体的颜色,识别程序会忽略大部分非marker区域的处理。



How to achieve this in FLARtoolkitWe will create a custom detector class since we need to work at lower level of the FLARtoolkit. If you have not look into the internal classes of FLARtoolkit (because the FLARmanager is so much easier to work with ), there are two detectors: FLARSingleMarkerDetector and FLARMultiMarkerDetector. As their names suggest, one is for single marker detection and the other one can detect multiple markers. For simplicity, I will go through only the single detection for a red marker (if you want me to cover the other ones too, leave comment).
First we just copy all the codes inside FLARSingleMarkerDetector to a new class, I named it FLARSingleRedMarkerDetector.
用FLARtoolkit怎样做到呢?
我们需要使用FLARtoolkit的底层,所以要创建一个自己的识别类。也许你没有看过FLARtoolkit内部的类(因为使用FLARmanager容易得多),有两个识别类: FLARSingleMarkerDetector和FLARMultiMarkerDetector。正如他们的名称一样,一个用作单marker识别,另一个用作多marker识别。为了简单化,我只会写一个识别单一红色marker的类。我们先把所有FLARSingleMarkerDetector的代码复制到一个新的类,我把它叫做FLARSingleRedMarkerDetector。




To detect markers, we use the detectMarkerLite method, which is:
public function detectMarkerLite(i_raster:IFLARRgbRaster, i_threshold:int):BooleanIFLARRgbRaster wraps a BitmapData, we can get it by:
var srcImg:BitmapData = (i_raster as FLARRgbRaster_BitmapData).bitmapData;Originally, the method uses a threshold filter to extract black areas and give the result to other classes to process. As you might think of, we can simply swap the filter code. Originally the black areas will be turned to white pixels and others will be turned black and be ignored. We now want to detect red markers, so just try to turn everything black except the red regions to white. You may use ColorTransform if you want, but I am now obsessed with PixelBender.
我们可以这样得到一个IFLARRgbRaster包装的BitmapData:
public function detectMarkerLite(i_raster:IFLARRgbRaster, i_threshold:int):BooleanIFLARRgbRaster
我们可以这样用,包含一个BitmapData类:
var srcImg:BitmapData = (i_raster as FLARRgbRaster_BitmapData).bitmapData;
原来,这个方法用一个过滤算法来提取黑色区域,然后把结果送给其它类去处理。你可能也想到,我们只改写过滤算法就可以了。本来黑色区域会变成白色,其他部分会变成黑色而被忽略。现在我们想识别红色marker,所以要把红色区域边白,其他区域边黑。你可以用ColorTransform类,但我现在用PixelBender类。




My version of kernel is:
kernel extractRedARMarker<   namespace : "net.onthewings.filters";    vendor : "Andy Li";    version : 1;    description : "used for FLARtoolkit, pre-proccess for red marker.";>{    input image4 src;    output pixel4 dst;    parameter float threshold<        minValue: 0.0;        maxValue: 1.0;        defaultValue: 0.4;        description:"decrease to increase likelihood of marker detection.";    >;    void    evaluatePixel()    {        float4 p = sampleNearest(src,outCoord());        float sum = p.r+p.g+p.b;        float val = p.r - (p.g + p.b)*0.5;        if (val+(1.0-(sum/3.0))*0.1 <= threshold) {            val = 0.0;        } else {            val = 1.0;        }        dst = float4 (val,val,val,1);    }}Note that I let the dark red pass the threshold easier since I find it is common the web cam image is too dark.
注意,我把深红色传给过滤算法,因为我发现通常摄像头的图像太暗。


To use the finished detector class:
tempFLARRgbRaster_BitmapData.bitmapData.draw(videoDisplay);if (detector.detectMarkerLite(tempFLARRgbRaster_BitmapData,170)){        detector.getTransformMatrix(lastDetectionResult);        //FLARPVGeomUtils is from FLARmanager        overlay3dObj.transform = FLARPVGeomUtils.convertFLARMatrixToPVMatrix(lastDetectionResult);        overlay3dObj.visible = true;} else {        overlay3dObj.visible = false;}render();Now you get all the concepts. So let’s skip all the boring stuff and see it in action. Or get the finished codes.
现在你知道了所有概念。我们跳过所有麻烦的东西,看看效果或者下载代码吧!
Happy AR!
嗯,看看再说~
厉害啊,希望可以看到一些源代码资源
好东西,有demo就更好了......
1# cankeyyin
看看再说
抗盲北鼻沟  哟哟切克闹
伟哥
返回列表