基于OpenCV的视频图像组态 (3):常见PPT动画1

来源:互联网 发布:撒贝宁老婆二婚 知乎 编辑:程序博客网 时间:2024/04/30 10:48

写在前面

本系列博客URL:

http://www.cnblogs.com/drgraph

http://blog.csdn.net/arwen

配套软件下载地址:

http://www.czwenwu.com/YeeVingSetup.exe

配套软件含三个可执行文件:YeeVingDriver.exe,YeeVingPlayer.exe,WatchDog.exe

其中,YeeVingDriver.exe是双目触控屏的驱动程序,内含键盘鼠标钩子,安装或运行的时候有可能会当成病毒。

WatchDog.exe是无人值守软件

YeeVingPlayer.exe是广告播放软件客户端。

本系列博客是在上述三个软件研发过程中的片面记录,基本上是属于想到哪写到哪的,不系统。主要目的是自己整理归纳一下,并期望与更多朋友交流。

QQ/微信:282397369

EMail: drgraph@qq.com

 

动画派生继承

书接上回,有了动画基类,再处理各个动画效果,就只需要重载实现各自的显示区域、显示矩阵与屏蔽矩阵。

 

比如淡出、飞入、浮入、弹跳几个动画效果,可以简单总结列成下表。

动画类型

显示区域

显示矩阵

屏蔽阵

缺省

=最终的显示区域

=最终的显示矩阵图像

=缺省屏蔽阵

TCbwAnimationEffect_FadeOut

淡出

不变

亮度变化

不变

TCbwAnimationEffect_FlyIn

飞入

区域大小不变

变动左上角位置(线性)

不变

不变

TCbwAnimationEffect_FloatIn

浮入

区域大小不变

变动左上角位置(线性)

渐显,亮度变化

不变

TCbwAnimationEffect_Bounce

弹跳

区域大小不变

变动左上角位置(弹性)

不变

不变

 

 

类型定义

初步进行类型划分定义:

