Capturing image from WebCam in .Net Core 2.0 - c#

I'm developing an app in .Net Core 2.0 to run on a Raspberry Pi, which is running Win 10 IoT. The Pi has a USB WebCam attached and I'm looking to capture a still image from the camera. Unfortunately this is proving somewhat troublesome, to say the least.
Firstly I had a good search through the .Net Core 2.0 libraries to see if there's anything that will provide this functionality, but have not had any luck.
My second line of enquiry was NuGet, to see if any third-party libraries might do the job. EmguCV looked promising for a while, but they do not seem to support .Net Core just yet.
Finally I googled for anything that might do the job and came across the MediaCapture class in Windows.Media.Capture for UWP, but I've had no success referencing this from my .Net Core console app. It seems like you can reference .Net Core assemblies from UWP solutions, but I've not found a way to do it the other way around.
Bearing in mind that I'd prefer to keep my project in .Net Core 2.0, rather than re-writing for UWP, I'm looking for any means of capturing a still image from the WebCam. Any pointers will be gratefully received, as this is proving to be surprisingly frustrating.

For capturing images and other image processing activities, probably you can try OpenCvSharp.
It has support for .NET Core.
https://github.com/shimat/opencvsharp
NuGet Packages are available (look for more details in the above link on the correct one(s) to choose).
Here is an example for capturing video:
https://github.com/shimat/opencvsharp_samples/tree/master/CameraOpenCV
if you pass 0 (zero) as input to VideoCapture, it should open the default camera.
Something like this (not tried):
VideoCapture capture = new VideoCapture(0); //assumption based on how actual openCV works.

You can reference universal windows app's core libraries (Windows.Media.winmd, Windows.Security.winmd, etc...) on any dot net application (core, framework, standard). I have done it. However, the 'await' will be all messed up so you will have to deal with work around to use await and async (i.e. manually waiting for the task).
Windows.Media has the Microsoft's api to talk to the camera.
I am not sure if universal apps work on a Raspberry Pi thou.

Since you are using Win 10 IoT on Raspberry try using "Intelligent Kiosk" sample program available in Git by Microsoft. It gives a UWP app (Source Code) which has a good camera control with more options to customize. This is C#. If you want VB version you can ping me.
The IK code does many more things using Azure Cognitive services which may be of interest to you.

Related

WPF, UWP and Hardware

