一 功能
實時顯示通過調(diào)用halcon函數(shù)處理后的圖像
二 前期
相機大恒MER-500-7UM,,系統(tǒng)win7-64位,,編程環(huán)境vs2010,,軟件halcon12.0,基礎(chǔ)開發(fā)為大恒自帶樣例SDK包(C:\Program Files\Daheng Imavision\MER-Series\Samples\VC SDK\src\GxSingleCamMono)
三 方法
先說總體思想,,直接在SDK開發(fā)基礎(chǔ)上增加圖像處理功能,。先將bitmap轉(zhuǎn)成HObject(必須要把bitmap格式轉(zhuǎn)成halcon相關(guān)格式,然后才能調(diào)用halcon函數(shù)庫處理圖像),,然后調(diào)用halcon庫函數(shù)(halcon生成的圖像處理cpp代碼片段),,最后再將處理后的圖像格式由HObject改成bitmap,通過大恒自身帶的函數(shù)顯示出來,。
1 打開halcon12.0->文件->瀏覽實例程序->圖像分割->background_seg.hdev->文件->導出->C++,HALCON/C++,。
2 打開大恒SDK開發(fā)包,位置如上文((C:\Program Files\Daheng Imavision\MER-Series\Samples\VC SDK\src\GxSingleCamMono)視安裝目錄而定)GxSingleCamMono_VS2010。然后把halcon生成的cpp文件代碼截取加入到CGxSingleCamMonoDlg.cpp中,。代碼中加中文注釋的部分是我添加的代碼(A,bitmap轉(zhuǎn)HObject,;B,halcon圖像處理;C,,HObject轉(zhuǎn)bitmap)
- void __stdcall CGxSingleCamMonoDlg::OnFrameCallbackFun(GX_FRAME_CALLBACK_PARAM* pFrame)
- {
- CGxSingleCamMonoDlg *pDlg = (CGxSingleCamMonoDlg*)(pFrame->pUserParam);
- int nImageHeight = (int)pDlg->m_nImageHeight;
- int nImageWidth = (int)pDlg->m_nImageWidth;
- if (pFrame->status == 0)
- {
- memcpy(pDlg->m_pBufferRaw,pFrame->pImgBuf,pFrame->nImgSize);
- // Show image after flipping image data if mono camera has been used.
- for(int i =0;i <nImageHeight;i++)
- {
- memcpy(pDlg->m_pImageBuffer+i*nImageWidth, pDlg->m_pBufferRaw+(nImageHeight-i-1)*nImageWidth,(size_t)nImageWidth);
- }
- ///////////bitmap轉(zhuǎn)HObject///////////
- HObject Image;
- GenImage1(&Image,"byte",(HTuple)nImageWidth,(HTuple)nImageHeight,(long)pDlg->m_pImageBuffer);
- ////////////////////////////////////
- ///////////halcon圖像處理///////////
- HObject ho_EdgeAmplitude,ho_Edges;
- SobelAmp(Image, &ho_EdgeAmplitude, "thin_sum_abs", 3);
- Threshold(ho_EdgeAmplitude, &ho_Edges, 5, 255);
- ////////////////////////////////////
- ///////////HObject轉(zhuǎn)bitmap///////////
- HTuple hv_Pointer;
- HTuple hv_Type="byte";
- HTuple hv_Width=nImageWidth;
- HTuple hv_Height=nImageHeight;
- GetImagePointer1(ho_EdgeAmplitude, &hv_Pointer, &hv_Type, &hv_Width, &hv_Height);
- BYTE *p=(BYTE *)hv_Pointer[0].L();
- int height= (Hlong)hv_Height;
- int width = (Hlong)hv_Width;
- memcpy(pDlg->m_pImageBuffer,p,width*height*sizeof(BYTE));
- ////////////////////////////////////
- pDlg->DrawImg();
- if (pDlg->m_bIsSaveImg)
- {
- pDlg->SaveImage();
- }
- }
- }
四 效果
1 未加代碼實時圖像如下:
2 加代碼實時圖像如下:
注意看,,有白色邊界。
五 參考
1 https://blog.csdn.net/d_a_r_k/article/details/66973582將bitmap轉(zhuǎn)HObject,,原文是彩色圖,,我的是8位灰度圖,因此做了些修改,。
2 http://www./read-2272.html 將HObject轉(zhuǎn)bitmap,。