b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

视频前景提取_网络新闻视频的特征及前景_视频背景音乐提取

电脑杂谈  发布时间:2020-02-15 07:01:12  来源:网络整理

网络新闻视频的特点及前景_视频前景提取_视频背景音乐提取

这是(II)中的Mat版本,特别注意一下accumulateWeighted这个函数的用法。

我将官网文档中的函数表明贴起来:

accumulateWeighted

Updates a running average.

视频前景提取_视频背景音乐提取_网络新闻视频的特点及前景

C++:voidaccumulateWeighted(InputArraysrc,

InputOutputArraydst, doublealpha, InputArraymask=noArray())

Python:cv2.accumulateWeighted(src,

dst, alpha[, mask])→ None

视频前景提取_视频背景音乐提取_网络新闻视频的特点及前景

C:voidcvRunningAvg(const

CvArr*image, CvArr*acc, doublealpha, const CvArr*mask=NULL)

Python:cv.RunningAvg(image,

acc, alpha, mask=None)→ None

视频前景提取_视频背景音乐提取_网络新闻视频的特点及前景

Parameters:

The function calculates the weighted sum of the input imagesrcand the accumulatordstso

thatdstbecomes a running average of a frame sequence:

\texttt{dst} (x,y)  \leftarrow (1- \texttt{alpha} )  \cdot \texttt{dst} (x,y) +  \texttt{alpha} \cdot \texttt{src} (x,y)  \quad \text{if} \quad \texttt{mask} (x,y)  \ne 0

视频背景音乐提取_视频前景提取_网络新闻视频的特点及前景

That is,alpharegulates the update speed (how fast the accumulator “forgets” about earlier images). The function supports multi-channel

images. Each channel is processed independently.

See also

,,

代码:

//opencv2.0风格的视频前景提取
#include "cv.h"
#include "highgui.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <cstdio>
using namespace std;
using namespace cv;
int main()
{
	Mat frame, frame_copy,img1,output,gray,frame_copy_8U;
	double learningRate = 0.01;	// 控制背景累积学习的速率
	char* input_name = "001.avi";
	//从视频读入
	VideoCapture capture(input_name);
	cvNamedWindow( "result", 1 );
	if(capture.isOpened()/*capture*/)	// 读取文件开关
	{
		//对每一帧做处理
		for(;;)
		{
			//frame = cvQueryFrame( capture );	// 读取文件开关
			capture >> frame;
			if(!frame.empty())
			{ 
				cvtColor(frame, gray, CV_BGR2GRAY);
				//进行处理
				if (frame_copy.empty())
				{
					//记录第一帧
					gray.convertTo(frame_copy, CV_32F);
				}
				frame_copy.convertTo(frame_copy_8U, CV_8U);
				//做差分
				absdiff(frame_copy_8U, gray, img1);
				// 对得到的前景进行阈值选取,去掉伪前景
				threshold(img1, output, 30, 255, THRESH_BINARY_INV);
				accumulateWeighted(gray, frame_copy,0.01,output);
				imshow("src", frame);
				imshow("result", output);
			}
			else
			{ 
				printf(" --(!) No captured frame -- Break!");
				break;
			}
			//10ms中按任意键进入此if块
			if( cvWaitKey( 10 ) >= 0 )
				break;
		}
	}
	return 0;
}

更好版本(II):


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-140825-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...