当前位置:网站首页>Opencv learning log 31 -- background difference
Opencv learning log 31 -- background difference
2022-07-06 15:43:00 【@Spring sauce】
Preface
This article is mainly about opencv Background difference in image processing .
One 、 Background subtraction
// The first question is Background subtraction
#include <opencv2/opencv.hpp>
#include <iostream>
#include<cmath>
using namespace cv;
using namespace std;
int main()
{
// Counter
int cnt = 0;
Mat frame;
Mat background;
Mat subpic;
Mat bin_subpic;
VideoCapture cap;
cap.open("C://Users//john//Desktop//VID.mp4");
while (1)
{
cap.read(frame);
cvtColor(frame, frame, COLOR_BGR2GRAY);
if (cnt == 0) {
frame.copyTo(background);
}
else {
// The second frame starts with background subtraction
// The background image is subtracted from the current image
absdiff(frame, background, subpic);
// Binarization of difference results
threshold(subpic, bin_subpic, 50, 144, CV_THRESH_BINARY);
imshow("subpic", subpic);
imshow("bin_subpic", bin_subpic);
imshow("frame", frame);
waitKey(30);
}
cnt++;
}
return 0;
}
summary
1. The code can run directly , If you don't understand, you can leave a message .
2. Missing material pictures , Subsequent patch , thank you .
边栏推荐
- Cost accounting [24]
- C 基本语法
- Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
- 用C语言写网页游戏
- 学习记录:串口通信和遇到的错误解决方法
- cs零基础入门学习记录
- Crawling cat's eye movie review, data visualization analysis source code operation instructions
- Opencv learning log 12 binarization of Otsu method
- Cost accounting [14]
- Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
猜你喜欢
学习记录:串口通信和遇到的错误解决方法
学习记录:USART—串口通讯
Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
学习记录:TIM—电容按键检测
STM32 how to use stlink download program: light LED running light (Library version)
Matlab comprehensive exercise: application in signal and system
ucorelab4
STM32 learning record: LED light flashes (register version)
STM32学习记录:玩转按键控制蜂鸣器和LED
C语言必背代码大全
随机推荐
cs零基础入门学习记录
通俗地理解什么是编程语言
MATLAB综合练习:信号与系统中的应用
Medical colposcope Industry Research Report - market status analysis and development prospect forecast
Record of brushing questions with force deduction -- complete knapsack problem (I)
Shell脚本编程
Matlab comprehensive exercise: application in signal and system
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
区间和------离散化
ucore lab 2
Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
China medical check valve market trend report, technical dynamic innovation and market forecast
STM32學習記錄:輸入捕獲應用
Learning record: use stm32f1 watchdog
Cost accounting [22]
Truck History
LeetCode#204. Count prime
JS --- all knowledge of JS objects and built-in objects (III)
China earth moving machinery market trend report, technical dynamic innovation and market forecast
Cost accounting [21]