【unity opencv 调整摄像头参数】

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
参考:https://blog.csdn.net/hkmaike/article/details/103193980
https://blog.csdn.net/weixin_47965042/article/details/113359922

using OpenCVForUnity.CoreModule;
using OpenCVForUnity.UnityUtils;
using OpenCVForUnity.VideoioModule;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CS1 : MonoBehaviour
{
VideoCapture vv;
float camerFps = 60f;
WaitForSecondsRealtime waitTime1;
[SerializeField] RawImage rawImage;
int videoW, videoH;
// Start is called before the first frame update
private void Start()
{
vv = new VideoCapture(0);
if (vv.isOpened())
{
print(“isOpened”);
print(camerFps=(float)vv.get(5));
print(videoW = (int)vv.get(3));
print(videoH = (int)vv.get(4));

           waitTime1 = new WaitForSecondsRealtime(1f/camerFps);
           m = new Mat();
           StartCoroutine(ShowVideo());
    }
    else
    {
        print("UpOpened");
        return;
    }

}
Mat m;
IEnumerator ShowVideo()
{
    while (true)
    {
        yield return waitTime1;
        
        
        if (vv.grab())
        {
            print("up");
            vv.retrieve(m);
            Texture2D outputTexture = new Texture2D(videoW, videoH, TextureFormat.RGBA32, false);
            Utils.matToTexture2D(m, outputTexture);
            rawImage.texture = outputTexture;
        }
    }
    
    
}
private void Update()
{
    if (Input.GetKeyDown(KeyCode.A))
    {
        vv.set(10,-63);//亮度 -64 ~64
    }
    if (Input.GetKeyDown(KeyCode.B))
    {
        vv.set(10, 63);
    }
}

}

猜你喜欢

转载自blog.csdn.net/u010267208/article/details/125620574