Take a Picture of Persenels with a Digital Camera Attached To Computer - c#

I Want Create a Win-Form Application Can be Connect to a Digital Camera Attached to My Computer.I Want See a LiveView of Persenels in Computer And Then Take a Picture of Persenels.
How Can I Implement This Action?
What Camera Can I Use?
What Component Or Library Can I Use??
What SDk Tools Can I Use??
Please Help me...

You can do this with the Windows Image Acquisition API. Get this started with Project + Add Reference, Browse tab, navigate to c:\windows\system32\wiaaut.dll. That's a COM component, you'll get an interop library for it with interface types in the WIA namespace.
First thing you want to do is get a reference to the camera, use WIA.ShowSelectDevice(). It returns a Device object if there's only one camera attached, a dialog to let the user select if there are more. Like this:
public static WIA.Device SelectCamera() {
var dlg = new WIA.CommonDialog();
try {
return dlg.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, false);
}
catch (System.Runtime.InteropServices.COMException ex) {
if (ex.ErrorCode == -2145320939) return null;
throw;
}
}
That ought to get you started. Check out the code snippets at this MSDN page for more of the thing you can do with the API. Beware that not all cameras allow you do use them interactively when they are attached to the machine. My cheapo point-and-shoot doesn't.

Related

Access MacBook camera using C# and Xamarin.Mac forms on Visual Studio?

I need to integrate a video stream from my Macbook camera using a Xamarin.Mac form. However, all of the documentation that I find only tells you how to do so in iOS and Android platforms.
How would you go at getting a video stream from a Macbook then? Any libraries I should look at?
You will want to review the AVFoundation APIs (QTKit is deprecated).
You can create a custom Xamarin.Forms View renderer based on a NSView and assign the AVCaptureVideoPreviewLayer as the control's layer to stream the camera output to this control.
Store class level references to following and make sure you Dispose them when your control goes out of scope otherwise there will be leaks:
AVCaptureDevice device;
AVCaptureDeviceInput input;
AVCaptureStillImageOutput output;
AVCaptureSession session;
In your capture setup, you can grab the default AV device assuming you want to use the build-in FaceTime Camera (also known as iSight).
macOS/Forms Example:
device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
input = AVCaptureDeviceInput.FromDevice(device, out var error);
if (error == null)
{
session = new AVCaptureSession();
session.AddInput(input);
session.SessionPreset = AVCaptureSession.PresetPhoto;
var previewLayer = AVCaptureVideoPreviewLayer.FromSession(session);
previewLayer.Frame = Control.Bounds;
Control.Layer = previewLayer;
output = new AVCaptureStillImageOutput();
session.AddOutput(output);
session.StartRunning();
}
Note: A lot of the AVFoundation framework is shared between iOS and MacOS, but there are some differences so if you end up looking at iOS sample code be aware you might need to alter it for macOS.
https://developer.apple.com/documentation/avfoundation

Embedding Cardboard profile in Unity3D

