public static void Main(string[] args) { O3D o3d; String localIpAdress = "192.168.0.69"; if (0 == O3D.getLocalIPAddress(out localIpAdress)) { o3d = new O3D("192.168.1.26", localIpAdress,8080); } else { return; } string fwVersion = "null"; string deviceType = "null"; int ret = -1; ret = o3d.disconnect(); ret = o3d.connect(out fwVersion, out deviceType); if( 0 == ret ) { ret = o3d.startLiveImageServer(); } if(0 == ret ) { O3D.ImagerData imager_settings = new O3D.ImagerData(); ret = o3d.getFrontendSettings(ref imager_settings); imager_settings.delayTime = 100; ret = o3d.setFrontendSettings(imager_settings); } if( 0 == ret ) { O3DImage[] images = new O3DImage[2]; images[0] = new O3DImage(O3DImage.ImageType.AmplitudeImage); images[1] = new O3DImage(O3DImage.ImageType.DistanceImage); ret = o3d.getImageData(ref images,true ); Bitmap bmp = images[0].toBitmap(O3DImage.BitmapType.GrayScale); bmp.Save("mypic_intensity.png",System.Drawing.Imaging.ImageFormat.Png); bmp = images[1].toBitmap(O3DImage.BitmapType.GrayScale); bmp.Save("mypic_distance.png",System.Drawing.Imaging.ImageFormat.Png); } ret = o3d.stopLiveImageServer(); ret = o3d.disconnect(); }
/// <summary> /// Retrieve images from the camera you have to provide a arry with /// image references where which define the image type /// </summary> /// <param name="images"> /// A <see cref="O3DImage[]"/> /// the array which containes the images to retrieve. /// </param> /// <param name="synced"> /// A <see cref="System.Boolean"/> /// This parameter defines if the transfer is synchron which means upper case /// letters or asynchronous lowercase letters please refer to the "o3d2xx Programmers Guide" /// </param> /// <returns> /// A <see cref="System.Int32"/> /// Return 0 on success otherwise an error code is returned /// </returns> public int getImageData(ref O3DImage[] images, bool synced) { int ret = 0; try { if (sock.Connected) { string command = ""; for (int idx = 0; idx < images.Length; idx++ ) { command += commands[images[idx].imageType]; } if (synced) { string start = command.Substring(0, 1); string rest = command.Remove(0,1); command = start.ToUpper() + rest; } int size = (O3DImage.metaSize + (O3DImage.height * O3DImage.width)) * 4; Byte[] chunk = new Byte[size]; float[] floatChunk = new float[Convert.ToInt32(chunk.Length / 4)]; Byte[] toSend = Encoding.ASCII.GetBytes(command); sock.Send(toSend, toSend.Length, SocketFlags.None); for (int idx = 0; idx < images.Length; idx++) { int received = 0; do { received += sock.Receive(chunk, received, size - received, SocketFlags.None); } while (received < size); for (int i = 0; i < floatChunk.Length; i++) { if (BitConverter.IsLittleEndian) { Array.Reverse(chunk, i * 4, 4); } floatChunk[i] = BitConverter.ToSingle(chunk, i * 4); } System.Console.WriteLine("{0}", floatChunk[(int)O3D.ImageMetaDataIndex.UnambiguousRange]); Array.Copy(floatChunk, 0, images[idx].metaData, 0, O3DImage.metaSize); for (int y = 0; y < O3DImage.height; y++) { for (int x = 0; x < O3DImage.width; x++) { images[idx].imageData[y, x] = floatChunk[O3DImage.metaSize + (y * O3DImage.width) + x]; images[idx].min = Math.Min(images[idx].imageData[y, x], images[idx].min); images[idx].max = Math.Max(images[idx].imageData[y, x], images[idx].max); } } } } } catch (Exception e) { Console.WriteLine(e.Message); } return ret; }