复制代码
enum CbwEffectType { // 效果类型枚举量     cetBase = 0, // TCbwAnimationEffect        cetAppear = 1, // TCbwAnimationEffect_Appear        cetFadeOut = 2, // TCbwAnimationEffect_FadeOut        cetFlyIn = 3, // TCbwAnimationEffect_FlyIn        cetFloatIn = 4, // TCbwAnimationEffect_FloatIn        cetSplit = 5, // TCbwAnimationEffect_Split        cetErase = 6, // TCbwAnimationEffect_Erase        cetShape = 7, // TCbwAnimationEffect_Shape        cetWheel = 8, // TCbwAnimationEffect_Wheel        cetRandomLine = 9, // TCbwAnimationEffect_RandomLine        cetRotateToNear = 10, // TCbwAnimationEffect_RotateToNear        cetZoomEffect = 11, // TCbwAnimationEffect_Zoom        cetRotateEffect = 12, // TCbwAnimationEffect_Rotate        cetBounce = 13, // TCbwAnimationEffect_Bounce};
复制代码

 

实现代码

 

复制代码
class TCbwAnimationEffect_FadeOut : public TCbwAnimationEffect { // 淡出    virtual void __fastcall BuildDisplayMat(cv::Mat& destMat, cv::Mat& srcMat,        TRect displayRect);    CBW_ANIMATION_OBJECT(TCbwAnimationEffect_FadeOut, TCbwAnimationEffect, cetFadeOut);}; class TCbwAnimationEffect_FlyIn : public TCbwAnimationEffect { // 飞入    virtual TRect __fastcall BuildDisplayRect(OBJECTMAT * m);    CBW_ANIMATION_OBJECT(TCbwAnimationEffect_FlyIn, TCbwAnimationEffect, cetFlyIn);}; class TCbwAnimationEffect_FloatIn : public TCbwAnimationEffect { // 浮入    virtual TRect __fastcall BuildDisplayRect(OBJECTMAT * m);    virtual void __fastcall BuildDisplayMat(cv::Mat& destMat, cv::Mat& srcMat,        TRect displayRect);    CBW_ANIMATION_OBJECT(TCbwAnimationEffect_FloatIn, TCbwAnimationEffect, cetFloatIn);}; class TCbwAnimationEffect_Bounce : public TCbwAnimationEffect { // 弹跳    virtual TRect __fastcall BuildDisplayRect(OBJECTMAT * m);     CBW_ANIMATION_OBJECT(TCbwAnimationEffect_Bounce, TCbwAnimationEffect, cetBounce);};
复制代码

 

 

 

 

复制代码
void __fastcallTCbwAnimationEffect_FadeOut::BuildDisplayMat(cv::Mat& destMat,         cv::Mat&srcMat) {         for(int y = 0; y < destMat.rows; y++) {                   for(int x = 0; x < destMat.cols; x++) {                            for(int c = 0; c < 3; c++) {                                     BYTEvalue = srcMat.at<cv::Vec3b>(y, x)[c];                                     value= 255 - FCurrentIndex / double(FPeriodLength) *                                               (255- value);                                     destMat.at<cv::Vec3b>(y,x)[c] =                                               cv::saturate_cast<uchar>(value);                            }                   }         }} TRect __fastcall TCbwAnimationEffect_FlyIn::BuildDisplayRect(OBJECTMAT * m) {    TPoint startPos(m->FinalRect.left, m->FinalRect.top),        endPos(m->FinalRect.left, m->FinalRect.top);    int effectOptionType = MyOptionType.Items[1].CurrentValue;    if (cedFromBottom == effectOptionType ||        cedFromLeftBottom == effectOptionType ||        cedFromRightBottom == effectOptionType) // 自底部            startPos.y = FContraintHeight;    if (cedFromTop == effectOptionType || cedFromLeftTop == effectOptionType ||        cedFromRightTop == effectOptionType) // 自顶部            startPos.y = -m->FinalMat.rows;    if (cedFromLeft == effectOptionType ||        cedFromLeftBottom == effectOptionType ||        cedFromLeftTop == effectOptionType) // 自左侧            startPos.x = -m->FinalMat.cols;    if (cedFromRight == effectOptionType ||        cedFromRightBottom == effectOptionType ||        cedFromRightTop == effectOptionType) // 自右侧            startPos.x = FContraintWidth;    int x = startPos.x + (endPos.x - startPos.x) * (FCurrentIndex + 1)        / FTotalFramesInOnePeriod;    int y = startPos.y + (endPos.y - startPos.y) * (FCurrentIndex + 1)        / FTotalFramesInOnePeriod;    TRect result(x, y, x + m->FinalMat.cols, y + m->FinalMat.rows);    return result;} TRect __fastcall TCbwAnimationEffect_FloatIn::BuildDisplayRect(OBJECTMAT * m) {    TPoint startPos(m->FinalRect.left, m->FinalRect.top),        endPos(m->FinalRect.left, m->FinalRect.top);    int delta = 100;    int effectOptionType = MyOptionType.Items[1].CurrentValue;    if (cfdUp == effectOptionType) // 上浮            startPos.y = endPos.y + delta;    if (cfdDown == effectOptionType) // 下浮            startPos.y = endPos.y - delta;    int x = startPos.x + (endPos.x - startPos.x) * (FCurrentIndex + 1)        / FTotalFramesInOnePeriod;    int y = startPos.y + (endPos.y - startPos.y) * (FCurrentIndex + 1)        / FTotalFramesInOnePeriod;    TRect result(x, y, x + m->FinalMat.cols, y + m->FinalMat.rows);    return result;} void __fastcall TCbwAnimationEffect_FloatIn::BuildDisplayMat(cv::Mat& destMat,    cv::Mat& srcMat, TRect displayRect) {    InnerTrans_FadeOut(destMat, srcMat);} TRect __fastcall TCbwAnimationEffect_Bounce::BuildDisplayRect(OBJECTMAT * m) {    double x = double(FCurrentIndex + 1) / FTotalFramesInOnePeriod;    double v = sin((x - 1) * 3 * PI);     double y = fabs(200 * v / exp(0.3 * (x - 1)));    y = m->FinalRect.top - y;    x = m->FinalRect.left + (x - 1) * 500;    TRect result(x, y, x + m->FinalMat.cols, y + m->FinalMat.rows);    return result;}
复制代码

 

运行演示

 

阅读全文
0 0
原创粉丝点击