Unity WebcamTexture advanced settings (exposure, focus, zoom) - c#

I have my camera feed working in Unity that uses WebcamTexture. According to https://docs.unity3d.com/ScriptReference/WebCamTexture.html, there are no features for changing the exposure or focus settings.
Just to be clear:
Is there any way to change the exposure of WebcamTexture?
If not, is there any other way to adjust the exposure without using WebcamTexture?
If not, what are some widely used API/tools that I can use in Unity for getting camera feed with these adjustable settings?

Is there any way to change the exposure of WebcamTexture?
No. You can on Android with AndroidJavaObject but that's a hack and can stop working each time there is Unity update. Also, it will only work on Android but not on iOS, Windows, Mac and other platforms.
If not, is there any other way to adjust the exposure without using
WebcamTexture?
Again, no. You can't modify the camera settings while using WebcamTexture.
If not, what are some widely used API/tools that I can use in Unity
for getting camera feed with these adjustable settings?
The only way to be able to modify the camera settings you mentioned is to create a camera API plugin for each platform. This is not easy to do since you have to know many programming languages to get it working such as Java for Android, Objective-C for iOS and Mac, C++ for Windows and Linux and Javascript for WebGL then use C# to put them together. It's really time-consuming to make this and therefore better to use an existing plugin.
The best one out there is the NatCam plugin. This plugin can control the exposure, focus and zoom of the camera but it's not free. It's worth it.
You can set the exposure and the exposure bias as:
DeviceCamera.RearCamera.ExposureMode = ExposureMode.Locked;
NatCam.Camera.ExposureBias = NatCam.Camera.MinExposureBias;
To set the Focus Mode:
NatCam.Camera.FocusMode = FocusMode.TapToFocus | FocusMode.AutoFocus;
To zoom the camera:
NatCam.Camera.ZoomRatio = 2.0f;
You can find the complete tutorial for NatCam here.

Related

How to control exposure or brightness of webcam in UWP using MediaCapture.VideoDeviceController for QR-Code scanning

I'm working on a UWP app that needs to scan QR codes from a laptop webcam. I'm using the Windows.Media.Capture.MediaCapture class for this. Everything works well, except for when using qr code on a smartphone with it's brightness set too high for the limited dynamic range of built-in webcams. The auto-exposure of the webcam is active, but the screen can still be too bright compared to the environment.
I'm looking for a way to control or override the brightness or exposure either manually or by using some kind of exposure compensation mode.
The only properties to do with brightness/exposure that are enabled/working on my regular built-in webcam are Brightness and Contrast, and those change the image accordingly, but look like they are post-processing effects. They don't change the exposure of the camera itself, thus not fixing the issue.
mediaCapture.VideoDeviceController.ExposureCompensationControl.Supported;
mediaCapture.VideoDeviceController.ExposureControl.Supported;
mediaCapture.VideoDeviceController.ExposurePriorityVideoControl.Supported;
mediaCapture.VideoDeviceController.Exposure.Capabilities.Supported;
all return false
mediaCapture.VideoDeviceController.Brightness.TrySetValue(10);
changes the image, but highlights are still washed out and have no detail for the scanner to pickup
With respect to programmatically controlling the camera exposure via a windows driver, you are considering the correct interface. Using the MS Surface Pro 4, I have successfully modified the exposure using this interface:
mediaCapture.VideoDeviceController.ExposureControl
As well, MS has provided some nice examples and documentation for how to get this to work. Keep in mind, the examples (and the MS camera app) will hide the controls if the exposure feature is not supported by your HW.
https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/capture-device-controls-for-photo-and-video-capture
https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/CameraManualControls
The lack of access to imaging controls (such as exposure) really has nothing to do with quality. It has more to do with completeness of the camera solution. Camera sensors have a control interface (for example i2c) which is separate from the data interface which drives image. Most third party camera modules will not implement the HW/SW required to enable these controls.
The Supported property of the VideoDeviceController's control objects (ExposureCompensationControl.Supported, for example) doesn't always give accurate information unless the camera is active. So, be sure to get the preview or frame capture started before asking whether the camera controls are supported.
From VideoDeviceController
Some drivers may require that the camera device preview to be in a
running state before it can determine which controls are supported by
the VideoDeviceController. If you check whether a certain control is
supported by the VideoDeviceController before the preview stream is
running, the control may be described as unsupported even though it is
supported by the video device.

