Metro MediaCapture MFT Effect Explaination - c#

I'm trying to apply an effect on a mediacapture stream for a WPF app I'm porting over to Metro. In the WPF app I used Pixel shaders to modify a bitmap whose source was set to the stream of a webcam, but since effects have been dropped for Metro I'm looking for an alternative solution.
The best, and most Metro standards compliant, way of doing this that I've found is building my own MFTs and adding them to my MediaCapture element via the addEffectAsync() method. I've downloaded the MFTGrayscale and MediaExtension examples which show how to apply these effects to a MediaCapture element, but I'm having an issue understanding the actual C++ MFT code. Can someone point me to or give a decent walkthrough/explanation of how I'd go about building my own MFT effect from the ground up? I don't know too much C/C++, just enough to understand some of the example code. I'm really having trouble with the conceptual and architectural aspects of MFT, and hence am very confused by the source code.
Your help is very much appreciated.
EDIT:
Another option I'd consider is using SharpDX. However I'm having issues getting a stream of the MediaCapture object to display on a xaml image element. Any help would be appreciated. Thanks.

You should absolutely have a look at the following git repo: https://github.com/mmaitre314/VideoEffect
It shows how to apply image effects from the Lumia Imaging SDK, Win2D, and DirectX HLSL pixel shaders to videos in Universal Store Apps for Windows Phone 8.1 and Windows 8.1.
Effects can be applied via MediaTranscoder, MediaComposition, MediaCapture, or MediaElement. And the binaries are available via NuGet.

I ended up getting answer on the MSDN forums. It's not an ideal answer, but it's what I'd been fearing all along.
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/f3a6934e-df7a-44da-bfd8-7b95d494ff43/#90690f89-e57d-4043-9881-60fcc587f736

This is totally doable... I've just rewritten one of the MF transforms from the samples to use the Nokia Imaging SDK and apply filters in real-time to webcam video. You can see how I did it at the link below (plus download some source code). It's not exactly what you need to do, but in the wiki page I explain what you need to change from the boilerplate sample that MS provided.
http://developer.nokia.com/community/wiki/Template_universal_app_for_video_recording_with_MediaCapture_using_Imaging_SDK_Filters

Related

How to take high quality photo from integrated camera in WPF