I just got back from Microsoft Build 2018 where they announced .NET Core 3 support for WPF applications. This is great because I can finally start using some of those cool fluent design things that are available for UWP. The only problem is, it's not getting released until next year.
I started looking into converting my app to a UWP app (because I'm impatient) but I'm running into some challenges. Mainly hardware. Talking with a few guys at Build, they made it seem like it was possible to write UWP apps that connect to low-level Win32 drivers for communicating with hardware (HID printers, card readers, bar code scanners, etc). I'm not having any luck finding information about this. Just to be clear, this is not an app I want to release to the Windows Store. This is a kiosk app that runs on our own hardware.
How does one access Win32 APIs for hardware integration in UWP?
Your best bet is likely to use P/Invoke, which is technology designed to allow .NET code to call unmanaged code. Assuming that your hardware is accessed through Win32 APIs in a DLL, this may be your best option.
The pinvoke.net Web site provides specific examples of the .NET code needed to call a specific Win32 API. Perhaps those examples can help you get started.
UWP app written in C++/CX has access to the Win32 and COM APIs that are part of the Universal Windows Platform (UWP).
The APIs in Win32 and COM APIs for UWP apps is only for C++, you can not use the C# to access it directly. Please see Visual C++ Language Reference (C++/CX) to get more details about C++/CX.
But, you can create a Windows Runtime component in C++/CX, then call it from C#, you can see the Walkthrough here:
https://learn.microsoft.com/en-us/windows/uwp/winrt-components/walkthrough-creating-a-basic-windows-runtime-component-in-cpp-and-calling-it-from-javascript-or-csharp

Xamarin.forms .NetStandard How to play a video?

I currently developing a Xamarin.form app that use .NetStandard as code sharing technique.
On a certain point in the app, the app must show a video from a url. A video could take up to 5 minutes.
I currently can't find a way how I can play a video in my Xamarin.Forms app.
Most of the examples on the web using PCL with .NET Framework.
I tried This plug in, but it isn't fully supported for .NetStandard, since it is written for .Net Framework:
https://github.com/martijn00/XamarinMediaManager
I already managed to play a video on Android and iOs following this tutorial:
https://blog.xamarin.com/delivering-rich-media-experiences-xamarin-forms-video-player/
However, it can only play videos up to 15 seconds for free and in UWP, it seems to be a bit broken.
I simply cannot figure out how I can play a video up to 5 minutes using .Net Standard.
Can someone please explain step by step how I can show a video in a Xamarin.Form app using .NetStandard as code sharing technique?
Or If anyone could explain in detail how to make my own video control, that works on each platform, that would be fantastic.
Your help is really much appreciated.
You may want to have a look at LibVLCSharp which provides a netstandard target as well as well native controls for each platforms.
Disclaimer: I am the maintainer.
You can find a full tutorial how implementing a video(local or web) in your app
manually at Xamarin documentation
either there is a sample

C# Cross platform GUI for desktop and mobile

I have a hobby project that I wrote in C#. Library is for geomatics calculations, it has over 4000 lines of code and I have spent years developing it. Recently I completed GUI using Windows Forms and shared it for free. I got good feedback and now I want to make it cross platform.
Problem is that after days of searching the Internet I found nothing. All links are outdated. I would prefer something like JavaFX, where I could possibly create one GUI for desktop and mobile without much hassle with compiling.
GTK# is stuck (no mobile and no integration for newer versions with Xamarin studio)
QtSharp is in Alpha stage
Eto.Forms for mobile is still under development
Are there any free working alternatives with good tutorials/documentation in late 2016? Or do I have to rewrite my libraries in Java and create GUI in JavaFX?
At the moment there isn't a .Net framework that support all platform. The solution that covers most platform is Xamarin (right now support Android, iOS and MS Universal App). As this post suggest probably in the near future there will a Xamarin version also for Linux systems.
But there is an alternative: duocode. Basically it's a tool that convert c# code into javascript and once is transformed you can use the javascript code to implement a mobile interface using a cross platform framework like cordova. You will have two different application but with the same code base.

Capture camera using DirectShow

I'm developping a SmartDevice application (Pocket PC 2003 template) in C# for a device with Windows Mobile 6.1. I need to use the camera of this device (photos, video); to do this work i tried using the CameraCaptureDialog class but it does not work for Pocket PC applications.
So, I documented on the internet and found that I probably refer to DirectShow API, but the problem is that I do not know where to start because I can't found a working/correct example.
My questions:
Is this the right way? Are there alternatives?
Where I can find a very good example that shows how to do this work?
You may try directshowbetcf: http://alexmogurenko.com/blog/directshownetcf/ if you really want to go with DirectShow and NetCF.
There's plenty of examples of directshow on the web. There is a site dedicated to converting the API over to C# which makes it a lot easier, maybe this was it http://directshownet.sourceforge.net/about.html. I struggled with DirectShow until I read the book "programming directshow" from microsoft press. About a third of that way through that book it all seemed incredibly easy and I was able to complete what I wanted. In the end it's a lot like referencing any library and using the classes from within that library. The added difficulty is that you need to add wrappers because they are all COM objects but that has been done for you.
This might be useful to you to understand the DirectShow technology. Basically gives a start to DirctShow and explains some of the important points. But its C++ not C#. Hope this help
Basic Video Capture
DirectShow is the video capture API in Windows Mobile 6. There is a Video Capture Filter there and all in all things are designed pretty much the same way they are in Windows.
The problem is that however that this is a native API, and not just in Windows Mobile. To develop in C# you need some bindings and they are missing. On desktop there is DirectShow.NET, which is a missing piece, but it does not seem to fit well for CE. Yet you still need to fill this gap in Windows Mobile.
To work it around you have a few ways, the first would be to go through DirectShow.NET and update it appropriately to start working on your device, strip parts missing in mobile OS etc. This would get you a twin for DS.NET but for mobile operating system.
Another option would be to do some C++ development and implement the minimal sufficient feature set in that domain, exposing the component via COM. Then you will reference this from managed code and things will get connected together. And another obvious option would be to use a third party solution which already does one of the mentioned above.

VoIP/SIP Soft Phone C# WPF

I need to write VoIP/SIP Soft Phone in C# using WPF interface with Audio support only.
I need to have call transfer, call conference, and recording of conversations in mp3.
I've looked at VoIP SDK from ABTO LLC, but it is slow at application startup (30 seconds to start application, I think it's related to loading activex part of this sdk).
I've also looked at SIP.Net, but it's only for SIP and doesn't contain components for voice data transfer.
I have very limited time only 2 months from zero to fully working app.
What SDK can I use to accomplish this task?
Windows 7 must be supported.
We have done this using SipekSDK. It's written on top of famous pjSIP open source SIPClient project. It does all the operations you have mentioned in the question.
https://sites.google.com/site/sipekvoip/
What is the Sip server you are going to use ? If its not asterisk, you can have a look of microsoft's Lync here.
You can download the Lync SDK and start exploring. Not just the audio call, Microsoft Lync has features like video call, chat, presence, conference etc.... and ofcourse connectivity to landline/pstn through voip providers
Another interesting article explaining the different SDKs for unified communications can be found here
Edit: If its for Asterisk, Sipek is the only available free opensource but we had lot of problems in installing in clients system like
C folder access
Poor device
support
Port conflict- If any
other voip app like qutecom runs on
5060, then Sipek wont run as the
port is being used already.
I struggled with this exact issue and eventually came across ABTO LLC.
They have an SDK available that supports Win 7, Win XP and can be used in WPF.
We did ask them though to build a separate SDK example for us as we are using ClickOnce for our deployments and so registering external libraries is impossible, but they graciously did it and i think have integrated into their SDK, if not then ask them to give it to you.
We are using a FreeSwitch SIP Server combined with ABTO's library and it is working like a dream. We are doing VoIP, Video and Conferencing and have had no issues at all.
The application I added the VoIP functionality to is a WPF 4 app.

Categories