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

这篇博客介绍了如何利用OpenCV来创建PPT中的常见动画,如淡出、飞入、浮入和弹跳效果。通过动画基类的派生和重载显示区域、显示矩阵及屏蔽矩阵的方法,实现了不同动画效果。博客作者提供了配套软件下载,并分享了联系方式以促进交流。
摘要由CSDN通过智能技术生成

写在前面

本系列博客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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值