当前位置:网站首页>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 .
边栏推荐
猜你喜欢

毕业才知道IT专业大学生毕业前必做的1010件事

Eslint--- error: newline required at end of file but not found (EOL last) solution

JS --- detailed explanation of JS facing objects (VI)

Learning record: use STM32 external input interrupt

LeetCode#237. Delete nodes in the linked list

ucore lab 6

学习记录:理解 SysTick系统定时器,编写延时函数

LeetCode#19. Delete the penultimate node of the linked list

力扣刷题记录

7-1 懂的都懂 (20 分)
随机推荐
入门C语言基础问答
0-1 knapsack problem (I)
JS调用摄像头
cs零基础入门学习记录
Crawler series (9): item+pipeline data storage
ucore lab 6
学习记录:TIM—电容按键检测
Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
csapp shell lab
JS --- all basic knowledge of JS (I)
Truck History
D - Function(HDU - 6546)女生赛
Accounting regulations and professional ethics [1]
Determine the Photo Position
Optimization method of path problem before dynamic planning
Hospital privacy screen Industry Research Report - market status analysis and development prospect forecast
Learning records: serial communication and solutions to errors encountered
7-1 懂的都懂 (20 分)
JS --- JS function and scope (II)
China's PCB connector market trend report, technological innovation and market forecast