相关
视频叠加算法-白色素材叠加
视频叠加算法-黑色素材叠加
视频叠加算法-彩色加亮融合
视频叠加算法-彩色均值融合
引言
此次是彩色素材,素材如下:
彩色素材算法实现
原视频:
inputint frame_cover_color( AVFrame* dst_frame, AVFrame* src_frame, AVFrame* cover_frame,int whiteskip,int colorskip,int top) { if(dst_frame == NULL || src_frame == NULL || cover_frame == NULL) { puts("frame_cover_white input or output frame is NULL"); return -1; } char* tempblack = (char*)malloc(sizeof(char) * cover_frame->linesize[0]); memset(tempblack, 16, cover_frame->linesize[0]); int w2 = cover_frame->width; int h2 = cover_frame->height; int i = 0,j = 0; int temp,a,u,v,a2,u2,v2; float rat; int yindex = 0; int yindex2,uindex2; int udiv,vdiv; for(i = 0;i<h2;i++) { yindex = i*cover_frame->linesize[0]; if(strncmp((char*)cover_frame->data[0]+yindex,tempblack,cover_frame->linesize[0])==0) { continue; } yindex2 = i*src_frame->linesize[0]; uindex2 = (i>>1)*src_frame->linesize[1]; for(j=0;j<w2;j++) { a2 = cover_frame->data[0][yindex]; v2 = cover_frame->data[2][uindex2]; u2 = cover_frame->data[1][uindex2]; udiv = u2 - 128; vdiv = v2 - 128; if(udiv < 0) udiv = -udiv; if(vdiv < 0) vdiv = -vdiv; if((a2 <= whiteskip&& udiv+vdiv == 0)||(udiv+vdiv != 0)&&a2 <= colorskip) { yindex++; yindex2++; if(j%2!=0) uindex2++; continue; } a = src_frame->data[0][yindex2]; u = src_frame->data[1][uindex2]; v = src_frame->data[2][uindex2]; v2 = cover_frame->data[2][uindex2]; u2 = cover_frame->data[1][uindex2]; rat = (a2+udiv+vdiv)*(a2+udiv+vdiv)/(float)(top*top); if(rat > 1) rat = 1; dst_frame->data[0][yindex2] = (char)a+(a2-a)*rat; dst_frame->data[1][uindex2]= u+(int)((u2-u)*rat); dst_frame->data[2][uindex2]= v+(int)((v2-v)*rat); yindex++; yindex2++; if(j%2!=0) uindex2++; } } free(tempblack); return 0; }
效果: output
具体解释参看视频叠加算法-白色素材叠加
与白色素材叠加的区别:
- 其没有固定某个临近值。
- 不能单纯以Y值作为叠加的权重,因为某些颜色肉眼分辨十分敏感,但是其Y值差别不大。
三 待改进
参看视频叠加算法-白色素材叠加
网友评论