1

我正在尝试从运行 Windows IOT 核心的 Raspberry Pi 2 上的网络摄像头捕获图片。有时我得到未对齐的图片,如下所示。我在使用不同的网络摄像头时遇到了同样的问题。错位似乎非常随机。每次拍摄时,我都会得到不同类型的错位。请帮忙。

在此处输入图像描述 在此处输入图像描述

这是代码。

    private Windows.Media.Capture.MediaCapture captureManager;
    private ImageEncodingProperties imgFormat;
    private StorageFolder myPictures;

    public Camera()
    {
        captureManager = new MediaCapture();
        captureManager.InitializeAsync().AsTask().Wait();
        imgFormat = ImageEncodingProperties.CreateJpeg();
        StorageLibrary pictureLibrary = Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures).AsTask().Result;
        myPictures = pictureLibrary.SaveFolder;
    }

    public StorageFile TakePictureToFile()
    {
        DateTime now = DateTime.Now;
        string foldername = now.ToString("ddMMyy");
        string filename = now.ToString("hh-mm-sstt fffffff");

        StorageFolder foldertosave = null;
        if (!Directory.Exists(myPictures.Path + "\\" + foldername))
        {
            foldertosave = myPictures.CreateFolderAsync(foldername).AsTask().Result;
        }
        else
        {
            foldertosave = myPictures.GetFolderAsync(foldername).AsTask().Result;
        }
        StorageFile file = foldertosave.CreateFileAsync(filename).AsTask().Result;

        captureManager.CapturePhotoToStorageFileAsync(imgFormat, file).AsTask().Wait();
        return file;
    }
4

0 回答 0