生活随笔
收集整理的這篇文章主要介紹了
MFC Halcon WriteImage自动添加序号保存图片
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
環(huán)境:vs2019,Unicode,MFC,C++,Halcon代碼:
#pragma once
#include <afxwin.h>
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
#include <direct.h>
#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 轉(zhuǎn) HTupelHTuple HTImgPath = strPath.c_str();WriteImage(ho_RealImage, "png", 0, HTImgPath);break;}}bCapture = false;return true;
} ?
說明:該代碼配合MFC中自定義的拍照按鈕使用,每點(diǎn)擊一次按鈕則保存一張圖片,保存的圖片格式為png,使用的WriteImage函數(shù)是Halcon的函數(shù),圖片文件前綴為“calib_distorted_”,是根據(jù)圖片文件數(shù)量來命名圖片序號(hào),如“calib_distorted_01.png”、“calib_distorted_02.png”、“calib_distorted_03.png”。
總結(jié)
以上是生活随笔為你收集整理的MFC Halcon WriteImage自动添加序号保存图片的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。