Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture high resolution video and capture photo from it in windows 8.1. I am having a UI jumping effect while tried it

Im my camera capturing application am used to take continuous photos using the Camera implemented in a view using CaptureElement. When it taks continuouly capturing the photos the UI is moving back and forth seems like a jump effect. That is the problem am facing.

Codes used are the following

var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
MediaCaptureInitializationSettings settings=new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id, StreamingCaptureMode = StreamingCaptureMode.Video };
var_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(settings);
if (null != videoCapture) videoCapture.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();

setting the high resolution

int max = 0;
var resolutions = videoController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
            for (var i = 0; i < resolutions.Count; i++)
            {
                ImageEncodingProperties res = resolutions[i] as ImageEncodingProperties;
                if (null == res) continue;


                if (res.Width * res.Height < max)
                {
                    max = (int)(res.Width * res.Height);
                    _imageEncodingProperties = res;
                }
            }

     await videoController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, _imageEncodingProperties);

And capturing the photo from video frame using

    using (var photoStream = new InMemoryRandomAccessStream())
                {                        
                    await _mediaCapture.CapturePhotoToStreamAsync(_imageEncodingProperties, photoStream);
                    await photoStream.FlushAsync(); 
                }

I tested capturing by setting different video resolutions.

var videoController = _mediaCapture.VideoDeviceController;

Firstly i set default preview resolution [640x480] for the videoController and capturing process is taking place without any issue. And after that i checked it by setting High resolution [1200x800] in Surface tablet , in this case a photo frame is appearing over the video control for a moment and and it is having some small width on each side. It feels like a zoom in / zoom out effect [back n forward jumping] in the camera view.

Have anybody getting this problem when setting high resolution to the video media element video controller in windows 8.1? I t will be great if anybody can explain it's reason.

Thanks

EDIT: I analysed the situation and found the following things

There many available resolutions 640 x 360 , 1280x720 , 1280x800 , 640x480 etc

And i found that this problem is not at all occurs at the resolutions where width to height ratio is 1.777778. All other resolutions where the rato is less than 1.777 have the issue.

That is , The problem doesn't exists for 640x360 , 1280x720 resolutions and other two have the jumping effect. I think the last 2 one have the ratio 1.6 and 1.33 respectively.

Also i checked with default camera app and captured photos by setting 1280x800 resolution, there i saw there is a black border both sides of the camera element in the window.

Conclusion:

The issue was with the aspect ratio. When i set High resolution [1280x800] from the available camera resolutions which is not maintaining the surface device's aspect ratio [1366x768], so that the Image is trying to fit in to the screen and an jumping effect felt by the user. So i set the Highest resolution which maintains the device aspect ratio , which is 1280x720 and the problem solved.

like image 897
asitis Avatar asked Oct 01 '22 17:10

asitis


1 Answers

Actually the issue was with the aspect ratio. When i set High resolution [1280x800] from the available camera resolutions which is not maintaining the surface device's aspect ratio [1366x768], so that the Image is trying to fit in to the screen and an jumping effect felt by the user. So i set the Highest resolution which maintains the device aspect ratio , which is 1280x720 and the problem solved.

like image 84
asitis Avatar answered Oct 21 '22 10:10

asitis