ヒント: 記事を書いた後、目次を自動的に生成することができます. 生成方法は、右のヘルプドキュメントを参照してください
.
/article/details/113359922
OpenCVForUnity.CoreModule の使用;
OpenCVForUnity.UnityUtils の使用;
OpenCVForUnity.VideoioModule の使用;
System.Collections を使用します。
System.Collections.Generic の使用;
UnityEngine の使用;
UnityEngine.UI の使用;
public class CS1 : MonoBehaviour
{ VideoCapture vv; float cameraFps = 60f; WaitForSecondsRealtime waitTime1; [SerializeField] RawImage rawImage; int videoW、videoH; // Start は最初のフレーム更新前に呼び出されます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);
}
}
}