// -- following by relative HObject converter codes /// <summary> /// Convert Bitmap to HObject which Halcon dot net data type /// </summary> /// <param name="input"></param> /// <returns></returns> public static HalconDotNet.HObject Bitmap2Hobject(System.Drawing.Bitmap input) { if (input == null) { return(new HalconDotNet.HObject()); } try { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, input.Width, input.Height); HalconDotNet.HObject himg = new HalconDotNet.HObject(); if (input.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { System.Drawing.Imaging.BitmapData srcBmpData = input.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); HalconDotNet.HOperatorSet.GenImage1(out himg, "byte", input.Width, input.Height, srcBmpData.Scan0); input.UnlockBits(srcBmpData); } else if (input.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb) { System.Drawing.Imaging.BitmapData srcBmpData = input.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); HalconDotNet.HOperatorSet.GenImageInterleaved(out himg, srcBmpData.Scan0, "bgr", input.Width, input.Height, -1, "byte", 0, 0, 0, 0, -1, 0); input.UnlockBits(srcBmpData); } else if (input.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { System.Drawing.Imaging.BitmapData srcBmpData = input.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, input.PixelFormat); HalconDotNet.HOperatorSet.GenImageInterleaved(out himg, srcBmpData.Scan0, "bgrx", input.Width, input.Height, -1, "byte", input.Width, input.Height, 0, 0, -1, 0); input.UnlockBits(srcBmpData); } else // default: trans to color image { System.Drawing.Imaging.BitmapData srcBmpData = null; System.Drawing.Bitmap MetaBmp = new System.Drawing.Bitmap(input.Width, input.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(MetaBmp); g.DrawImage(input, rect); g.Dispose(); srcBmpData = MetaBmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); HalconDotNet.HOperatorSet.GenImageInterleaved(out himg, srcBmpData.Scan0, "bgr", input.Width, input.Height, -1, "byte", 0, 0, 0, 0, -1, 0); MetaBmp.UnlockBits(srcBmpData); } return(himg); } catch (HalconDotNet.HalconException ex) { Console.WriteLine("In ImageTypeConverter.Bitmap2Hobject: " + ex.Message); return(null); } catch (System.Exception ex) { Console.WriteLine("In ImageTypeConverter.Bitmap2Hobject: " + ex.Message); return(null); } }
public override void AddIconicVar(HalconDotNet.HObject hobj) { lock (_SyntRoot) { if (hobj is HalconDotNet.HImage) { ClearAndDisposeEntries(); } base.AddIconicVar(hobj); hobjectArray.Add(hobj); } }
//取流回调函数 private void ImageCallBack(object sender, TIS.Imaging.ICImagingControl.ImageAvailableEventArgs e) { try { //Trace.WriteLine(string.Format("触发回调 = {0}", DateTime.Now.ToString("HH:mm:ss:fff"))); TIS.Imaging.ImageBuffer CurrentBuffer = null; CurrentBuffer = m_ImageControl.ImageBuffers[e.bufferIndex]; bmp_image1 = CurrentBuffer.Bitmap; ho_image1 = Bitmap2HObject(bmp_image1); // bmp_image1 // ReturnImgEvent.Set(); //Trace.WriteLine(string.Format("获取图像 = {0}",DateTime.Now.ToString("HH:mm:ss:fff"))); if (bmp_image1 != null) { bool benableNew = false; if (threadProcess1 == null) { benableNew = true; } else if (!threadProcess1.IsAlive) { benableNew = true; } if (benableNew) { threadProcess1 = new System.Threading.Thread(processCamera01); threadProcess1.Start(); } } } catch (Exception ex) { Trace.WriteLine(ex.Message + "回调失败!!!"); } }
/// <summary> /// Bitmap转HObject /// </summary> /// <param name="bmp">8位Bitmap</param> /// <param name="hobj"></param> /// <returns></returns> private bool BitmapBpp8ToHObject(System.Drawing.Bitmap bmp, out HalconDotNet.HObject hobj) { bool rt = false; HalconDotNet.HOperatorSet.GenEmptyObj(out hobj); try { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData srcBmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); HalconDotNet.HOperatorSet.GenImage1(out hobj, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0); bmp.UnlockBits(srcBmpData); rt = true; } catch { } finally { } return(rt); }
static void dhDosome(Bitmap bmpImage, HalconDotNet.HObject hoIntsnsity) { //System.Windows.Forms.MessageBox.Show("in class jai say :hello!"); return; }
private static void SetColorsInObjectModel3D(HalconDotNet.HTuple objectModel3D, HalconDotNet.HObject RGB, HalconDotNet.HObject zReduced) { var domain = new HalconDotNet.HObject(); var rows = new HalconDotNet.HTuple(); var cols = new HalconDotNet.HTuple(); HalconDotNet.HOperatorSet.GetDomain(zReduced, out domain); HalconDotNet.HOperatorSet.GetRegionPoints(domain, out rows, out cols); var objectRed = new HalconDotNet.HObject(); var objectGreen = new HalconDotNet.HObject(); var objectBlue = new HalconDotNet.HObject(); HalconDotNet.HOperatorSet.AccessChannel(RGB, out objectRed, 1); HalconDotNet.HOperatorSet.AccessChannel(RGB, out objectGreen, 1); HalconDotNet.HOperatorSet.AccessChannel(RGB, out objectBlue, 1); var tupleRed = new HalconDotNet.HTuple(); var tupleGreen = new HalconDotNet.HTuple(); var tupleBlue = new HalconDotNet.HTuple(); HalconDotNet.HOperatorSet.GetGrayval(objectRed, rows, cols, out tupleRed); HalconDotNet.HOperatorSet.GetGrayval(objectGreen, rows, cols, out tupleGreen); HalconDotNet.HOperatorSet.GetGrayval(objectBlue, rows, cols, out tupleBlue); HalconDotNet.HOperatorSet.SetObjectModel3dAttribMod(objectModel3D, "red", "points", tupleRed); HalconDotNet.HOperatorSet.SetObjectModel3dAttribMod(objectModel3D, "green", "points", tupleGreen); HalconDotNet.HOperatorSet.SetObjectModel3dAttribMod(objectModel3D, "blue", "points", tupleBlue); }
static void Main() { try { Console.WriteLine("Connecting to camera"); var zividDevice = GetFirstAvailableZividDevice(); var framegrabber = new HalconDotNet.HTuple(); HalconDotNet.HOperatorSet.OpenFramegrabber("GenICamTL", 1, 1, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", zividDevice, 0, 0, out framegrabber); Console.WriteLine("Configuring 3D-settings"); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "create_objectmodel3d", "enable"); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "add_objectmodel3d_overlay_attrib", "enable"); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "AcquisitionMode", "SingleFrame"); Console.WriteLine("Configuring camera settings"); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "Aperture", 5.66); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "ExposureTime", 8333); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "Gain", 1); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "ProcessingFiltersOutlierRemovalEnabled", 1); HalconDotNet.HOperatorSet.SetFramegrabberParam(framegrabber, "ProcessingFiltersOutlierRemovalThreshold", 5); Console.WriteLine("Capturing frame"); var frame = new HalconDotNet.HObject(); var region = new HalconDotNet.HObject(); var contours = new HalconDotNet.HObject(); var data = new HalconDotNet.HTuple(); HalconDotNet.HOperatorSet.GrabData(out frame, out region, out contours, framegrabber, out data); var x = frame.SelectObj(1); var y = frame.SelectObj(2); var z = frame.SelectObj(3); var snr = frame.SelectObj(4); var rgb = frame.SelectObj(5); Console.WriteLine("Removing invalid 3D points (zeroes)"); var reducedRegion = new HalconDotNet.HObject(); var zReduced = new HalconDotNet.HObject(); HalconDotNet.HOperatorSet.Threshold(z, out reducedRegion, 0.0001, 10000); HalconDotNet.HOperatorSet.ReduceDomain(z, reducedRegion, out zReduced); Console.WriteLine("Constructing ObjetModel3D based on XYZ data"); var objectModel3D = new HalconDotNet.HTuple(); HalconDotNet.HOperatorSet.XyzToObjectModel3d(x, y, zReduced, out objectModel3D); Console.WriteLine("Adding RGB to ObjectModel3D"); SetColorsInObjectModel3D(objectModel3D, rgb, zReduced); string pointCloudFile = "Zivid3D.ply"; Console.WriteLine("Saving point cloud to file: " + pointCloudFile); SaveHalconPointCloud(objectModel3D, pointCloudFile); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Environment.ExitCode = 1; } }
private bool BitmapToHObject(System.Drawing.Bitmap bmp, out HalconDotNet.HObject hobj) { bool rt = false; HalconDotNet.HOperatorSet.GenEmptyObj(out hobj); try { switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: break; case System.Drawing.Imaging.PixelFormat.Format16bppGrayScale: break; case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: break; case System.Drawing.Imaging.PixelFormat.Format16bppRgb565: break; case System.Drawing.Imaging.PixelFormat.Format1bppIndexed: break; case System.Drawing.Imaging.PixelFormat.Format24bppRgb: if (BitmapBpp24ToHObject(bmp, out hobj)) { rt = true; } break; case System.Drawing.Imaging.PixelFormat.Format32bppArgb: break; case System.Drawing.Imaging.PixelFormat.Format32bppPArgb: break; case System.Drawing.Imaging.PixelFormat.Format32bppRgb: break; case System.Drawing.Imaging.PixelFormat.Format48bppRgb: break; case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: break; case System.Drawing.Imaging.PixelFormat.Format64bppArgb: break; case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: break; case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: if (BitmapBpp8ToHObject(bmp, out hobj)) { rt = true; } break; } } catch { } finally { } return(rt); }
/// <summary>Sets the value of a global iconic variable</summary> public void SetGlobalIconicVarObject(string name, HObject iconic) { HDevEngine.HCkE(EngineAPI.SetGlobalIconicVarObject(this.engine, name, iconic.Key)); GC.KeepAlive((object)iconic); GC.KeepAlive((object)this); }
/// <summary> /// Create empty vector of specified dimension. In case of dimension /// 0 a leaf vector for an empty object is created /// </summary> public HObjectVector(int dimension) : base(dimension) { this.mObject = dimension <= 0 ? HObjectVector.GenEmptyObj() : (HObject)null; }
public static int LoadNew(IntPtr proc, int parIndex, int err, out HObject obj) { obj = new HObject(HObjectBase.UNDEF); return(obj.Load(proc, parIndex, err)); }
public HObject(HObject obj) : base((HObjectBase)obj) { this.AssertObjectClass(); GC.KeepAlive((object)this); }
public virtual void DevDisplay(HObject obj) { HOperatorSet.DispObj(obj, this.activeID); }
private void _baslerCamera_eventProcessImage(HalconDotNet.HObject hImage) { ImageHelper.GenertateRGBBitmap(hImage,out Bitmap bitmap); ShowImage = ImageHelper.BitmapToBitmapImage(bitmap); }