生活随笔
收集整理的這篇文章主要介紹了
MFC Halcon WriteImage自动添加序号保存图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
環境: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 轉 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”。
總結
以上是生活随笔為你收集整理的MFC Halcon WriteImage自动添加序号保存图片的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。