我的需求:我想通过定时器实现不断保存摄像头图片并进行图像处理(halcon算法),也就是每隔5s保存图片然后调用这个processimage函数显示在UI界面上,halcon集成在mfc里面应该配置没有问题,我的程序能够执行一遍,但是执行第二遍就会报错,在一开头就会报错,而且我的picturecontrol控件不更新,不知道什么原因。在MFC的定时器事件中里面重复调用processimage函数并进行显示,希望你能解决我的问题,金额也能追加。
void CDemoMFCDlg::ProcessImage()
{
/*if (HDevWindowStack::IsOpen())
CloseWindow(HDevWindowStack::Pop());*/
//ClearObj(ho_Image); ClearObj(ho_GrayImage); ClearObj(ho_sharp0);
TRACE(_T("开始 ProcessImage\n"));
/*if (HalconCpp::HDevWindowStack::IsOpen())
{
HalconCpp::CloseWindow(HalconCpp::HDevWindowStack::Pop());
}*/
ReadImage(&ho_Image, "D:/A_CODE_ATMV/SDK_AtUsbA_V3.3_halcon2.1/SDK_AtUsbA_V3.3/Demos/DemoMFC/image.bmp");
GetImagePointer1(ho_Image, &hv__, &hv__, &hv_Width, &hv_Height);
SetWindowAttr("background_color", "black");
HWND hwndl = GetDlgItem(IDC_STATIC1)->GetSafeHwnd();
CRect rect;
GetDlgItem(IDC_STATIC1)->GetClientRect(&rect);
//ScreenToClient(&rect);
//Hlong halconWinID;
OpenWindow(0, 0, rect.Width(), rect.Height(), (LONG)hwndl, "visible", "", &hv_WindowHandle);
HDevWindowStack::Push(hv_WindowHandle);
if (HDevWindowStack::IsOpen())
SetColored(HDevWindowStack::GetActive(), 12);
if (HDevWindowStack::IsOpen())
SetDraw(HDevWindowStack::GetActive(), "margin");
SetLineWidth(hv_WindowHandle, 3);
Rgb1ToGray(ho_Image, &ho_GrayImage);
Emphasize(ho_GrayImage, &ho_sharp0, 7, 7, 7.0);
if (HDevWindowStack::IsOpen())
DispObj(ho_sharp0, HDevWindowStack::GetActive());
//mult_image (GrayImage, GrayImage, Mult_image2, 0.006, 0)
//AfxMessageBox(_T("success"));
// Call this after you've done all the image processing and the image is ready to be displayed
CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC1);
pStatic->Invalidate(TRUE); // TRUE to erase the background as well
pStatic->UpdateWindow(); // Forces the control to be redrawn immediately
//计数
processImageCounter++;
CString strCallCount;
strCallCount.Format(_T("%d "), processImageCounter);
m_staticCallCount.SetWindowText(strCallCount);
}