MFC Halcon WriteImage自动添加序号保存图片

  1. 环境:vs2019,Unicode,MFC,C++,Halcon
  2. 代码:
    
    #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、02
    	iSaveImgIndex = 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 转 HTupel
    			HTuple HTImgPath = strPath.c_str();
    			WriteImage(ho_RealImage, "png", 0, HTImgPath);
    			break;
    		}
    	}
    
    	bCapture = false;
    	return true;
    }

     

  3. 说明:该代码配合MFC中自定义的拍照按钮使用,每点击一次按钮则保存一张图片,保存的图片格式为png,使用的WriteImage函数是Halcon的函数,图片文件前缀为“calib_distorted_”,是根据图片文件数量来命名图片序号,如“calib_distorted_01.png”、“calib_distorted_02.png”、“calib_distorted_03.png”。

你可能感兴趣的:(C++,MFC,Halcon,经验分享,c++,mfc)