📄 baseclass.cpp
字号:
#include "stdafx.h"
#include "baseclass.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "afxdlgs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CvCapture* pCapture;
CBaseClass::CBaseClass(bool iscam)
{
//创建显示窗口
m_isCam=iscam;
//cvNamedWindow("pImage", CV_WINDOW_AUTOSIZE);
}
CBaseClass::~CBaseClass()
{
}
/*bool CBaseClass::openCamera()
{
if(pCapture!=NULL)
{
cvReleaseCapture(&pCapture);
}
if((pCapture=cvCreateCameraCapture(-1))==NULL)
{
AfxMessageBox("in CBase.OnOpencam(),the pCapture is null");
return false;
}
ASSERT(pCapture);
return true;
}
bool CBaseClass::openFile()
{
CFileDialog dlg(TRUE,0,0,OFN_HIDEREADONLY,"*.avi|所有文件|*.*||",NULL);
if (dlg.DoModal()==IDOK)
{
CString lpszPathName=dlg.GetPathName();
char* path=(LPTSTR)(LPCTSTR)(lpszPathName);
if(pCapture!=NULL)
{
cvReleaseCapture(&pCapture);
}
if((pCapture=cvCreateFileCapture(path))==NULL)
{
AfxMessageBox("in CBase.OnOpenfile(),the pCapture is null");
}
ASSERT(pCapture);
return true;
}
return false;
}*/
/*UINT CBaseClass::process(LPVOID lpParam)
{
CBaseClass* cb=(CBaseClass*)lpParam;
cvNamedWindow("pImage", CV_WINDOW_AUTOSIZE );
cvNamedWindow("pResultImage",CV_WINDOW_AUTOSIZE);
cvMoveWindow("pImage", 30, 10);
cvMoveWindow("pResultImage",cb->width, 10);
while(cb->pImage = cvQueryFrame( cb->pCapture ))
{
cvShowImage("pImage", cb->pImage);
cvShowImage("pResultImage", cb->pResultImage);
}
cvDestroyWindow("pImage");
cvDestroyWindow("pResultImage");
cvReleaseImage(&cb->pImage);
cvReleaseImage(&cb->pResultImage);
cvReleaseCapture(&cb->pCapture);
//cb->pCapture=NULL;
//cb->pImage=NULL;
//cb->pResultImage=NULL;
return 0;
}*/
void CallBackTrackbar(int pos)
{
pos=cvGetTrackbarPos("pImage","pImage");
cvSetCaptureProperty(pCapture,CV_CAP_PROP_POS_FRAMES,(double)pos);
}
void CBaseClass::processImage(CvCapture* pCapture1)
{
//HWND hWnd=GetSafeHwnd();//取得当前窗口的句柄供函数使用。
//AfxBeginThread(process,this,0);//以正常优先级调用。
pCapture=pCapture1;
if(pCapture==NULL)
{
AfxMessageBox("in CBaseClass.processImage(),the pCapture is null");
return;
}
/*double bb=cvGetCaptureProperty(pCapture,CV_CAP_PROP_FRAME_COUNT);
CString str;
str.Format("%d",(int)(bb));
AfxMessageBox(str);*/
IplImage* pImage = cvQueryFrame(pCapture);
double bb=cvGetCaptureProperty(pCapture,CV_CAP_PROP_FRAME_COUNT);
/*IplImage* pResultImage=cvCreateImage(cvSize(pImage->width,pImage->height), IPL_DEPTH_32F,3);
CString str;
str.Format("%d",pResultImage->widthStep);
AfxMessageBox(str);*/
ASSERT(pImage);
int width=pImage->width;
int height=pImage->height;
cvNamedWindow("pImage", CV_WINDOW_AUTOSIZE);
cvNamedWindow("pResultImage",CV_WINDOW_AUTOSIZE);
if(!m_isCam)
{
cvCreateTrackbar("pImage","pImage",0,(int)bb,CallBackTrackbar);
}
cvMoveWindow("pImage", 120, 200);
cvMoveWindow("pResultImage",180+width, 200);
// CString str;
// str.Format("%d",pImage->nChannels);
// AfxMessageBox(str);
//int x=0;
// CString str;
//int xx=1;
while(pImage = cvQueryFrame(pCapture))
{
// CString str;
//x++;
/*if(xx>3385)
{
str="";
str.Format("%d",(int)(xx));
AfxMessageBox(str);
}*/
int pos=(int)cvGetCaptureProperty(pCapture,CV_CAP_PROP_POS_FRAMES);
cvSetTrackbarPos("pImage","pImage",pos-1);
//cvResizeWindow("pImage",width*2,height*2);
cvShowImage("pImage",pImage);
cvShowImage("pResultImage",pImage);
cvSaveImage("image.jpg",pImage);
//如果有按键事件,则跳出循环
//此等待也为cvShowImage函数提供时间完成显示
//等待时间可以根据CPU速度调整
if(cvWaitKey(1) >= 0 || ((!m_isCam) && pos>=(int)(bb)) )
{
break;
}
}
/*str="";
str.Format("%d",(int)(xx));
AfxMessageBox(str);*/
//cvReleaseImage(&pResultImage);
cvDestroyWindow("pImage");
cvDestroyWindow("pResultImage");
//cvReleaseCapture(&pCapture);
//pCapture=NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -