- 环境:vs2019,Unicode,MFC,C++,Halcon
- 代码:
#pragma once
#include
#include
#include
#include
#include
#include
#include "HalconCpp.h"
#include "HDevThread.h"bool CMy005MFCHalconDlg::SaveCaliImage()
{bCapture = true;USES_CONVERSION;string strPath;std::ostringstream ostr;CString csIndex;CString csPath;CFileFind finder;BOOL bWorking = false;iSaveImgIndex = 0;strPath = "D:\\Img";csIndex.Format(_T("%02d"), iSaveImgIndex); // 格式化 00、01、02iSaveImgIndex = 1;strPath = strPath + "\\" + "calib_distorted_" + T2A(csIndex) + ".png";csPath = strPath.c_str();while (1){bWorking = finder.FindFile(csPath);if (bWorking){GetTxtValue("ImgSavePath", &strPath);csIndex.Format(_T("%02d"), iSaveImgIndex);++iSaveImgIndex;strPath = strPath + "\\" + "calib_distorted_" + T2A(csIndex) + ".png";csPath = strPath.c_str();}else{// string 转 HTupelHTuple HTImgPath = strPath.c_str();WriteImage(ho_RealImage, "png", 0, HTImgPath);break;}}bCapture = false;return true;
}
- 说明:该代码配合MFC中自定义的拍照按钮使用,每点击一次按钮则保存一张图片,保存的图片格式为png,使用的WriteImage函数是Halcon的函数,图片文件前缀为“calib_distorted_”,是根据图片文件数量来命名图片序号,如“calib_distorted_01.png”、“calib_distorted_02.png”、“calib_distorted_03.png”。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!