www.pudn.com > CBVRtest.rar > CBVRtestsystemView.cpp
// CBVRtestsystemView.cpp : implementation of the CCBVRtestsystemView class
//
#include "stdafx.h"
#include "CBVRtestsystem.h"
#include "CBVRtestsystemDoc.h"
#include "CBVRtestsystemView.h"
#include "MyHSV.h"
#include "MyRGB.h"
#include "KFE.h"
#include "SBD.h"
#include "InputDlg.h"
#include "vfw.h"
#include "al_cf.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCBVRtestsystemView
IMPLEMENT_DYNCREATE(CCBVRtestsystemView, CScrollView)
BEGIN_MESSAGE_MAP(CCBVRtestsystemView, CScrollView)
//{{AFX_MSG_MAP(CCBVRtestsystemView)
ON_COMMAND(ID_VIDEO_OPEN, OnVideoOpen)
ON_COMMAND(ID_SBD_2, OnSbd2)
ON_COMMAND(ID_SBD_1, OnSbd1)
ON_UPDATE_COMMAND_UI(ID_VIDEO_PLAY, OnUpdateVideoPlay)
ON_UPDATE_COMMAND_UI(ID_VIDEO_PAUSE, OnUpdateVideoPause)
ON_UPDATE_COMMAND_UI(ID_VIDEO_STEPBACK, OnUpdateVideoStepback)
ON_UPDATE_COMMAND_UI(ID_VIDEO_STEPFORWARD, OnUpdateVideoStepforward)
ON_UPDATE_COMMAND_UI(ID_VIDEO_STOP, OnUpdateVideoStop)
ON_COMMAND(ID_VIDEO_PAUSE, OnVideoPause)
ON_COMMAND(ID_VIDEO_PLAY, OnVideoPlay)
ON_COMMAND(ID_VIDEO_STEPBACK, OnVideoStepback)
ON_COMMAND(ID_VIDEO_STEPFORWARD, OnVideoStepforward)
ON_COMMAND(ID_VIDEO_STOP, OnVideoStop)
ON_WM_TIMER()
ON_COMMAND(ID_VIDEO_TOFRAME, OnVideoToframe)
ON_UPDATE_COMMAND_UI(ID_VIDEO_TOFRAME, OnUpdateVideoToframe)
ON_COMMAND(ID_KFE_1, OnKfe1)
ON_COMMAND(ID_KFE_2, OnKfe2)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCBVRtestsystemView construction/destruction
CCBVRtestsystemView::CCBVRtestsystemView()
{
// TODO: add construction code here
m_frameH=0;
m_frameW=0;
pData=NULL;
m_maxFrame=0;
pfi=NULL;
gapgf=NULL;
m_HSV=0;
m_RGB=0;
Point[0]=0;
Point[1]=0;
bmp1.LoadBitmap(IDB_BMP1);
m_vPlay=m_vPause=m_vStop=m_vStepBack=m_vStepForward=m_vToFrame=false;
}
CCBVRtestsystemView::~CCBVRtestsystemView()
{
}
BOOL CCBVRtestsystemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCBVRtestsystemView drawing
void CCBVRtestsystemView::OnDraw(CDC* pDC)
{
CCBVRtestsystemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if (gapgf)
{
CClientDC dc(this);
m_printInfor.Format("视频文件名: %s",filename);
dc.TextOut(300,10,m_printInfor);
m_printInfor.Format("视频长度: %d帧",m_maxFrame);
dc.TextOut(300,30,m_printInfor);
dc.LineTo(500,500);
DrawAviByNum(10,10,m_frameNumber);
if(m_kfnum) //记录当前算法关键帧的数量
{
int x=10,y=150;
for(int i=0;i900)
{
x=10;
y+=m_frameH+20;
}
}
}
if(m_sbnum)//记录当前算法镜头边界的数量
{
dc.TextOut(10,200,"镜头边界:");
int x1=80,y1=200;
for(int i=0;i900)
{
x1=60;
y1+=25;
}
}
}
if (m_misbdnum)
{
CClientDC dc(this);
dc.TextOut(10,200,"切变:");
int x1=50,y1=200,i=0;
while (m_sb[i])
{
if ((m_sb[i]+1)==m_sb[i+1])
{
m_printInfor.Format("%d帧到%d帧 ",m_sb[i],m_sb[i+1]);
dc.TextOut(x1,y1,m_printInfor);
x1=x1+100;
if (x1>800)
{
x1=80;
y1+=25;
}
}
i=i+2;
}
if (x1==50)
{
dc.TextOut(x1,y1,"无");
}
y1=y1+30;
dc.TextOut(10,y1,"渐变:");
x1=50;
i=0;
while (m_sb[i])
{
if ((m_sb[i]+1)!=m_sb[i+1])
{
m_printInfor.Format("%d帧到%d帧 ",m_sb[i],m_sb[i+1]);
dc.TextOut(x1,y1,m_printInfor);
x1=x1+100;
if (x1>800)
{
x1=80;
y1+=25;
}
}
i=i+2;
}
if (x1==50)
{
dc.TextOut(x1,y1,"无");
}
i=0;
x1=70;
y1=y1+30;
dc.TextOut(10,y1,"闪光灯:");
while(m_light[i])
{
m_printInfor.Format("%d帧 ",m_light[i]);
dc.TextOut(x1,y1,m_printInfor);
x1=x1+50;
if (x1>800)
{
x1=60;
y1+=25;
}
i++;
}
if (x1==70)
{
dc.TextOut(x1,y1,"无");
}
}
}
}
void CCBVRtestsystemView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CCBVRtestsystemView printing
BOOL CCBVRtestsystemView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCBVRtestsystemView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCBVRtestsystemView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCBVRtestsystemView diagnostics
#ifdef _DEBUG
void CCBVRtestsystemView::AssertValid() const
{
CScrollView::AssertValid();
}
void CCBVRtestsystemView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CCBVRtestsystemDoc* CCBVRtestsystemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCBVRtestsystemDoc)));
return (CCBVRtestsystemDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
//选择视频文件
void CCBVRtestsystemView::OnVideoOpen()
{
HRESULT hr;
AVIFileInit();
static char szFilter[]="AVI文件(*.avi)|*.avi||";
CFileDialog dlg(true,"avi",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if (dlg.DoModal()==IDOK)
{
filename=dlg.GetPathName();
pfi=new AVIFILEINFO;
hr = AVIFileOpen(&pfile,filename, OF_READ,NULL);
hr= AVIFileInfo(pfile, pfi, sizeof(AVIFILEINFO));
m_frameW=pfi->dwWidth; //图象宽、高
m_frameH=pfi->dwHeight;
m_maxFrame=pfi->dwLength;
m_eigenValue=new float[m_maxFrame];
memset(m_eigenValue,0,m_maxFrame*sizeof(float));
hr=AVIFileGetStream(pfile,&pavi,streamtypeVIDEO, 0);
AVISTREAMINFO avis;
hr=AVIStreamInfo(pavi, &avis, sizeof(avis));
gapgf = AVIStreamGetFrameOpen(pavi,0);//(BITMAPINFOHEADER *)AVIGETFRAMEF_BESTDISPLAYFMT );
if (gapgf)
{
Invalidate();
m_kfnum=m_sbnum=m_misbdnum=m_lightnum=0;
m_sb=new int[m_maxFrame];
m_kf=new int[m_maxFrame];
m_light=new int[m_maxFrame];
memset(m_sb,0,m_maxFrame*4);
memset(m_kf,0,m_maxFrame*4);
memset(m_light,0,m_maxFrame*4);
m_frameNumber=m_frameNF=m_frameNB=0;
m_vPlay=m_vStepForward=m_vToFrame=true;
m_vStop=m_vStepBack=m_vPause=false;
DrawAviByNum(10,10,0);
}
}
else
{
CClientDC dc(this);
m_printInfor.Format("请选择视频");
dc.TextOut(100,100,m_printInfor);
}
}
/////////////////////////////////////////////////////////////////////////////
//根据位置和帧号在视图内显示一帧图像
void CCBVRtestsystemView::DrawAviByNum(int position_x, int position_y, int framenumber)
{
LPBITMAPINFOHEADER lpbi=(LPBITMAPINFOHEADER)AVIStreamGetFrame(gapgf,framenumber);
if (lpbi==NULL){
//MessageBox("Not open yet");
return;
}
BYTE* BmpData;
float total=0;
BmpData=(BYTE*)(lpbi)+lpbi->biSize;
int **R=new int*[m_frameW]; //m_frameW图像高
int **G=new int*[m_frameW];
int **B=new int*[m_frameW];
for (int x=0;x=0;j--)
for(int i=0;i900)
{
x1=60;
y1+=25;
}
}
}
else
{
if (!gapgf)
{
m_printInfor.Format("请选择视频文件");
}
dc.TextOut(50,50,m_printInfor);
}
}
//镜头边界检测_基于直方图的镜头边界检测
void CCBVRtestsystemView::OnSbd2()
{
// TODO: Add your command handler code here
int i;
CClientDC dc(this);
if (gapgf)
{
SBD sbd(gapgf,m_frameW,m_frameH,m_maxFrame,2);
m_sbnum=sbd.sbnumber;
memcpy(m_sb,sbd.sb,m_sbnum*sizeof(int));
dc.TextOut(10,200,"镜头边界:");
int x1=80,y1=200;
for(i=0;i900)
{
x1=60;
y1+=25;
}
}
}
else
{
CClientDC dc(this);
if (!gapgf)
{
m_printInfor.Format("请选择视频文件");
}
dc.TextOut(50,50,m_printInfor);
}
}
///////////////////////////////////////////////////////////////////////////////
//菜单项:关键帧提取算法
//关键帧提取算法_帧平均法提取关键帧
void CCBVRtestsystemView::OnKfe1()
{
// TODO: Add your command handler code here
if (gapgf)
{
KFE kfe(gapgf,m_frameW,m_frameH,m_maxFrame,1);
int x=10,y=150;
{
m_kfnum=kfe.kfnumber;
memcpy(m_kf,kfe.kf,m_kfnum*sizeof(int));
}
Invalidate();
for(int i=0;i(1-total/(3*m_frameH*m_frameW*256+0.00));
}
//两帧HSV图像直方图比较
float CCBVRtestsystemView::CompFrameByHSVHistogram(MyHSV f1, MyHSV f2)
{
int i,j,k;
float total=0;
for(i=0;iEnable(m_vPlay);
}
void CCBVRtestsystemView::OnUpdateVideoPause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_vPause);
}
void CCBVRtestsystemView::OnUpdateVideoStepback(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_vStepBack);
}
void CCBVRtestsystemView::OnUpdateVideoStepforward(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_vStepForward);
}
void CCBVRtestsystemView::OnUpdateVideoStop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_vStop);
}
void CCBVRtestsystemView::OnUpdateVideoToframe(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_vToFrame);
}
//视频播放控件:暂停
void CCBVRtestsystemView::OnVideoPause()
{
// TODO: Add your command handler code here
KillTimer(1);
m_vPause=false;
m_vPlay=m_vStop=m_vStepBack=m_vStepForward=true;
}
//视频播放控件:播放
void CCBVRtestsystemView::OnVideoPlay()
{
// TODO: Add your command handler code here
SetTimer(1,0,NULL);
m_vPlay=m_vStepBack=m_vStepForward=false;
m_vPause=m_vStop=true;
}
//视频播放控件:向后一帧
void CCBVRtestsystemView::OnVideoStepback()
{
// TODO: Add your command handler code here
if (m_frameNB>=0)
{
DrawAviByNum(10,10,m_frameNB--);
m_frameNumber=m_frameNB+2;
m_frameNF=m_frameNB+2;
m_vPlay=m_vStop=true;
m_vStepForward=true;
}
else
{
m_vStepBack=false;
}
}
//视频播放控件:向前一帧
void CCBVRtestsystemView::OnVideoStepforward()
{
// TODO: Add your command handler code here
if (m_frameNF<=m_maxFrame)
{
DrawAviByNum(10,10,m_frameNF++);
m_frameNumber=m_frameNF;
m_frameNB=m_frameNF-2;
m_vStepBack=m_vStop=true;
}
else
{
m_vStepForward=false;
}
}
//视频播放控件:停止、复位
void CCBVRtestsystemView::OnVideoStop()
{
// TODO: Add your command handler code here
KillTimer(1);
DrawAviByNum(10,10,0);
m_frameNF=m_frameNumber=0;
m_vPlay=m_vStepForward=true;
m_vPause=m_vStop=m_vStepBack=false;
}
//视频播放控件:到指定帧
void CCBVRtestsystemView::OnVideoToframe()
{
// TODO: Add your command handler code here
InputDlg selectframedlg;
selectframedlg.m_title="指定帧";
m_printInfor.Format(" 范围:0-%d",m_maxFrame-1);
selectframedlg.m_title2=m_printInfor;
if (selectframedlg.DoModal()==IDOK)
{
if(int(selectframedlg.m_data)m_maxFrame)
{
m_frameNumber=m_maxFrame;
m_vPlay=m_vPause=m_vStepForward=false;
m_vStop=m_vStepBack=true;
KillTimer(1);
}
m_frameNB=m_frameNumber-2;
m_frameNF=m_frameNumber;
}
}