| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- /**************************************************************************************************
- 版本所有(C), 2020-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名: CameraTaskThread.cpp
- 功能描述: 相机标定处理
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期; 2021-12-20
- 最近修改:
- 函数列表:
- 修改历史:
- 1.日 期 :2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- #include "pch.h"
- #include "IDPMSComm.h"
- #include "CameraTaskThread.h"
- IMPLEMENT_DYNCREATE(CameraTaskThread, CUIThread)
- BEGIN_MESSAGE_MAP(CameraTaskThread, CWinThread)
- // {{AFX_MSG_MAP(DynamicTaskThread)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- ON_THREAD_MESSAGE(WM_SINGLE_CAM_CONFIG, OnSingleCamConfig)
- ON_THREAD_MESSAGE(WM_DOUBLE_CAM_CONFIG_STEP1, OnDoubleCamCofigStep1)
- ON_THREAD_MESSAGE(WM_DOUBLE_CAM_CONFIG_STEP2, OnDoubleCamCofigStep2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- CameraTaskThread::CameraTaskThread(void)
- {
- }
- CameraTaskThread::~CameraTaskThread(void)
- {
-
- }
- BOOL CameraTaskThread::InitInstance()
- {
- return TRUE;
- }
- /**************************************************************************************************
- 函 数 名 :OnSingleCamConfig
- 功能描述 :单相机标定
- 输入参数 :略
- 输出参数 :无
- 返 回 值 :void
- **************************************************************************************************/
- void CameraTaskThread::OnSingleCamConfig(WPARAM wParam, LPARAM lParam)
- {
- CString szCommand;
- BOOL bRet = TRUE;
- int iRet = 0;
- DMSResponse *pRes = NULL;
- int iSizeRecevied = 0;
- int iCam = (int)wParam;
- CString szPhotoPath;
- // 获取像片路径
- bRet = this->GetPhotoPath(szPhotoPath);
- if (!bRet) {
- LOG::E(_T("像片路径不存在"));
- this->PostMsg(WM_FAILURE, pRes);
- return;
- }
- // IDPMS通讯器
- IDPMSComm *pComm = new IDPMSComm();
- bRet = pComm->Open();
- if (!bRet) {
- this->PostMsg(WM_START_IDPMS, pRes);
- delete pComm;
- return;
- }
- // 1.结束当前工程
- // szCommand.Format("IDPMS-CD:SET0003");
- // iRet = pComm->SendCommand(szCommand, pRes);
- // if (iRet <= 0) {
- // pComm->Close();
- // this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- // delete pComm;
- // return;
- // }
- // 2. 删除之前的工程文件夹
- CString szCameraFolder;
- szCameraFolder.Format("C:\\PD\\IDPMS\\工程\\%d号相机", iCam);
- Utils::DeleteFolder(szCameraFolder);
- // 3.新建工程
- szCommand.Format("IDCMD0017(PDTL=%d号模板,PDSV=%d号相机,PDDT= false)", iCam, iCam);
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- /* 4.读取路径下相机相片
- szCommand.Format("IDPMS-CD:SET0008");
- bRet = pComm->SendCommand(szCommand, pRes);
- if (!bRet) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- return;
- }
- */
- // // 5.读取当前路径下的全部相片
- // szCommand.Format("IDPMS-CD:SET1701:C:/PD/2号/外参");
- // bRet = pComm->SendCommand(szCommand, pRes);
- // if (!bRet) {
- // pComm->Close();
- // this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- //delete pComm;
- // return;
- // }
- // 6.读取当前路径下所有相片
- szCommand.Format("IDPMS-CD:SET1701:%s", szPhotoPath);
- iRet = pComm->SendCommand(szCommand, pRes, 1);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- //// 5.读取当前路径下的全部相片
- //szCommand.Format("IDPMS-CD:SET1701:D:/BD");
- //iRet = pComm->SendCommand(szCommand, pRes);
- //if (iRet <= 0) {
- // pComm->Close();
- // this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- // delete pComm;
- // return;
- //}
- // 6.开始自动测量
- szCommand.Format("IDCMD0016(PDST=true,PDGO=true,PDCE=true,PDWN=false,PDFP=false,PDSS=true)");
- iRet = pComm->SendCommand(szCommand, pRes, _T("CPDSimpleBundleStats"));
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 关闭通讯器
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_SUCCESS, pRes);
- return;
- }
- /**************************************************************************************************
- 函 数 名 :GetPhotoPath
- 功能描述 :获取最新像片路径
- 输入参数 :略
- 输出参数 :无
- 返 回 值 :void
- **************************************************************************************************/
- BOOL CameraTaskThread::GetPhotoPath(CString &szTargetPath)
- {
- CString szPhotoDir = AppConfig::GetString(_T("Directory"), _T("PhotoDir"));
- if (szPhotoDir.IsEmpty()) return FALSE;
- CFileFind finder;
- CString szSearchDir;
- szSearchDir.Format("%s%s", szPhotoDir, _T("\\*.*"));
- BOOL bFound = finder.FindFile(szSearchDir);
- CTime time0 = 0;
- CString szTargetDir;
- while (bFound) {
- bFound = finder.FindNextFile();
- CString szPath = finder.GetFilePath();
- if (finder.IsDirectory() && !finder.IsDots()) {
- CString szDirName = finder.GetFileName();
- CFileStatus fileStatus;
- CFile::GetStatus(szPhotoDir + "\\" + szDirName, fileStatus);
- CTime time1 = fileStatus.m_ctime;
- if (time0 < time1) {
- szTargetDir = szDirName;
- time0 = time1;
- }
- }
- }
- if (szTargetDir.IsEmpty()) return FALSE;
- szTargetPath.Append(szPhotoDir);
- szTargetPath.Append(_T("\\"));
- szTargetPath.Append(szTargetDir);
- return TRUE;
- }
- /**************************************************************************************************
- 函 数 名 :GetPhotoPath
- 功能描述 :获取最新像片路径
- 输入参数 :略
- 输出参数 :无
- 返 回 值 :void
- **************************************************************************************************/
- BOOL CameraTaskThread::GetFileName(CString &szPath, CString szPrefix, CString &szTargetFile)
- {
- if (szPath.IsEmpty()) return FALSE;
- int iPrefixLen = szPrefix.GetLength();
- CString szTName;
- CFileFind ff;
- CString szFilter;
- szFilter.Format("%s\\%s*.TDX", szPath, szPrefix);
- BOOL bFound = ff.FindFile(szFilter);
- CTime time0 = 0;
- CString szTargetDir;
- int iTIdex = 0;
- while (bFound) {
- bFound = ff.FindNextFile();
- CString szPath = ff.GetFilePath();
- if (!ff.IsDirectory() && !ff.IsDots()) {
- CString szFileTitle = ff.GetFileTitle();
- CString strIdx = szFileTitle.Right(szFileTitle.GetLength()- iPrefixLen);
- int idex = _ttoi(strIdx);
- if (idex > iTIdex) {
- szTName.Format("%s", szFileTitle);
- iTIdex = idex;
- }
- }
- }
- if (szTName.IsEmpty()) return FALSE;
- szTargetFile.Empty();
- szTargetFile.Append(szTName);
- return TRUE;
- }
- /**************************************************************************************************
- 函 数 名 :OnDoubleCamCofigStep1
- 功能描述 :双相机外参标定:建立工程
- 输入参数 :略
- 输出参数 :无
- 返 回 值 :void
- **************************************************************************************************/
- void CameraTaskThread::OnDoubleCamCofigStep1(WPARAM wParam, LPARAM lParam)
- {
- CString szCommand;
- BOOL bRet = TRUE;
- int iRet = 0;
- DMSResponse *pRes = NULL;
- int iSizeRecevied = 0;
- // IDPMS通讯器
- IDPMSComm *pComm = new IDPMSComm();
- bRet = pComm->Open();
- if (!bRet) {
- this->PostMsg(WM_START_IDPMS, pRes);
- delete pComm;
- return;
- }
-
- // 1.结束当前工程
- szCommand.Format("IDPMS-CD:SET0003");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
-
- // 2.删除之前的工程文件
- CString szCameraFolder;
- szCameraFolder.Format("C:\\PD\\IDPMS\\工程\\%s_%s_双相机", m_szEquipTypeCode, m_szEquipCode);
- Utils::DeleteFolder(szCameraFolder);
- // 3. Copy相机驱动文件
- CString szSourceCam;
- CString szTargetCam;
- szSourceCam.Format("C:\\PD\\IDPMS\\工程\\1号相机\\BDAData\\PDDT-IO50M-0001-7103HKFDJ-25.cam");
- szTargetCam.Format("C:\\Program Files\\PD\\IDPMS\\PDTemplate\\双相机\\PDDT-IO50M-0001-7103HKFDJ-25.cam");
- CopyFile(szSourceCam, szTargetCam, FALSE);
- szSourceCam.Format("C:\\PD\\IDPMS\\工程\\2号相机\\BDAData\\PDDT-IO50M-0002-7103HKFDJ-25.cam");
- szTargetCam.Format("C:\\Program Files\\PD\\IDPMS\\PDTemplate\\双相机\\PDDT-IO50M-0002-7103HKFDJ-25.cam");
- CopyFile(szSourceCam, szTargetCam, FALSE);
-
- // 4.双相机工程建立
- szCommand.Format("IDCMD0017(PDTL=双相机,PDSV=%s_%s_双相机,PDDT= false)", m_szEquipTypeCode, m_szEquipCode);
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 关闭通讯器
- pComm->Close();
- delete pComm;
- // 向视图发送完成消息
- this->PostMsg(WM_CAM_CONFIG_SUCCESS, pRes);
- }
- /**************************************************************************************************
- 函 数 名 :OnDoubleCamCofigStep2
- 功能描述 :双相机外参标定:外参标定
- 输入参数 :略
- 输出参数 :无
- 返 回 值 :void
- **************************************************************************************************/
- void CameraTaskThread::OnDoubleCamCofigStep2(WPARAM wParam, LPARAM lParam)
- {
- CString szCommand;
- BOOL bRet = TRUE;
- BOOL iRet = 0;
- DMSResponse *pRes = NULL;
- int iSizeRecevied = 0;
- // 打开通讯器
- IDPMSComm *pComm = new IDPMSComm();
- bRet = pComm->Open();
- if (!bRet) {
- this->PostMsg(WM_START_IDPMS, pRes);
- delete pComm;
- return;
- }
-
- // 1.选择机架文件作为模板
- szCommand.Format("IDPMS-CD:SET1401:PDFN=机架");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 2.拍摄一次
- szCommand.Format("IDPMS-CD:SET2901");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- Sleep(1000);
- // 3.选择机架上建立坐标点
- CString szFileFind;
- CString szTargetPath ;
- szTargetPath.Format("C:\\PD\\IDPMS\\工程\\%s_%s_双相机", m_szEquipTypeCode, m_szEquipCode);
- bRet = GetFileName(szTargetPath, _T("TRI3D E"), szFileFind);
- if (!bRet) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- szCommand.Format("IDCMD0025(PDFN=%s,PDMP=flase, PDDP=flase, PDCP=flase, PDPL=C1 C2 C3)", szFileFind);
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 4.将机架上建立坐标点拷贝到RO3D
- szCommand.Format("IDCMD0032(PDFN=RO3D,PDMP=true, PDDP=true, PDCP=true, PDAP=flase)");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 4.设置RO3D为驱动
- szCommand.Format("IDCMD0004(PDFN=RO3D)");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 3.轴对准
- szCommand.Format("IDPMS-CD:SET3701:p1=C1:p2=C2:p3=C3:p1x=Y:p1y=Z:p1z=X:p2type=type:p3type=type:sys=frame");
- iRet = pComm->SendCommand(szCommand, pRes);
- if (iRet <= 0) {
- pComm->Close();
- this->PostMsg(WM_CAM_CONFIG_FAILURE, pRes);
- delete pComm;
- return;
- }
- // 3.双相机快速标定
- //szCommand.Format("IDPMS-CD:SET2701");
- //iRet = pComm->SendCommand(szCommand);
- //if (iRet <= 0) {
- // szResult.Format("%s", pRes);
- // pComm->Close();
- // return FALSE;
- //}
- // 关闭通讯器
- pComm->Close();
- delete pComm;
- // 向视图发送完成消息
- this->PostMsg(WM_CAM_CONFIG_SUCCESS, pRes);
- }
|