AR实现透明视频的播放
来源:互联网 发布:js定位当前地理位置 编辑:程序博客网 时间:2024/06/09 20:58
你想使用透明的视频在你的增强现实的应用程序,使用OpenGL。 先去官网下载Demo吧:https://developer.vuforia.com/downloads/samples
提供一个背景颜色单一的视频先 http://download.csdn.net/detail/u012847940/9293245
Replace original videos in assets with your own video. (If you want to have matching video preview, you will have to replace also the .png files) If you changed the file name, make sure to update it correspondingly in the VideoPlayback Activity.Now the important part! Android : Open VideoPlaybackShaders and replace VIDEO_PLAYBACK_FRAGMENT_SHADER with this code: iOS: Open Simple.fragsh
修改代码:
public static final String VIDEO_PLAYBACK_FRAGMENT_SHADER ="#extension GL_OES_EGL_image_external : require \n" +"precision mediump float; \n" +"uniform samplerExternalOES texSamplerOES; \n" +" varying vec2 texCoord;\n" +" varying vec2 texdim0;\n" +" void main()\n\n" +" {\n" +" vec3 keying_color = vec3(0.647, 0.941, 0.29);\n" +" float thresh = 0.45; // [0, 1.732]\n" +" float slope = 0.1; // [0, 1]\n" +" vec3 input_color = texture2D(texSamplerOES, texCoord).rgb;\n" +" float d = abs(length(abs(keying_color.rgb - input_color.rgb)));\n" +" float edge0 = thresh * (1.0 - slope);\n" +" float alpha = smoothstep(edge0, thresh, d);\n" +" gl_FragColor = vec4(input_color,alpha);\n" +" }";
In the keying_color variable is stored the actual color we want to replace. It is using classic RGB model, but intensity is not expressed as 0-255 integer. It is a float value in range 0-1. (So 0 = 0, 255 = 0, 122 = 0.478…) In our case, the green color has value (0.647, 0.941, 0.29), but if you are using different video, measure the color yourself.Note: Make sure you have the right color. Some color measurement software automatically converts colors to slightly different formats, such as AdobeRGB.So where’s the magic?We load current pixel color in the input_color, then calculate difference between input and keying color. Based on this difference, alpha value is calculated and used for specific pixel.You can control how strict the comparison is using the slope and threshold values. It is a bit more complicated, but the most basic rule is: The more threshold you have, the bigger tolerance.So, we are done, right? Nope.
Blending
添加代码:
To enable transparency, you need to also enable blending. Without blending, every time you write a new pixel color value, transparent or not, the old one gets deleted. So you get nice video playback, but you destroy the camera image behind it.To enable blending, insert following two lines of code into VideoPlaybackRenderer class, renderFrame method, before each of these two glUseProgram calls:GLES20.glUseProgram(keyframeShaderID);GLES20.glUseProgram(videoPlaybackShaderID);Code to insert:GLES20.glEnable(GLES20.GL_BLEND);GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);First glUseProgram call is responsible for rendering png video previews. So if you don’t use transparency in you png files, you can skip that. Second call is used when rendering actual video.Regarding those two lines you have to insert: They enable blending and set it to blend pixels based on their alpha values. So the colors of pixels are not affected and only alpha values matter.Done?Not exactly. On most devices, this will do. But on some, you will still get black background instead of camera image. That’s because we turned the blending on, but we never turned it off.To turn blending off, you have to add this line after all glUseProgram(0) calls:GLES20.glDisable(GLES20.GL_BLEND);There should be three glUseProgram(0) calls, the last one is already followed by such line, so that one shouldn’t concern you.ok
0 0
- AR实现透明视频的播放
- 基于unity制作的AR视频播放
- 透明视频播放
- VideoView播放视频的时候出现播放前透明问题
- Transparent Desktop Video C#实现透明桌面视频播放源代码
- unity3d播放透明mov格式视频的一种方式
- Unity透明视频播放 所需的Shader脚本
- 高通|AR扫描图片播放视频
- AR 广告大屏视频播放模块
- 简单的实现播放视频
- 基于标记的AR的OpenCV实现:动态视频输入
- EasyAR开发教程第二弹--AR 视频的识别与播放
- win8上openframeworks播放透明mov视频
- 实现土豆网的视频播放
- 实现带列表的视频播放2
- 三种方式实现视频的播放
- Html实现的Windows视频播放器
- android 简易视频播放器的实现
- Binary Search Tree Iterator
- .net 1.0 或1.1 环境下发送邮件
- Struts标签
- Leetcode#17||Letter Combinations of a Phone Number
- 归并排序【基础】
- AR实现透明视频的播放
- fatal: Paths with -a does not make sense.
- DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value to i报错解决方法
- HDU5374 Tetris (2015年多校比赛第7场)大模拟
- 四色原型总结(优秀)
- 新的开始
- SaveOrUpdate
- Owin入门
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式(转)