How to deal with high resolution devices while porting for android?

I recently developed a car parking game using Unity 2018, and I was facing a lot of stutters on my Note 4. Later I turned down the device resolution to 1080p from 1440, and the stuttering was gone. I would like to know how can I detect if a device resolution is above 1080p and downscale it or if there is another better way of handling it, please let me know.
You can use Screen.SetResolution to set a specific value (do it in Awake() on some script in your first scene) and then make sure you adjust the Blit Type in Player Settings to Always or you'll run into this problem.

Integrating WPF, Unity3D (and Kinect)

I created a WPF project in Visual studio. The XAML markup is managed by C# code-behind. What i want to do is create a component on the user interface, which will show a 3D scene. I would like this 3D scene to be managed by Unity, because i need to take advantage of Unity's physics engine. The user must be able to interact with this 3D scene via gestures, recognized by Kinect (for example toss a ball).
Is there any way I can connect WPF, Unity3D and Kinect, so that the user will be able to manipulate 3D scene in such manner? If so, could you provide me with some examples/tutorials? If not, what is the best approach for letting user manipulate 3D scene with Kinect gestures?
I would see How get the Unity3D View In wpf winform as for using Unity3d with wpf. The tricky part will be the Kinect interaction.
You can interface with Kinect through WPF, and use Zigfu for unity. The downside to using WPF for the Kinect interaction is that you won't be able to send data to unity unless you use the new Kinect Client Server System and send all of your information to a webserver, then retrieve it in unity. That is a very bad idea, and will probably not be fast enough and experience serious lag.
The second option, using ZigFu in unity for the Kinect support, is to be considered. The issue with it is if you want to use the Kinect in WPF, then you would have to disconnect from unity. This is the only possible way I see being able to implement
Overall, this is achievable, but will be very difficult. I suggest you use ZigFu, but there are drawbacks to both methods.
This is quite a big and generic question. But I will suggest you to use a web deployment of your unity project and, on your project/References/COM there is a UnityWebPlayerAXLib Control that will help you a lot.

Buidling an XNA tile editor

I'm writing a tile editor for a game and would like to be able to select which level file to open. Once open I would load the level into an XNA window and click to add/remove tiles to the level. When the editing is finished I would save the file layout back to the original file.
Currently I don't see a way to integrate windows forms and XNA. Is this even possible?
When I was working on a small, "2.5D" isometric game in XNA, I found it worth while to also have a separate WinForms version that would just render a 2D top-down view using GDI. This was due to my inexperience with XNA and my (relative) comfort using WinForms.
This approach also had the useful side-effect of enforcing separation between logic and rendering code. It made it easier (for me, at least) to test changes without having to worry about how to deal with the XNA rendering aspects.
It may not be exactly what you had in mind, but it might be something to consider.
WinForms and Xna can cooperate, but it's not recommended to use Xna's built in Game class with WinFroms. There are two samples demonstrating it:
http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1
http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2

game development xna/unity3d

i am want to build some games,not something big like mmorpg ,games like snake and similar,maybe in future i would like to make a progress.
i built "pong" with xna before 3 month and left it without any progression.
now i want program games again and i search on the internet and got to 2 final best options
xna/unity3d.
which is better if i know c#?
tyvm.
Well, XNA Game Studio [GS] and Unity3D do not really compare as the former is “only” a framework and the latter a full fledged game engine with visual editor and stuff.
So, XNA GS would be the right choice if you want to do it all on your own, e.g. write your own graphics renderer, the game logic infrastructure (as opposed to writing the game logic only in Unity3D) and pretty much everything else.
Unity3D would be the better choice if you want to concentrate on the game play only without having to write a lot (or any at all) infrastructure code.
However, there’s another thing to consider: if you want your game to run on the 360 you might need to use XNA GS as Unity3D doesn’t seem to support Xbox LIVE Indie Games publishing. If you’re in it for a broad range of target platforms (e.g. outside the Microsoft realm), Unity3D is the better choice (Mono.Xna, while it returned from the dead, is still in a rather unusable state).
Disclaimer: I haven’t used Unity3D at all so my words about it may be totally wrong.
XNA is fully integrated into Visual Studio and is a "first party" product (as in Microsoft produces it). You also get relatively cheap access to running it on an XBox (a nice bonus).
Unity3d has the advantage of being multi-platform (such as their iPhone port).

Categories

Resources