您好,登錄后才能下訂單哦!
小編給大家分享一下opencv3/C++怎么實(shí)現(xiàn)視頻背景去除建模,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
視頻背景建模主要使用到:
高斯混合模型(Mixture Of Gauss,MOG)
createBackgroundSubtractorMOG2(int history=500, double varThreshold=16,bool detectShadows=true);
K最近鄰(k-NearestNeighbor,kNN)
createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0, bool detectShadows=true);
history:history的長(zhǎng)度。
varThreshold:像素和模型之間馬氏距離的平方的閾值。
detectShadows:默認(rèn)為true,檢測(cè)陰影并標(biāo)記它們(影子會(huì)被標(biāo)記為灰色)。 會(huì)降低了部分速度。
實(shí)例:
#include<opencv2/opencv.hpp> using namespace cv; int main() { VideoCapture capture; capture.open("E:/image/01.avi"); if(!capture.isOpened()) { printf("can not open video file \n"); return -1; } Mat frame; namedWindow("input", CV_WINDOW_AUTOSIZE); namedWindow("MOG2", CV_WINDOW_AUTOSIZE); namedWindow("KNN", CV_WINDOW_AUTOSIZE); Mat maskMOG2, maskKNN; Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2(500,25,true); Ptr<BackgroundSubtractor> pKNN = createBackgroundSubtractorKNN(); Mat kernel = getStructuringElement(MORPH_RECT, Size(5,5)); while (capture.read(frame)) { imshow("input", frame); pMOG2->apply(frame, maskMOG2); pKNN->apply(frame, maskKNN); //對(duì)處理后的幀進(jìn)行開操作,減少視頻中較小的波動(dòng)造成的影響 morphologyEx(maskMOG2,maskMOG2, MORPH_OPEN, kernel, Point(-1,-1)); morphologyEx(maskKNN,maskKNN, MORPH_OPEN, kernel, Point(-1,-1)); imshow("MOG2", maskMOG2); imshow("KNN", maskKNN); waitKey(3); } capture.release(); return 0; }
視頻中移動(dòng)的玻璃球:
MOG分離出的小球區(qū)域:
KNN分離出的小球區(qū)域:
以上是“opencv3/C++怎么實(shí)現(xiàn)視頻背景去除建?!边@篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。