日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

帧差法——动态检测——统计车流量

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 帧差法——动态检测——统计车流量 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

幀差法——動態檢測——統計車流量

幀差法原理

幀間差分法是一種通過對視頻圖像序列的連續兩幀圖像做差分運算獲取運動目標輪廓的方法。當監控場景中出現異常目標運動時,相鄰兩幀圖像之間會出現較為明顯的差別,兩幀相減,求得圖像對應位置像素值差的絕對值,判斷其是否大于某一閾值,進而分析視頻或圖像序列的物體運動特性。

實現流程

實現效果


動態檢測函數代碼

Mat MoveDetect(Mat frame1, Mat frame2) {Mat result = frame2.clone();Mat gray1, gray2;cvtColor(frame1, gray1, CV_BGR2GRAY);cvtColor(frame2, gray2, CV_BGR2GRAY);Mat diff;absdiff(gray1, gray2, diff);//兩幅圖做差imshow("absdiss", diff);threshold(diff, diff, 25, 255, CV_THRESH_BINARY);//二值化diffMat element = getStructuringElement(MORPH_RECT, Size(3, 3));//返回指定形狀與尺寸得結構元素Mat element2 = getStructuringElement(MORPH_RECT, Size(19, 19));erode(diff, diff, element);//腐蝕函數medianBlur(diff, diff, 3);//中值濾波dilate(diff, diff, element2);//膨脹函數 vector<vector<Point>> contours;vector<Vec4i> hierarcy;findContours(diff, contours, hierarcy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));//查找輪廓vector<vector<Point>>contours_poly(contours.size());vector<Rect> boundRect(contours.size()); //定義外接矩形集合 int x0 = 0, y0 = 0, w0 = 0, h0 = 0;for (int i = 0; i<contours.size(); i++){approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);//對圖像輪廓點進行多邊形擬合:輪廓點組成的點集,輸出的多邊形點集,精度(即兩個輪廓點之間的距離),輸出多邊形是否封閉boundRect[i] = boundingRect(Mat(contours_poly[i]));if (boundRect[i].width>90 && boundRect[i].width<180 && boundRect[i].height>90 && boundRect[i].height<180) {//輪廓篩選 (90 180)x0 = boundRect[i].x;y0 = boundRect[i].y;w0 = boundRect[i].width;h0 = boundRect[i].height;rectangle(result, Point(x0, y0), Point(x0 + w0, y0 + h0), Scalar(0, 255, 0), 2, 8, 0);if ((y0 + h0 / 2 + 1) >= 198 && (y0 + h0 / 2 - 1) <= 202) {//經過這條線(區間),車輛數量+1CarNum++;}}line(result, Point(0, 200), Point(720, 200), Scalar(0, 0, 255), 1, 8);//畫紅線Point org(0, 35);putText(result, "CarNum=" + intToString(CarNum), org, CV_FONT_HERSHEY_SIMPLEX, 0.8f, Scalar(0, 255, 0), 2);}return result; }

完整代碼及實驗使用視頻請到資源處下載

鏈接: https://download.csdn.net/download/weixin_46958585/12708964.

總結

以上是生活随笔為你收集整理的帧差法——动态检测——统计车流量的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。