/// <summary> /// Write the perceived value on the yarp port. /// </summary> public override void WritePerceivedValue() { Bottle b = portPerceived.prepare(); b.clear(); b.addString(vectorToString(PerceivedValue)); portPerceived.write(); }
public static void Main(string[] args) { var serviceProvider = BuildDIContainer(); // Initialize Yarp Network.init(); using (var videoSource = serviceProvider.GetRequiredService <IVideoSource>()) using (var audioSource = serviceProvider.GetRequiredService <IAudioSource>()) using (var videoPort = new BufferedPortImageRgb()) using (var audioPort = new BufferedPortBottle()) using (var videoFrameRgbBuffer = new Image <Rgb, byte>(640, 480)) { // Stream the video frames to a yarp port videoPort.open("/camera"); videoSource.FrameReady += (_, frame) => { using (var msg = videoPort.prepare()) { // Convert the incoming image which is BGR to RGB var bits = frame.Image.LockBits(new Rectangle(0, 0, frame.Image.Width, frame.Image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); using (var videoFrameBgr = new Image <Bgr, byte>(frame.Image.Width, frame.Image.Height, bits.Stride, bits.Scan0)) CvInvoke.CvtColor(videoFrameBgr, videoFrameRgbBuffer, ColorConversion.Bgr2Rgb); frame.Image.UnlockBits(bits); // Send the RGB image over yarp var handle = GCHandle.Alloc(videoFrameRgbBuffer.Bytes, GCHandleType.Pinned); msg.setExternal(new SWIGTYPE_p_void(handle.AddrOfPinnedObject(), true), (uint)frame.Image.Width, (uint)frame.Image.Height); videoPort.write(); videoPort.waitForWrite(); handle.Free(); } }; // Stream the audio samples to a yarp port audioPort.open("/microphone"); audioSource.SampleReady += (_, sample) => { using (var bottle = audioPort.prepare()) { var handle = GCHandle.Alloc(sample.Data, GCHandleType.Pinned); bottle.clear(); bottle.add(Value.makeBlob(new SWIGTYPE_p_void(handle.AddrOfPinnedObject(), true), sample.Data.Length)); audioPort.write(); audioPort.waitForWrite(); handle.Free(); } }; // Run the sample application RunDemoApplication(videoSource, audioSource); } // Explicitely shutdown NLog and Yarp Network.fini(); NLog.LogManager.Shutdown(); }
/// <summary> /// Write the perceived value on the yarp port. /// </summary> public override void WritePerceivedValue() { Bottle b = portPerceived.prepare(); b.clear(); for (int i = 0; i < size; i++) { b.addDouble((PerceivedValue[i] * (maxBounds[i] - minBounds[i])) + minBounds[i]); } portPerceived.write(); }
static void Main(string[] args) { Network.init(); BufferedPortBottle p = new BufferedPortBottle(); p.open("/csharp"); int top = 100; for (int i=1; i<top; i++) { Bottle bottle = p.prepare(); bottle.clear(); bottle.addString("count"); bottle.addInt(i); bottle.addString("of"); bottle.addInt(top); Console.WriteLine("Sending " + bottle.toString()); p.write(); Time.delay(0.5); } p.close(); Network.fini(); }
static void Main(string[] args) { Network.init(); BufferedPortBottle p = new BufferedPortBottle(); p.open("/csharp"); int top = 100; for (int i = 1; i < top; i++) { Bottle bottle = p.prepare(); bottle.clear(); bottle.addString("count"); bottle.addInt32(i); bottle.addString("of"); bottle.addInt32(top); Console.WriteLine("Sending " + bottle.toString()); p.write(); Time.delay(0.5); } p.close(); Network.fini(); }