📄 calibrtwocamadlg.cpp
字号:
}
delete []p2p_InputImages;
}
}
BOOL CCalibrtwocamaDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
McSetParamInt(m_Channel1, MC_ChannelState, MC_ChannelState_IDLE);
McSetParamInt(m_Channel2, MC_ChannelState, MC_ChannelState_IDLE);
// Delete the channel
McDelete(m_Channel1);
McDelete(m_Channel2);
McCloseDriver ();
return CDialog::DestroyWindow();
}
void CCalibrtwocamaDlg::DispCam1()
{
CRect rect;
if (m_pCurrent1==NULL) return;
GetDlgItem(IDC_VID1)->GetClientRect(&rect);
CDC *pDC;
pDC = GetDlgItem(IDC_VID1)->GetWindowDC();
// Retrieve image size in the document
CSize siz = rect.Size();
int SizeX = m_SizeX;
int SizeY = m_SizeY;
int BufferPitch = m_BufferPitch;
// Configure the bitmap info according to the image size
m_pBitmapInfo->bmiHeader.biWidth = BufferPitch / ( m_pBitmapInfo->bmiHeader.biBitCount / 8); // Width = Pitch(bytes) divided by the number of bytes per pixel
m_pBitmapInfo->bmiHeader.biHeight = -SizeY ;
SetStretchBltMode(pDC->GetSafeHdc(), COLORONCOLOR);
//// Display
StretchDIBits (pDC->GetSafeHdc(), 0, 0, siz.cx, siz.cy,
0, 0, SizeX, SizeY,
m_pCurrent1, m_pBitmapInfo, DIB_RGB_COLORS,SRCCOPY);
//SetDIBitsToDevice(pDC->GetSafeHdc(),0,0,siz.cx,siz.cy,0,0,0,SizeY,m_pCurrent1,m_pBitmapInfo,DIB_RGB_COLORS);
// Advice the callback the screen refresh is terminated
m_bScreenRefreshCompleted1 = true;
// Display channel info on status bar
// Retrieve the channel state
McGetParamInt (m_Channel1, MC_ChannelState, &m_ChannelState);
// Retrieve the frame rate
double frameRate_Hz;
McGetParamFloat(m_Channel1, MC_PerSecond_Fr, &frameRate_Hz);
// Display frame rate and channel state
m_strChannelStatus.Format("Camera 1 Frame Rate: %.2f, Channel State: %s", frameRate_Hz,
(m_ChannelState == MC_ChannelState_ACTIVE? "ACTIVE" : "NOT ACTIVE"));
GetDlgItem(IDC_SHOWCM1)->SetWindowText(m_strChannelStatus);
UpdateData();
}
void CCalibrtwocamaDlg::DispCam2()
{
CRect rect;
if (m_pCurrent2==NULL) return;
GetDlgItem(IDC_VID2)->GetClientRect(&rect);
CDC *pDC;
pDC = GetDlgItem(IDC_VID2)->GetWindowDC();
// Retrieve image size in the document
CSize siz = rect.Size();
int SizeX = m_SizeX;
int SizeY = m_SizeY;
int BufferPitch = m_BufferPitch;
// Configure the bitmap info according to the image size
m_pBitmapInfo->bmiHeader.biWidth = BufferPitch / ( m_pBitmapInfo->bmiHeader.biBitCount / 8); // Width = Pitch(bytes) divided by the number of bytes per pixel
m_pBitmapInfo->bmiHeader.biHeight = -SizeY ;
SetStretchBltMode(pDC->GetSafeHdc(), COLORONCOLOR);
//// Display
StretchDIBits (pDC->GetSafeHdc(), 0, 0, siz.cx, siz.cy,
0, 0, SizeX, SizeY,
m_pCurrent2, m_pBitmapInfo, DIB_RGB_COLORS,SRCCOPY);
//SetDIBitsToDevice(pDC->GetSafeHdc(),0,0,siz.cx,siz.cy,0,0,0,SizeY,m_pCurrent1,m_pBitmapInfo,DIB_RGB_COLORS);
// Advice the callback the screen refresh is terminated
m_bScreenRefreshCompleted2 = true;
// Display channel info on status bar
// Retrieve the channel state
McGetParamInt (m_Channel2, MC_ChannelState, &m_ChannelState);
// Retrieve the frame rate
double frameRate_Hz;
McGetParamFloat(m_Channel2, MC_PerSecond_Fr, &frameRate_Hz);
// Display frame rate and channel state
m_strChannelStatus.Format("Camera 2 Frame Rate: %.2f, Channel State: %s", frameRate_Hz,
(m_ChannelState == MC_ChannelState_ACTIVE? "ACTIVE" : "NOT ACTIVE"));
GetDlgItem(IDC_SHOWCM2)->SetWindowText(m_strChannelStatus);
UpdateData();
}
void CCalibrtwocamaDlg::OnStop()
{
// TODO: Add your control notification handler code here
McSetParamInt(m_Channel1, MC_ChannelState, MC_ChannelState_IDLE);
McSetParamInt(m_Channel2, MC_ChannelState, MC_ChannelState_IDLE);
GetDlgItem(IDC_LEFTCA)->EnableWindow(FALSE);
GetDlgItem(IDC_RIGHTCA)->EnableWindow(FALSE);
GetDlgItem(IDC_SAVE)->EnableWindow(FALSE);
GetDlgItem(IDC_BCALIA)->EnableWindow(FALSE);
lfg=0;rfg=0;
}
void CCalibrtwocamaDlg::OnActive()
{
// TODO: Add your control notification handler code here
McSetParamInt(m_Channel1, MC_ChannelState, MC_ChannelState_ACTIVE);
McSetParamInt(m_Channel2, MC_ChannelState, MC_ChannelState_ACTIVE);
GetDlgItem(IDC_LEFTCA)->EnableWindow(TRUE);
GetDlgItem(IDC_RIGHTCA)->EnableWindow(TRUE);
GetDlgItem(IDC_SAVE)->EnableWindow(TRUE);
lfg=0;rfg=0;
}
void CCalibrtwocamaDlg::OnLeftca()
{
// TODO: Add your control notification handler code here
// Choose the video standard
DispCam1();
McSetParamInt(m_Channel1, MC_ChannelState, MC_ChannelState_IDLE);
//GetDlgItem(IDC_BCALIA)->EnableWindow(FALSE);
m_nLeftCamNo++;
UpdateData();
lfg=1;rfg=0;
}
void CCalibrtwocamaDlg::OnRightca()
{
// TODO: Add your control notification handler code here
DispCam2();
McSetParamInt(m_Channel2, MC_ChannelState, MC_ChannelState_IDLE);
//GetDlgItem(IDC_BCALIA)->EnableWindow(FALSE);
m_nRightCamNO++;
UpdateData();
rfg=1;lfg=0;
}
void CCalibrtwocamaDlg::OnSave()
{
// TODO: Add your control notification handler code here
BITMAPFILEHEADER bmfHdr; // Header for Bitmap file
WORD hdLength = sizeof(BITMAPINFOHEADER);
CFile *pFile;
pFile = new CFile;
CString strFile;
char buffer[5];
// Fill in file type (first 2 bytes must be "BM" for a bitmap)
bmfHdr.bfType = 0x4d42; // "BM"
// Calculate the file size by adding the DIB size to sizeof(BITMAPFILEHEADER)
bmfHdr.bfSize = m_SizeX*m_SizeY*3 + sizeof(BITMAPFILEHEADER);
bmfHdr.bfReserved1 = 0;
bmfHdr.bfReserved2 = 0;
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + m_pBitmapInfo->bmiHeader.biSize;
TRY{
if (lfg==1&&rfg==0)
{
strFile="..\\CaliData\\leftcap";
strFile=strFile+::itoa(m_nLeftCamNo,buffer,10)+".bmp";
//strcpy(PathName,"..\\CaliData\\leftcap"+::itoa(m_nLeftCamNo,buffer,10)+".bmp");
pFile->Open(strFile,CFile::modeCreate | CFile::modeWrite);
// Write the file header
pFile->Write((BYTE*)&bmfHdr, sizeof(BITMAPFILEHEADER));
// Write the DIB header
pFile->Write(m_pBitmapInfo, hdLength);
// pFile->Write((BYTE*)(m_pBitmapInfo->bmiHeader), hdLength);
// Write the DIB bits
pFile->Write(m_pCurrent1, m_SizeX*m_SizeY*3);
pFile->Close();
}
else if(lfg==0&&rfg==1)
{
strFile="..\\CaliData\\rightcap";
strFile=strFile+::itoa(m_nLeftCamNo,buffer,10)+".bmp";
//strcpy(PathName,"..\\CaliData\\rightcap"+::itoa(m_nLeftCamNo,buffer,10)+".bmp");
pFile->Open(strFile,CFile::modeCreate | CFile::modeWrite);
// Write the file header
pFile->Write((BYTE*)&bmfHdr, sizeof(BITMAPFILEHEADER));
// Write the DIB header
pFile->Write(m_pBitmapInfo, hdLength);
// pFile->Write((BYTE*)(m_pBitmapInfo->bmiHeader), hdLength);
// Write the DIB bits
pFile->Write(m_pCurrent2, m_SizeX*m_SizeY*3);
pFile->Close();
}
lfg=0; rfg=0;
}
CATCH (CFileException, e) {
AfxMessageBox("Write error--possible disk full condition");
}
END_CATCH
delete pFile;
//GetDlgItem(IDC_BCALIA)->EnableWindow(TRUE);
}
void CCalibrtwocamaDlg::OnLoadSelected()
{
// TODO: Add your control notification handler code here
CFileDialog dlg (TRUE,
"*.*",
"*.*",
OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY |
OFN_ALLOWMULTISELECT ,
"All Files (*.*)|*.*|BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg|TIFF Files (*.tif;*.tiff)|*.tif; *.tiff||",
this);
char * buffer = new char[2000];
for(int i=0; i<2000; i++)
{
buffer[i]=0;
}
dlg.m_ofn.lpstrTitle = "Open File...";
dlg.m_ofn.lpstrFile = buffer;
dlg.m_ofn.nMaxFile = 2000;
if (dlg.DoModal () == IDCANCEL){
delete []buffer; buffer = NULL;
return;
}
CString tempFileName,tmfname;
POSITION pos = dlg.GetStartPosition();
int counter = 0;
while(true)
{
if( pos != NULL )
{
tempFileName = dlg.GetNextPathName(pos);
counter ++;
tmfname=dlg.GetFileName();
if (tmfname.Left(4)=="left")
califlag="left";
else if(tmfname.Left(5)=="right")
califlag="right";
else
califlag="";
}
else break;
}
m_nImageNumber = counter;
p2p_InputImages = new IplImage *[m_nImageNumber];
delete []m_cstrImageNames;
m_cstrImageNames = new CString [m_nImageNumber];
pos = dlg.GetStartPosition();
for( i=0 ; i<counter; i++)
{
if( pos != NULL )
{
tempFileName = dlg.GetNextPathName(pos);
p2p_InputImages[i] = cvvLoadImage (tempFileName);
if( i==0 )
{
m_ImageRoot.path = tempFileName;
m_ImageRoot.GenerateFileProps();
imgsize.width = p2p_InputImages[0]->width;
imgsize.height = p2p_InputImages[0]->height;
}
m_cstrImageNames[i] = tempFileName.Right(tempFileName.GetLength()-tempFileName.ReverseFind('\\')-1);
}
}
m_nImageNumber=counter;
UpdateData(false);
delete []buffer; buffer = NULL;
}
void CCalibrtwocamaDlg::OnLoad()
{
// TODO: Add your control notification handler code here
// get the number of images to process from the "Number of Images" box
UpdateData();
if( m_nImageNumber == 0 || m_nXHeight == 0 || m_nXWidth == 0)
return;
///Get root file name that will be used to generate 5 filenames of the images
CFileDialog dlg (TRUE,
"*.bmp",
"*.*",
OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY,
"BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg|TIFF Files (*.tif;*.tiff)|*.tif; *.tiff|All Files (*.*)|*.*||",
this);
dlg.m_ofn.lpstrTitle = "Open File...";
dlg.m_ofn.lpstrInitialDir="H:\\";
if (dlg.DoModal () == IDCANCEL)
{
return;
}
CString tempString,tmfname;
tmfname=dlg.GetFileName();
if (tmfname.Left(4)=="left")
califlag="left";
else if(tmfname.Left(5)=="right")
califlag="right";
else
califlag="";
m_ImageRoot.path = dlg.GetPathName ();
m_ImageRoot.GenerateFileProps();
// form the root names....
m_ImageRoot.title = m_ImageRoot.title.Left(m_ImageRoot.title.GetLength()-1);
m_ImageRoot.name = m_ImageRoot.title + '.' + m_ImageRoot.extension;
m_ImageRoot.path = m_ImageRoot.folderPath + '\\' + m_ImageRoot.name;
char buffer[5];
p2p_InputImages = new IplImage *[m_nImageNumber];
delete []m_cstrImageNames; m_cstrImageNames = NULL;
m_cstrImageNames = new CString [m_nImageNumber];
// load images as IplImage*'s
for( int i=0; i<m_nImageNumber; i++)
{
::itoa(i,buffer,10);
tempString = m_ImageRoot.folderPath
+'\\'
+m_ImageRoot.title
+buffer
+"."
+m_ImageRoot.extension;
m_cstrImageNames[i] =m_ImageRoot.title+buffer+"."+m_ImageRoot.extension;
p2p_InputImages[i] = cvvLoadImage (tempString);
if( i==0 )
{
imgsize.width = p2p_InputImages[0]->width;
imgsize.height = p2p_InputImages[0]->height;
}
}
}
void CCalibrtwocamaDlg::OnCalibrate()
{
// TODO: Add your control notification handler code here
UpdateData();
if( m_nImageNumber == 0 )
return;
m_nNumCorners = m_nXHeight*m_nXWidth;
// Extract World and Image Coordinates
FindCorners();
// Find CameraMatrix, Distortion Params, Rotation Matrices, Translation Vectors
CalibrateCamera();
// Backproject Points and Calculate Errors on X and Y direction
CalculateCalibrationErrors( true );
// Generates Reports concerning Calibration and Error
GenerateReport();
// Displays Results.
DisplayReport();
}
void CCalibrtwocamaDlg::FindCorners()
{
m_nNumCorners = m_nXWidth * m_nXHeight;
IplImage* img = 0; // initialize some image arrays
IplImage* img0 = 0;
IplImage* img1 = 0;
IplImage* greyimg = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -