📄 1394camerademo.cpp
字号:
{
theCamera.SetVideoFormat(1);
theCamera.SetVideoMode(5);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941280x960yuv422()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(0);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941280x960rgb()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(1);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941280x960mono()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(2);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941600x1200yuv422()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(3);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941600x1200rgb()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(4);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::On13941600x1200mono()
{
theCamera.SetVideoFormat(2);
theCamera.SetVideoMode(5);
m_pMainWnd->SetWindowPos(NULL, 0, 0, theCamera.m_width+m_borderWidth+12, theCamera.m_height+m_borderHeight+12, SWP_NOMOVE|SWP_NOZORDER);
}
void C1394CameraDemoApp::OnUpdate13942fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][0]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 0);
}
void C1394CameraDemoApp::OnUpdate13944fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][1]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 1);
}
void C1394CameraDemoApp::OnUpdate13947fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][2]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 2);
}
void C1394CameraDemoApp::OnUpdate139415fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][3]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 3);
}
void C1394CameraDemoApp::OnUpdate139430fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][4]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 4);
}
void C1394CameraDemoApp::OnUpdate139460fps(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[theCamera.GetVideoFormat()][theCamera.GetVideoMode()][5]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck(theCamera.GetVideoFrameRate() == 5);
}
void C1394CameraDemoApp::OnUpdate1394160x120yuv444(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][0][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==0));
}
void C1394CameraDemoApp::OnUpdate1394320x240yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][1][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==1));
}
void C1394CameraDemoApp::OnUpdate1394640x480yuv411(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][2][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==2));
}
void C1394CameraDemoApp::OnUpdate1394640x480yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][3][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==3));
}
void C1394CameraDemoApp::OnUpdate1394640x480rgb(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][4][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==4));
}
void C1394CameraDemoApp::OnUpdate1394640x480mono(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[0][5][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==0)&&(theCamera.GetVideoMode()==5));
}
void C1394CameraDemoApp::OnUpdate1394800x600yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][0][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==0));
}
void C1394CameraDemoApp::OnUpdate1394800x600rgb(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][1][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==1));
}
void C1394CameraDemoApp::OnUpdate1394800x600mono(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][2][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==2));
}
void C1394CameraDemoApp::OnUpdate13941024x768yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][3][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==3));
}
void C1394CameraDemoApp::OnUpdate13941024x768rgb(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][4][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==4));
}
void C1394CameraDemoApp::OnUpdate13941024x768mono(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[1][5][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==1)&&(theCamera.GetVideoMode()==5));
}
void C1394CameraDemoApp::OnUpdate13941280x960yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][0][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==0));
}
void C1394CameraDemoApp::OnUpdate13941280x960rgb(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][1][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==1));
}
void C1394CameraDemoApp::OnUpdate13941280x960mono(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][2][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==2));
}
void C1394CameraDemoApp::OnUpdate13941600x1200yuv422(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][3][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==3));
}
void C1394CameraDemoApp::OnUpdate13941600x1200rgb(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][4][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==4));
}
void C1394CameraDemoApp::OnUpdate13941600x1200mono(CCmdUI* pCmdUI)
{
pCmdUI->Enable((theCamera.m_videoFlags[2][5][theCamera.GetVideoFrameRate()]) && !m_showCamera && theCamera.m_cameraInitialized);
pCmdUI->SetCheck((theCamera.GetVideoFormat()==2)&&(theCamera.GetVideoMode()==5));
}
UINT DisplayThreadMethod1(LPVOID pParam)
{
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = theCamera.m_width;
bmi.bmiHeader.biHeight = theCamera.m_height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 1000;
bmi.bmiHeader.biYPelsPerMeter = 1000;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
CMainFrame* pWnd = (CMainFrame *) theApp.GetMainWnd();
RECT rect;
HDC hDC = GetDC(pWnd->m_hWnd);
int x,y,w,h,i=0;
char buf[64];
unsigned long hist[16], sum = 0, t;
float fps;
while (theApp.m_showCamera)
{
t = clock();
if (theCamera.AcquireImage())
AfxMessageBox("Problem Acquiring Image");
pWnd->GetWindowRect(&rect);
h = rect.bottom - rect.top - theApp.m_borderHeight;
w = rect.right - rect.left - theApp.m_borderWidth;
x = w - theCamera.m_width;
x >>= 1;
if(x < 0) x = 0;
y = h - theCamera.m_height;
y >>= 1;
if(y < 0) y = 0;
theCamera.getDIB(theApp.m_pBitmap);
//theApp.ComputeRGB(theCamera.GetVideoFormat(), theCamera.GetVideoMode());
SetDIBitsToDevice(hDC, x, y, theCamera.m_width, theCamera.m_height, 0, 0, 0, theCamera.m_height, theApp.m_pBitmap, &bmi, DIB_RGB_COLORS);
if(i > 15)
sum -= hist[i & 15];
hist[i & 15] = clock() - t;
sum += hist[i & 15];
fps = ( i >= 15 ? 16.0f : (float) (i + 1)) / (float) sum;
sprintf(buf,"Displaying: %2.2f fps",1000.0f * fps);
pWnd->SetStatus(buf);
i++;
}
if (theCamera.StopImageAcquisition())
AfxMessageBox("Problem Stopping Image Acquisition");
delete [] theApp.m_pBitmap;
theApp.m_pBitmap = NULL;
pWnd->SetStatus("Ready");
return (0);
}
void C1394CameraDemoApp::On1394ShowCamera()
{
if (theCamera.StartImageAcquisition())
AfxMessageBox("Problem Starting Image Acquisition");
else
{
m_showCamera = true;
m_pBitmap = new unsigned char [theCamera.m_width * theCamera.m_height * 3];
AfxBeginThread(DisplayThreadMethod1, NULL);
}
}
UINT DisplayThreadMethod2(LPVOID pParam)
{
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = theCamera.m_width;
bmi.bmiHeader.biHeight = theCamera.m_height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 1000;
bmi.bmiHeader.biYPelsPerMeter = 1000;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
CMainFrame* pWnd = (CMainFrame *) theApp.GetMainWnd();
RECT rect;
HDC hDC = GetDC(pWnd->m_hWnd);
int x,y,w,h,i=0;
char buf[64];
unsigned long hist[16], sum = 0, t;
float fps;
while (theApp.m_showCamera)
{
t = clock();
if (theCamera.CaptureImage())
AfxMessageBox("Problem Capturing Image");
pWnd->GetWindowRect(&rect);
h = rect.bottom - rect.top - theApp.m_borderHeight;
w = rect.right - rect.left - theApp.m_borderWidth;
x = w - theCamera.m_width;
x >>= 1;
if(x < 0) x = 0;
y = h - theCamera.m_height;
y >>= 1;
if(y < 0) y = 0;
theCamera.getDIB(theApp.m_pBitmap);
SetDIBitsToDevice(hDC, x, y, theCamera.m_width, theCamera.m_height, 0, 0, 0, theCamera.m_height, theApp.m_pBitmap, &bmi, DIB_RGB_COLORS);
if(i > 15)
sum -= hist[i & 15];
hist[i & 15] = clock() - t;
sum += hist[i & 15];
fps = ( i >= 15 ? 16.0f : (float) (i + 1)) / (float) sum;
sprintf(buf,"Displaying: %2.2f fps",1000.0f * fps);
pWnd->SetStatus(buf);
i++;
}
if (theCamera.StopImageCapture())
AfxMessageBox("Problem Stopping Image Capture");
delete [] theApp.m_pBitmap;
theApp.m_pBitmap = NULL;
return (0);
}
void C1394CameraDemoApp::On1394ShowCamera2()
{
if (theCamera.StartImageCapture())
AfxMessageBox("Problem Starting Image Capture");
else
{
m_showCamera = true;
m_pBitmap = new unsigned char [theCamera.m_width * theCamera.m_height * 3];
AfxBeginThread(DisplayThreadMethod2, NULL);
}
}
void C1394CameraDemoApp::On1394StopCamera()
{
m_showCamera = false;
}
void C1394CameraDemoApp::OnUpdate1394ShowCamera(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_showCamera && theCamera.m_cameraInitialized);
}
void C1394CameraDemoApp::OnUpdate1394ShowCamera2(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_showCamera && theCamera.m_cameraInitialized);
}
void C1394CameraDemoApp::OnUpdate1394StopCamera(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_showCamera);
}
void C1394CameraDemoApp::On1394MeasureFramerate1()
{
CString text;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -