1. 程式人生 > >基於OpenCV的視訊影象組態 (4) :劈裂動畫效果

基於OpenCV的視訊影象組態 (4) :劈裂動畫效果

寫在前面

本系列部落格URL:

配套軟體下載地址:

配套軟體含四個可執行檔案:DrGraph.exe,YeeVingDriver.exe,YeeVingPlayer.exe,WatchDog.exe

其中,

DrGraph.exe為圖形博士軟體,可進行電路定量分析及其應用。

YeeVingDriver.exe是雙目觸控屏的驅動程式,內含鍵盤滑鼠鉤子,安裝或執行的時候有可能會當成病毒。

WatchDog.exe是無人值守軟體

YeeVingPlayer.exe是廣告播放軟體客戶端。

本系列部落格是在上述四個軟體研發過程中的片面記錄,基本上是屬於想到哪寫到哪的,不繫統。主要目的是自己整理歸納一下,並期望與更多朋友交流。

QQ/微信:282397369

劈裂效果

劈裂效果:顯示目標區域位置不變,顯示內容(原始陣不變,遮蔽陣變化 -> 顯示內容變化)

enum CbwSplitDirection { // 劈裂方向

    csdVertCollapse = 0, // 上下向中央收縮

        csdVertExpand = 1, // 中央向上下展開

        csdHorzCollapse = 2, // 左右向中央收縮

        csdHorzExpand = 3 // 中央向左右展開

    };

bool __fastcall TCbwAnimationEffect_Split::BuildMaskMat(cv::Mat& destMat,

    cv::Mat& srcMat, TRect displayRect) {

    TRect wholeRect(0, 0, displayRect.right - displayRect.left,

        displayRect.bottom - displayRect.top);

    TRect partRect = wholeRect;

    double cx = partRect.right / 2.0, cy = partRect.bottom / 2.0;

    int effectOptionType = MyOptionType.Items[1].CurrentValue;

    bool vertFlag = (effectOptionType <= csdVertExpand);

    double delta = double(FCurrentIndex + 1) / FTotalFramesInOnePeriod * (vertFlag ?

        cy : cx);

    if (csdVertExpand == effectOptionType) { // 上下向中央收縮

        partRect.top = cy - delta;

        partRect.bottom = cy + delta;

    }

    if (csdVertCollapse == effectOptionType) { // 中央向上下展開

        partRect.top = delta;

        partRect.bottom = 2 * cy - delta;

    }

    if (csdHorzExpand == effectOptionType) { // 左右向中央收縮

        partRect.left = cx - delta;

        partRect.right = cx + delta;

    }

    if (csdHorzCollapse == effectOptionType) { // 中央向左右展開

        partRect.left = delta;

        partRect.right = 2 * cx - delta;

    }

    bool expandFlag =

        (csdVertExpand == effectOptionType ||

        csdHorzExpand == effectOptionType);

    BYTE * pSrc = srcMat.data;

    BYTE * pDst = destMat.data;

    for (int row = 0; row < destMat.rows; ++row)

        for (int col = 0; col < destMat.cols; ++col) {

            bool hasValueFlag = (*pSrc++ != 0);

            if (!hasValueFlag)

                * pDst = 0;

            int y = (row - partRect.top) * (partRect.bottom - row);

            int x = (col - partRect.left) * (partRect.right - col);

            bool inFlag = (y >= 0 && x >= 0);

            if (!expandFlag)

                inFlag = (y > 0 && x > 0);

            bool setFlag = (inFlag == expandFlag);

            *pDst++ = (setFlag ? 255 : 0);

        }

    return true;

}

結果