OpenCV實現幀差法

2021-06-16 18:06:38 字數 702 閱讀 7466

幀差法的優勢是運算量小,實時性好,可以獲得不錯的輪廓。缺點是不夠精細,閾值過高容易漏檢,過低則無法做到noise tolerance. 另外如果發生光照突變等情況,幀差法會把整副影象當成運動區域。

以下是實現的**。

#include "highgui.h"

#include "cv.h"

void main()

if(framenum>=2)

//把當前幀儲存作為下一次處理的前一幀

cvcvtcolor(tempframe, previousframe, cv_bgr2gray);

cvwaitkey(10);

}//end while

//釋放資源

cvreleaseimage(&tempframe);

cvreleaseimage(&previousframe);

cvreleaseimage(¤tframe);

//tempframe不用在這裡釋放

cvreleasecapture(&capture);

cvreleasemat(&previousframemat);

cvreleasemat(¤tframemat);

cvdestroywindow("camera");

cvdestroywindow("moving area");

}

Open CV 三幀差法

首先 去連續三幅圖定義為 其中image1 image2 做幀的差值運算 image2 image3 做幀的差值運算 並將他們差值做平滑處理和閾值處理 轉化成二值影象 然後將其進行位與運算得出結果result include highgui.h include cv.h include cxcore...

OpenCV實現幀差法檢測運動目標

今天的目標是用opencv實現對運動目標的檢測,這裡選用三幀幀差法。如下 include include include include include double threshold index 0 const int contour max aera 200 void trackbar int...

opencv利用幀差法背景差分實現運動目標檢測

本博文主要介紹背景差法與幀差法 背景差法 就是用原影象減去背景模型,剩下的就是前景影象,即運動目標 幀差法 就是利用相鄰的兩幀或者三幀影象,利用畫素之間的差異性,判斷是否有運動目標 背景減法基本步驟 原圖 背景 閾值處理 去除雜訊 腐蝕濾波 膨脹連通 查詢輪廓 外接矩形 橢圓 圓 乙個攝像頭 inc...