C#中Emgucv呼叫Halcon

raoqin發表於2020-11-18

Mat與Halcon之間的相互轉化

void Mat2Halcon()
{
    //========================Mat轉化為Halcon
    Mat main8UC3 = new Mat(@"C:\Users\RQ\Desktop\test002.bmp", ImreadModes.Color);
    //Mat main8UC3 = new Mat(@"C:\Users\RQ\Desktop\yueqiu.bmp", ImreadModes.Color);

    HObject aHbj;
    HOperatorSet.GenEmptyObj(out aHbj);

    RqBmpHalConvert.Mat8C3ToHObject(main8UC3, out aHbj);
            
    //================halcon顯示,
    hWindowControl1.HalconWindow.ClearWindow();
    HOperatorSet.DispObj(aHbj, hWindowControl1.HalconWindow);

    //===============halcon儲存
    HTuple aaa;
    aaa = 0;
    HOperatorSet.WriteImage(aHbj, "bmp", aaa, "./hoBinImg001.bmp");
}

void Halcon2Mat()
{
    //=======================halcon開啟影像
    HObject aHbj;
    HOperatorSet.GenEmptyObj(out aHbj);
    HOperatorSet.ReadImage(out aHbj, @"C:\Users\RQ\Desktop\test002.bmp");

    Mat main8UC3 = new Mat(new Size(513, 481), DepthType.Cv8U, 3);

    //轉化
    RqBmpHalConvert.HObjectToMat8C3(aHbj, main8UC3);
    CvInvoke.Imwrite("./hoBinImg001.bmp", main8UC3); ;

}

 

相關文章