diff --git a/Samples/StreamingCam/Program.cs b/Samples/StreamingCam/Program.cs new file mode 100644 index 00000000..fbef7d09 --- /dev/null +++ b/Samples/StreamingCam/Program.cs @@ -0,0 +1,140 @@ +using System; +using System.Diagnostics; +using System.Threading; +using Uml.Robotics.Ros; +using std_msgs = Messages.std_msgs; +using Image = Messages.sensor_msgs.Image; +using System.Drawing; +using System.Drawing.Imaging; +using AForge.Video; +using AForge.Video.DirectShow; +using System.Linq; +using System.IO; +using System.Runtime.InteropServices; + +namespace StreamingCam +{ + class Program + { + static Bitmap video; + static void Main(string[] args) + { + + + FilterInfoCollection VideoCaptureDevices; + VideoCaptureDevice FinalVideo; + + + + Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); + ROS.Init(args, "Talker"); + var spinner = new SingleThreadSpinner(); + NodeHandle node = new NodeHandle(); + + Publisher Talker = node.Advertise("/video", 1); + int count = 0; + + + + VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString); + FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); + FinalVideo.Start(); + + + + while (ROS.OK && !Console.KeyAvailable) + { + Console.WriteLine("publishing message"); + ROS.Info()("Publishing a chatter message: \"Blah blah blah " + ""); + + if (video != null) + { + Image img = new Image(); + img.header = new std_msgs.Header(); + img.header.seq = (uint)count++; + img.header.stamp = new std_msgs.Time(); + img.header.frame_id = "/jkfd"; + img.width = (uint)video.Width; + img.height = (uint)video.Height; + img.encoding = "rgb8"; + img.is_bigendian = 0; + img.step = 640 * 1 * 3; + byte[] tmp = BitmapToByteArray(video); + + //img.data = new byte[img.width * img.height * 3]; + //Array.Copy(tmp, 54, img.data, 0, tmp.Length - 54); + img.data = BitmapToByteArray(video); + //323704 + //921654 + + Talker.Publish(img); + spinner.SpinOnce(); + } + Thread.Sleep(300); + } + ROS.Shutdown(); + + //view v = new view(); + //v.ShowDialog(); + + + + } + + static void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + video = (Bitmap)eventArgs.Frame.Clone(); + //Bitmap v= new Bitmap() + //this.pictureBox1.Image = video; + + + + + + } + + public static byte[] BitmapToByteArray(Bitmap bitmap) + { + + BitmapData bmpdata = null; + + try + { + bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); + int numbytes = bmpdata.Stride * bitmap.Height; + byte[] bytedata = new byte[numbytes]; + IntPtr ptr = bmpdata.Scan0; + + Marshal.Copy(ptr, bytedata, 0, numbytes); + + return bytedata; + } + finally + { + if (bmpdata != null) + bitmap.UnlockBits(bmpdata); + } + + } + + static byte[] ConvertBitMapToByteArray(Bitmap bitmap) + { + + bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); // in ros lo 0:0 si trova al top left + + MemoryStream stream = new MemoryStream(); + bitmap.Save(stream, ImageFormat.Bmp); + return stream.ToArray(); + + + + } + public static byte[] ImageToByte(Bitmap img) + { + ImageConverter converter = new ImageConverter(); + return (byte[])converter.ConvertTo(img, typeof(byte[])); + } + } +} diff --git a/Samples/StreamingCam/StreamingCam.csproj b/Samples/StreamingCam/StreamingCam.csproj new file mode 100644 index 00000000..f53c09bc --- /dev/null +++ b/Samples/StreamingCam/StreamingCam.csproj @@ -0,0 +1,35 @@ + + + + Exe + net462 + + + + + + + + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Imaging.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Video.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Video.DirectShow.dll + + + + + + + Form + + + + diff --git a/Samples/StreamingCam/view.Designer.cs b/Samples/StreamingCam/view.Designer.cs new file mode 100644 index 00000000..a04ab98c --- /dev/null +++ b/Samples/StreamingCam/view.Designer.cs @@ -0,0 +1,77 @@ +namespace StreamingCam +{ + partial class view + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnOK = new System.Windows.Forms.Button(); + + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "view"; + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.btnOK); + + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.view_FormClosing); + + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(361, 156); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(800, 700); + this.pictureBox1.TabIndex = 7; + this.pictureBox1.TabStop = false; + + // + // btnOK + // + this.btnOK.BackColor = System.Drawing.Color.LimeGreen; + this.btnOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnOK.ForeColor = System.Drawing.Color.White; + this.btnOK.Location = new System.Drawing.Point(506, 123); + this.btnOK.Name = "btnOK"; + this.btnOK.Size = new System.Drawing.Size(75, 54); + this.btnOK.TabIndex = 5; + this.btnOK.Text = "OK"; + this.btnOK.UseVisualStyleBackColor = false; + this.btnOK.Click += new System.EventHandler(this.btnOK_Click); + } + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button btnOK; + + #endregion + } +} \ No newline at end of file diff --git a/Samples/StreamingCam/view.cs b/Samples/StreamingCam/view.cs new file mode 100644 index 00000000..27ce2433 --- /dev/null +++ b/Samples/StreamingCam/view.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using AForge.Video; +using AForge.Video.DirectShow; + +namespace StreamingCam +{ + public partial class view: Form + { + private FilterInfoCollection VideoCaptureDevices; + private VideoCaptureDevice FinalVideo; + + public Bitmap video; + public view() + { + InitializeComponent(); + + VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString); + FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); + + + + + + + } + + public void btnOK_Click(object sender, EventArgs e) + { + FinalVideo.Start(); + } + private void view_FormClosing(object sender, FormClosingEventArgs e) + { + FinalVideo.Stop(); + } + void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + video = (Bitmap)eventArgs.Frame.Clone(); + + this.pictureBox1.Image = video; + + } + } +} diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index 8250aa26..3e70fe46 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.Loader; +#if NETCORE +using System.Runtime.Loader; +#endif namespace Uml.Robotics.Ros { public class TypeRegistryBase @@ -48,18 +50,17 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs #if NETCORE var context = DependencyContext.Load(Assembly.GetEntryAssembly()); var loadContext = AssemblyLoadContext.Default; - + return context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(loadContext.LoadFromAssemblyName); #else - var context = DependencyContext.Load(Assembly.GetEntryAssembly()); + + Assembly[] a = AppDomain.CurrentDomain.GetAssemblies(); - return context.RuntimeLibraries - .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) - .SelectMany(x => x.GetDefaultAssemblyNames(context)) - .Select(Assembly.Load); + return a.Where(x=> x.GetReferencedAssemblies().Any(y => referenceAssemblies.Contains(y.Name))); + #endif } } diff --git a/Uml.Robotics.Ros.sln b/Uml.Robotics.Ros.sln index 28f4746e..4823b78c 100644 --- a/Uml.Robotics.Ros.sln +++ b/Uml.Robotics.Ros.sln @@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ActionServerSample", "Sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PubSubTestbed", "Tests\PubSubTestbed\PubSubTestbed.csproj", "{1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreamingCam", "Samples\StreamingCam\StreamingCam.csproj", "{BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -115,6 +117,10 @@ Global {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Release|Any CPU.Build.0 = Release|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -131,6 +137,7 @@ Global {4F0E93D5-6CC7-4971-BB91-A5139CF4B05E} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} {3041CF5C-222C-412E-8EE6-289C1DE0E567} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0} = {EEE8759B-47AD-455B-8F32-0A36EAE2512B} + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {23E67514-C5C2-464B-8371-A9A618DE03BA} diff --git a/Uml.Robotics.Ros/RemappingHelper.cs b/Uml.Robotics.Ros/RemappingHelper.cs index 63d82779..f4b9d566 100644 --- a/Uml.Robotics.Ros/RemappingHelper.cs +++ b/Uml.Robotics.Ros/RemappingHelper.cs @@ -42,13 +42,34 @@ public static bool GetRemappings(ref string[] args, out IDictionaryhttps://raw.githubusercontent.com/Xamla/ROS.NET/master/Icon.png ROS.NET is a CLR implementation of the ROS communication infratructure (topics, services, actions) that can communicate with standard ROS 1 nodes. - + NETCORE @@ -32,6 +32,7 @@ + diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index 40be4be4..52133f41 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -387,7 +387,7 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly); srvRegistry.ParseAssemblyAndRegisterRosServices(assembly); } - + initOptions = options; _ok = true; diff --git a/common_msgs/audio_common_msgs/AudioData.msg b/common_msgs/audio_common_msgs/AudioData.msg new file mode 100644 index 00000000..c5fd6c87 --- /dev/null +++ b/common_msgs/audio_common_msgs/AudioData.msg @@ -0,0 +1 @@ +float32[] data \ No newline at end of file