How can I capture a frame from a video-4-linux device (e.g.: /dev/video0) using Mono and C#? OS is Angstrom Linux running on BeagleBoard.
I have done v4l2 capture using C. This is probably the only language I would chose to do it in as well. There are a lot of low level calls you need to make into the driver. You need to map kernel memory into your app and copy buffers. You also have to set a ton of configuration for the device. If you need to I would consider writing a C library and using Platform Invoke. Another alternative is to write two programs and send the data over to your C# app via some sort of IPC.
You can use Emgu CV for this, it specifically advertises that it can be compiled using Mono.
Main Site: http://www.emgu.com/wiki/index.php/Main_Page
Compiling in Mono: http://www.emgu.com/wiki/index.php/Compiling_with_Monodevelop
Sample Code for Capturing Webcam Video: http://www.emgu.com/wiki/index.php/Camera_Capture_in_7_lines_of_code
I am not familiar with Mono or C# on linux, but you may have to write an interface module that exposes the diver API, or a reasonable abstraction. I think you then might be able to import the module in the C# code. It looks like Mono does support the DLLImport.
(http://www.mono-project.com/Interop_with_Native_Libraries)
Related
In my application, I have provision to run Python scripts through IronPython. In one of the requirement, the data from my C# application should be displayed in 3D using Visualization Toolkit. When I try to use VTK in a script and execute it, I get "ImportError: No module named vtk" error. I have searched for file named vtkCommonPython.pyd but cannot find it on my computer. Should Python be installed even after installing IronPython? What is the correct way to use VTK from IronPython?
In most cases, IronPython does not work with native/CPython modules like what vtkCommonPython.pyd seems to be. You will probably want to look at .NET bindings for VTK in order to use it from your IronPython scripts.
ActiViz.NET might be what you should be using. Wiki/Documentation, Download
Other modules containing only pure python should typically work fine. It's 'just' the native extensions that do not work as there is no easy (and built-in) way to make native code callable from .NET/IronPython using the same conventions as in CPython.
For additional info see the FAQ ('Compatibility') and the issue tracker.
You might also want to keep an eye on the recent effort to revive and port ironclad to IronPython 2.7. This project aims to provide the marshalling layer required to invoke CPython modules.
Due to the lack of a managed .NET api for playing MP3 files, I'm using the PlaySound(byte[]) as P/Invoke and it is now playing the MP3 file successfully.
I can't use any third party libraries due to license restrictions.
Now, I want to port the application to Linux and OS X using Mono but I'm unsure which P/Invokes should be used on those platforms.
An answer to a similar question said
You can just open("/dev/dsp") and write to it. That's as "native syscall" as you can get, I believe.
but I don't know how to do that in C#
Thanks.
You'll need to use the SDL_Mixer library with the SMPEG library for mp3 support. The code should be reusable across all OS's.
Has anybody used Mapnik for rendering Maps from .net c# environment? I would like to use it to render maps in a desktop application developed under .net4. I found it the best open source map renderer tool, much more better, than the well known sharpmap, dotspatial (...). The 'only' problem is that it was written in C++ and Python and does not have a trivial way to use it from C#.
Do you know any .net Mapnik wrappers? Do you know any sample code?
I've just published my attempts in C# bindings.
They are available at: http://sourceforge.net/projects/mapniknet/
Some good new about Mapnik-.Net integration:
"Another thing that will help Windows developers is a way to use Mapnik from .Net languages. Although a full .Net wrapper is too much work besides all the other issues, hopefully I can make a meaningful start and open the door for .Net developers to leverage Mapnik in their applications."
Source: Mapnik homepage http://mapnik.org/news/2011/jun/09/gsoc_2011_windows_build_system_introduction/
NET-Mapnik
You might want to give this a try. Its pretty recent and has a simple example with options to create vector tiles.
https://github.com/kernelsanders/NET-Mapnik
So, finally I hacked it. Not a nice solution, but it works at least. In nutshell it operates in the following way:
developed a python script, which takes parameters as command line arguments. (using python api of mapnik)
call this python script by shell fom c# code (Process)
after map image has been generated, I show it in SharpMap as a background layer
In case of any map refresh (zoom, pan) I regenerate 'mapnik map layer'. I have also some kind of cache, in which I can store generated maps, so I can make tricks by using earlier generated map images or pre-generate them (e.g. generate maps for the next zoom level when user uses zoom tool). I also use some asynchron calls to do this, so I can create 1-3 map images paralelly.
The weak part of this solution is the communication between python and c# modules. I could not find better than command line arguments + shell.
My solution works, mapnik is fast, can genarate my maps less than a sec.
If you have any advice on .net - python communication (NO ironpython, it is not suitable for manik api), pls write it here. Thx.
Do you know about TAO Project?
It is a .Net project that takes unmanaged opengle library to .Net Managed Form by calling DllIMport() in C#.
You must do it for Mapnik, simaliar to TAOFramework.net
Is out there any Pure C# Silverlight video encoding lib?
By video I mean not only pictures compressor but also audio compressor...
So to say I'm looking for some kind of lib not only for compressing but also for sinchronisation etc... so to say I give it a web cam it gives me a conteiner!)
You're certainly not going to want to do this in safe code, unless you've got a lot of buffer memory, as the encoder would run glacially slowly.
One option is to run with elevated permissions, and then you can interact with external COM packages - see http://forums.silverlight.net/forums/p/156112/350144.aspx for some useful links
Here's a link from stackoverflow on the general issue that says pretty much the same thing - Using Native dlls in C# Com wrapper and Use dll in silverlight
If you can create a C# wrapper around calls to any native encoding DLL of your choice, then you can put the wrapper assembly in the GAC and you should be good to go - this would of course mean you need an additional install step to get this assembly into the gac, which is outside the 'normal' silverlight experience
To make this separation easier to implement and use, we introduced what we call the simple sandboxing APIs in the .NET Framework 2.0, which create each application domain with a given permission set for its sandbox and a list of fully trusted assemblies that are not in the Global Assembly Cache (GAC), as all assemblies in the GAC are already fully trusted.
taken from http://msdn.microsoft.com/en-us/magazine/cc765416.aspx - dated, but I believe still accurate
As of February 15, 2010 -- it appears that there is not a built-in way to do this in Silverlight.
Here is a thread that discusses this issue.
Rene Schulte has an example, EdgeCam Shots - Saving Silverlight 4 Webcam Snapshots to JPEG that saves the Webcam stream as sequential JPEG images.
I have an .INF for a virtual printer that I need to install from a .NET Application. I have done this before using batch scripts, but I am looking for a snippet of code to do this in the .NET Framework.
There's nothing particular about the printer .INF, so any code that installs a printer from an INF in C# or VB.NET will work.
I believe this is possible via interop to native win32 APIs, but I've found its much, much easier just to use a System.Diagnostics.Process() to call into printui.dll via:
rundll32.exe printui.dll,PrintUIEntry /?
Perhaps you're already using that in the mentioned batch script, but if not the parameters are documented here: PrintUI.DLL User's Guide and Reference
Just be sure to test it against all operation systems you need to support. Some options either do not exist in all Windows releases or have been renamed (although I think they're the more esoteric options - installing an .INF will likely work across the board).
You are going to want to look at the WMI objects available. These give you a finer control of the local machine settings. Take a look at the WMI code creator from Microsoft, I believe this will generate some example code you can leverage to solve your problem.
Administering Printer Settings in C# for Flexible Printing
see this article, it uses an MS Platform SDK DLL called PRNADMIN to manage printers, printer-drivers, printer-ports, ...etc.
I personally use it in a commercial project to install a printer driver and change the printer port to local port to intercept the Postscript. and it works like a Charm.
Alternatively you can use some pre-installed vbscripts that come with windows in C:\Windows\system32\Printing_Admin_Scripts and here is a an articles for them:
http://technet.microsoft.com/en-us/library/cc771846.aspx
This is not the ideal solution, but if nobody else answers, you can create a temp batch file and invoke that through C#/VB.NET.
Someone else will probably know a more natural way to do this.
You will need to wrap the setup APIs using PINVOKE or a native COM object.