• 大小: 26.28MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-28
  • 语言: 其他
  • 标签: opencv  

资源简介

内含代码可以检测运动物体,采用高斯混合模型算法提取前景

资源截图

代码片段和文件信息

#pragma once
#include “afxwin.h“
#include“highgui.h“

#include 
#include 
#include 
#include 
using namespace std;
using namespace cv;


void Writetxt(float xfloat y)
{
ofstream file;
file.open(“C:\\Users\\Administrator\\Desktop\\Result.txt“ios::app);
file< file<<““;
file<
file.close();

}



void main()
{

int m_ImageWidthm_ImageHeight;
BITMAPINFO* m_bmi1* m_bmi2; // 2个位图头,分别彩色和黑白。
CDC* m_pDC;
Mat m_Img;
VideoCapture m_cap(“C:\\Users\\Administrator\\Desktop\\768x576.avi“);

if(!m_cap.isOpened())
{
printf(“Cannot Open!“);
return;
}

double rate=m_cap.get(CV_CAP_PROP_FPS);
double wid=m_cap.get(CV_CAP_PROP_frame_WIDTH);
double hgt=m_cap.get(CV_CAP_PROP_frame_HEIGHT);
uchar bmbuffer1[2048]bmbuffer2[2048];

m_ImageWidth=(int)wid;
m_ImageHeight=(int)hgt;


// 位图信息头,可预先设置好。

if(m_bmi1==NULL)//tagBITMAPINFO结构体包含位图信息和颜色    ——2017.7.28
{
m_bmi1 = (BITMAPINFO*)bmbuffer1;
m_bmi1->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_bmi1->bmiHeader.biWidth = m_ImageWidth;
m_bmi1->bmiHeader.biHeight = -m_ImageHeight; // 不然倒置了
m_bmi1->bmiHeader.biPlanes = 1;
m_bmi1->bmiHeader.biBitCount = IPL_DEPTH_8U*m_Img.channels();
m_bmi1->bmiHeader.biCompression = BI_RGB;
m_bmi1->bmiHeader.biSizeImage=0;
m_bmi1->bmiHeader.biXPelsPerMeter=0;
m_bmi1->bmiHeader.biYPelsPerMeter=0;
m_bmi1->bmiHeader.biClrImportant=0;
m_bmi1->bmiHeader.biClrUsed=0;
}
if(m_bmi2==NULL)
{
m_bmi2 = (BITMAPINFO*)bmbuffer2;
m_bmi2->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_bmi2->bmiHeader.biWidth = m_ImageWidth;
m_bmi2->bmiHeader.biHeight = -m_ImageHeight; // 不然倒置了
m_bmi2->bmiHeader.biPlanes = 1;
m_bmi2->bmiHeader.biBitCount = IPL_DEPTH_8U;
m_bmi2->bmiHeader.biCompression = BI_RGB;
m_bmi2->bmiHeader.biSizeImage=0;
m_bmi2->bmiHeader.biXPelsPerMeter=0;
m_bmi2->bmiHeader.biYPelsPerMeter=0;
m_bmi2->bmiHeader.biClrImportant=0;
m_bmi2->bmiHeader.biClrUsed=0;

for(int i = 0; i < 256; i++)
{
m_bmi2->bmiColors[i].rgbBlue = i;
m_bmi2->bmiColors[i].rgbGreen = i;
m_bmi2->bmiColors[i].rgbRed  = i;
}
}

BackgroundSubtractorMOG mog;
int thresh=130;
Mat FrgroundBkgroundmatProcFrshow;
vector> contour;

//cvNamedWindow(“readvideo“);
while(1)
{

if(!m_cap.read(m_Img))
break;
    m_cap>>m_Img;
    imshow(“readvideo“m_Img);
    
 
mog(m_ImgFrground0.2);
threshold(FrgroundFrgroundthresh255THRESH_BINARY);
mog.getBackgroundImage(Bkground);//返回当前背景图片


Frground.copyTo(matProc);
contour.swap(vector>()); // clear
findContours(matProccontourCV_RETR_EXTERNAL CV_CHAIN_APPROX_SIMPLE Point(0 0));

vector>::const_iterator it=contour.begin(); // 迭代器
while(it!=contour.end())
{
if(contourArea(*it)<50)
{
cont

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    1005568  2017-08-18 09:36  TiquYunDongGuiji\Debug\TiquYunDongGuiji.exe

     文件          0  2017-08-18 09:36  TiquYunDongGuiji\Debug\TiquYunDongGuiji.ilk

     文件    6876160  2017-08-18 09:36  TiquYunDongGuiji\Debug\TiquYunDongGuiji.pdb

     文件   59834368  2017-08-18 09:36  TiquYunDongGuiji\ipch\tiquyundongguiji-d8360f2c\tiquyundongguiji-f65f22cb.ipch

     文件       5474  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\cl.command.1.tlog

     文件     116308  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\CL.read.1.tlog

     文件      13026  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\CL.read.2.tlog

     文件       2258  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\CL.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060-cvtres.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060-cvtres.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060.read.2.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060.read.3.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10060.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10492-cvtres.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10492-cvtres.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10492.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10492.read.2.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10492.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668-cvtres.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668-cvtres.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668.read.2.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668.read.3.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10668.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10996-cvtres.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10996-cvtres.write.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10996.read.1.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10996.read.2.tlog

     文件          2  2017-08-18 09:36  TiquYunDongGuiji\TiquYunDongGuiji\Debug\link.10996.write.1.tlog

............此处省略139个文件信息

评论

共有 条评论