I'm implementing WPF app where I need to take high quality photos from integrated camera. So far I've been successful with capturing video and taking frames from it (described for example here: Wpf and C # capture webcam and network cameras).
But this is not what I want - because video frame quality is not so great. I have MS Surface 4 Pro which has 8Mpx camera with full HD video support and with the above method I'm able to just get full HD frame from it. But I would like to have full 8Mpx picture, like it is possible to take in the native Windows Camera app.
In UWP I would probably have been successful with CameraCaptureUI class, but I didn't find any clues for WPF.
Does anyone has an idea how this could be implemented?
I've found out that XAML Islands do work with .NET Framework 4.8. So I've been able to implement a WPF solution using UWP components MediaCapture and CaptureElement. With that I can take photos with full resolution which was my goal.
Simple sample project can be found here: https://github.com/ondrasvoboda/WPFCamera, consider it just as a proof of concept.
If your app will run on Windows 10 or above, you can now use most of the APIs from Windows 10 in a WPF application.
https://blogs.windows.com/windowsdeveloper/2019/04/30/calling-windows-10-apis-from-a-desktop-application-just-got-easier/

Image Processing in Metro Application

I need to do some image processing in a Windows 8 metro application. I have written some functions in MATLAB for that. Is there a way I can integrate them in my application? I am kinda lost here. Can anyone suggest something about this? I would be grateful.
P.S: In my MATLAB program I am detecting face shape and skin tone.
Sure, why not? Just re-implement your Matlab code in C# or C++. Do you have a specific question?
You can use computer vision libraries like OpenCV (or the EmguCV C# wrapper) or AForge.NET.
Here is lightweight image processing sample. I think it's better to check this sample, it might be helpful to you. Please note the article is bit older so it must be updated by author.

Get image from webcam

I'm trying to find the way for getting image (only image, not video stream) from webcam in managed C#.
Usually people suggesting libraries, but they are old or commercial or under gpl.
How get image from webcam without third-party libraries?
upd.: thanks for Media Foundation, I shall use that.
Web cameras are supposed to deliver video feeds, not stills. So the native API you might be interested in is the one for video capture, which are DirectShow and Media Foundation.
The one you would most likely want is DirectShow, but it is not well suited to be interfaced from managed code, so you will need a DirectShow.NET which is open source wrapper. You typically start video streaming there and once you have a good image you stop the activity.
Or instead you might keep looking for a ready to use library which does the mentioned above for you.
One of DirectShow.NET samples does what you look for.
DxSnap – Use DirectShow to take snapshots from the Still pin of a
capture device. Note the MS encourages you to use WIA for this, but if
you want to do in with DirectShow and C#, here's how.
It mentions WIA, however WIA API is not available for all (or any in recent OSes?) web cameras, WIA more targets device like scanners.
Other APIs are perhaps less suitable.
VFW ("avicap32.dll") limits you to a subset of devices, is simple yet not well interfaced into managed code
Media Foundation is not well available in earlier OS versions
I wrote this many years ago
http://www.vbforums.com/showthread.php?344471-Vb.Net-WebCam-Class-(ICam)) in VB.net
You could easily port it to c#?
Is avicap32.dll out of the question?
Otherwise I think this is a simple and straightforward way:
http://www.creativecodedesign.com/node/66
http://www.c-sharpcorner.com/uploadfile/yougerthen/integrate-the-web-webcam-functionality-using-C-Sharp-net-and-com-part-viii/

How to implement face recognition in an image in .net 3.5?

I need to implement face recognition like in orkut album.
In my website when a user uploads a photo and checks the photo in album I need to implement the feature and place rectangles over the faces in photo like in orkut album like in this link.
Please help me to implement this.
Thanks in advance.
You need to use OpenCV, or more specifically, a C# wrapper library for OpenCV.
I think you can implement some (very) basic face detection using OpenCVDotNet, although you should be aware that I don't think it's actively being developed. I just noticed I'm still on the list as a project committer, but I haven't done any work on it for a long time (if ever, can't remember why I got added in the first place).
You should probably go with Emgu CV, which is a much better C# wrapper for OpenCV. It is actively developed, and is compatible with OpenCV 2.0, and has a wider community surrounding it, and the documentation is good enough that you can easily get face detection working pretty quickly.

C# Grab frame from wmv file

Does anyone know if it is possible to grab a frame/image from a video (.wmv) on position X using C# without installing DirectX and working on Windows 2008 (a webserver I would like to install as less as possible).
Or even a simple solution with directx could be nice.
Henk
What you'll actually need to look into is DirectShow, the general-purpose media (both audio and video) library for Windows. It used to be part of DirectX but several years ago it branched off and became part of the Windows (Platform) SDK. I should also point out here that it's now been deprecated since Windows Vista in favour of Media Foundation. From what I've read it's a much better library (DirectShow is hell for complex tasks), but unfortunately it's not really feasible to only target Media Foundation at the moment because of the lack of support for XP and earlier...
The best I can really do is point you to DirectShow.NET, a .NET wrapper library for DirectShow, which is rather stable and well tested at the moment. It includes various samples which should help you get going, but by no means will it be a straightforward solution. Also, I strongly recommend you take a look at this CodeProject article/sample application. It deals with both webcam video capture and video playback from files (including WMV). A bit of playing around with that, and learning how to do frame seeking/single frame capture (I think that project might even some code to do that) should get you what you need. Perhaps you'll even find the precise solution somewhere within the DirectShow.NET samples of that CodeProject app.
Of course, I would suggest an easier solution if I could here, but you're pretty much stuck with the horribleness that is DirectShow for the moment. Good luck anyway!
You should try FFmpeg.
Take a look at the Windows Media Format SDK, which is designed to give you pretty direct access to the frames inside a WMV (/WMA/ASF) file.
http://msdn.microsoft.com/en-us/library/dd757738(VS.85).aspx
In particular, you're interested in the synchronous API for reading these files (IWMSyncReader is the interface name). There are some pretty decent samples in the WMFSDK; I believe the most interesting one for you here will be WMSyncReader, which will show you how to dig through a WMV file and get frames, starting at position X.

Categories