I want to avoid users having to scan the QRCode with the Cardboard Viewer profile on it so that they can just place their device into the viewer and be ready. The viewer configuration is constant and I have a profile URL for it. Is it possible to load this profile at the application start up in Unity3D and if so how should I do it?
I tried setting it up by loading the following line of code at the Start of a Script attached to a camera but without any luck:
Cardboard.SDK.DefaultDeviceProfile = new Uri(SpecificVRViewerProfileUrl);
I'm using Unity 5.3.1f1, Cardboard 0.6, and Vuforia.
I haven't used the Unity SDK for cardboard, only java, but looking through the sample (https://github.com/googlesamples/cardboard-unity/blob/master/Cardboard/Scripts/Cardboard.cs) you might want to try getting a device reference using BaseVRDevice. It's a class also in the samples (https://github.com/googlesamples/cardboard-unity/blob/master/Cardboard/Scripts/VRDevices/BaseVRDevice.cs)
// The VR device that will be providing input data.
private static BaseVRDevice device;
device = BaseVRDevice.GetDevice();
device.Init();
and then setting the device profile with this instead of Cardboard.SDK.SetDefaultDeviceProfile
public Uri DefaultDeviceProfile = new Uri("your URL here");
if (DefaultDeviceProfile != null) {
device.SetDefaultDeviceProfile(DefaultDeviceProfile);
}

MagneticStripeReader.GetDefaultAsync(); returns null

I have a usb connected MSR reader and i am trying to get it by using the sample codes proveded in here. This works fine but the problem is when i add the same code to my app it doesn't work. GetDefaultAsync returns null.
private static MagneticStripeReader _reader = null;
public static async void StartRead()
{
if (await CreateDefaultMagneticStripeReaderObject())
{
....
}
}
private static async Task<bool> CreateDefaultMagneticStripeReaderObject()
{
if (_reader == null)
{
_reader = await MagneticStripeReader.GetDefaultAsync();
if (_reader == null)
return false;
}
return true;
}
My code is like above, very similer to sample but it doesnt work. Also i've added the device capability of pointOfService. So that is not the case.
I was in the exact same situation and I spent the last 5 hours, finally I know what was going on. You are missing a capability in the Package.appxmanifest
'pointOfService' is the capability you want to include. This capability does not show in the UI and therefore I could not find any difference between my broken project and Microsoft's sample project. You can not add that capability using the UI. You have to manually add it by modifying the XML file.
The sample project by Microsoft have it too
https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/MagneticStripeReader/cs/Package.appxmanifest#L53
Make sure the card reader is in HID mode and not Keyboard emulation mode. That was one of my problems.
To do this is really wonky. MagTek has a ActiveX control on their website to assist us... because ActiveX is awful, you can only use it with InternetExplorer (it won't even work with Edge.)
go here in IE: https://www.magtek.com/changemode/
Enable active X when it pops up, and you can change from hid to keyboard and back.

Play .oni-File on loop in C# / WPF

I'd like to play a previously recordet *.oni-File in C#/WPF. While, with the help of this tutorial I was able to get to RGB- and Depth-Stream to show up on my UI, I don't know how to play an *.oni-file.
The OpenNI page mentions, that I'd just have to "connect" to the file instead of the device, but I can't find the proper piece of code to do so.
The openni::Device class provides an interface to a single physical hardware device (via a driver). It can also provide an interface to a simulated hardware device via a recorded ONI file taken from a physical device.
If connecting to an ONI file instead of a physical device, it is only required that the ONI recording be available on the system running the application, and that the application have read access to this file.
I also found some clues / discussions, but none of it did help much
C# problem with .oni player
OpenNI-dev: Not able to play the skeletonRec.oni
EDIT: I found a way to at least get the recording played using the SamplesConfig.xml. I just inserted the following code into the <ProductionNodes>:
<Recording file="\test.oni" playbackSpeed="1.0"/>
Sadly, that recording crashes to program when it's done playing - I'm now looking for a way to loop the recording...
EDIT 2: Just if anybody should be interested, I'm using those lines to set the recording on loop:
ScriptNode scriptNode;
context = Context.CreateFromXmlFile(path + "\\" + configuration, out scriptNode);
Player p = (Player)context.FindExistingNode(NodeType.Player);
if (p!=null) p.SetRepeat(true); //Make sure it's really a recording.
If anybody should need the code one day - I managed to load the file and play the recording without the need of a config file:
Context context = new Context();
// Add license
License license = new License();
license.Vendor = "vendor";
license.Key = "key";
context.AddLicense(license);
// Open file
context.OpenFileRecordingEx("record.oni");
// Set to repeat
Player p = (Player)context.FindExistingNode(NodeType.Player);
if (p != null) p.SetRepeat(true);

How can I check that PowerPoint or point viewer is installed on the machine?

I need to play PowerPoint slides but first I want to check whether PowerPoint or viewer is installed on the machine or not. How can I do that using .NET?
It depends on whether you are trying to tell whether you can view a presentation (*.ppt, *.pptx, etc) or whether you can access the PowerPoint object model.
To check whether there is an associated handler for ppt files, you can do the following:
// using Microsoft.Win32;
private bool CheckPowerPointAssociation() {
var key = Registry.ClassesRoot.OpenSubKey(".ppt", false);
if (key != null) {
key.Close();
return true;
}
else {
return false;
}
}
if (CheckPowerPointAssociation()) {
Process.Start(pathToPPT);
}
To check whether the PowerPoint COM object model is available, you can check the following registry key.
// using Microsoft.Win32;
private bool CheckPowerPointAutomation() {
var key = Registry.ClassesRoot.OpenSubKey("PowerPoint.Application", false);
if (key != null) {
key.Close();
return true;
}
else {
return false;
}
}
if (CheckPowerPointAutomation()) {
var powerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();
....
}
Note, however, that in both cases it will only give you a pretty good indication of the availability of PowerPoint. For example, an uninstallation may not have fully removed all traces. Also in my experience selling an Outlook addin for years I've seen certain antivirus programs that interfere with the COM object model in a screwup effort to protect against malicious scripts. So in any case, have robust error handling as well.
Hope this helps!
HKEY_CLASSES_ROOT\MSPowerPoint\protocol\StdFileEditing\server
This key is the same for all installs of PowerPoint and points to the install dir for the executable to run PowerPoint. Great to use when detecting if this product is installed and good for figuring out which folder Office products are installed in, when the install is not using the defaults.
I am not sure this is the right way to do this. But you can use this
try
{
//It will throw a WIN32 Exception if there is no associated
//application available to open the file.
Process p = Process.Start("C:\\Sample.pptx");
}
catch (Win32Exception ex)
{
MessageBox.Show("Powerpoint or Powerpoint viewer not installed\n");
}
What about checking if the EXE file for PowerPoint or PowerPoint viewer exists or not by using "Exists Method" from system.io namespace?
Check this.

Categories

Resources