c++代码如下
- extern "C" __declspec(dllexport)
- int ProcessImage3(void* pixel,int width,int height,double* area,double* row,double* col)
- {
- try
- {
- HTuple hvPtr, hvWidth, hvHeight;
- hvPtr = (Hlong)pixel;
- hvWidth = width;
- hvHeight = height;
- // 用 GenImage1 重新生成 HObject
- HObject hoImg;
- GenImage1(&hoImg, "byte", hvWidth, hvHeight, hvPtr);
- HObject region, connected, selected;
- HTuple hv_Area, hv_Row, hv_Column;
- Threshold(hoImg, ®ion, 128, 255);
- Connection(region, &connected);
- SelectShape(connected, &selected, "area", "and", 5000, 99999);
- AreaCenter(selected, &hv_Area, &hv_Row, &hv_Column);
- *area = hv_Area.D();
- *row = hv_Row.D();
- *col = hv_Column.D();
- return 0;
- }
- catch (HException& e)
- {
- return 0;
- }
- }
复制代码
c#调用代码
- [DllImport("Dll0827.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int ProcessImage3(IntPtr pixel,int width,int height,out double area,out double row,out double col);
- private void button1_Click(object sender, EventArgs e)
- {
- HOperatorSet.ReadImage(out HObject image, @"C:\3.jpg");
- HOperatorSet.GetImagePointer1(image, out HTuple pointer, out HTuple type, out HTuple width, out HTuple height);
- int ret = ProcessImage3(pointer, width, height, out double area, out double row, out double col);
- }
复制代码 |