Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using OpenCVForUnity;
- public class webcam : MonoBehaviour
- {
- public int Width = 1920;
- public int Height = 1080;
- public int FPS = 30;
- public Material material;
- VideoCapture video;
- public int VideoIndex = 1;
- Texture2D texture;
- void Start()
- {
- video = new VideoCapture(VideoIndex);
- video.set(Videoio.CAP_PROP_FOURCC, VideoWriter.fourcc('M', 'J', 'P', 'G')); // ←この行があるかどうかでフレームレートが変わる
- video.set(Videoio.CAP_PROP_FRAME_WIDTH, Width);
- video.set(Videoio.CAP_PROP_FRAME_HEIGHT, Height);
- texture = new Texture2D(Width, Height, TextureFormat.RGB24, false);
- material.mainTexture = texture;
- }
- void Update()
- {
- using (Mat image = new Mat())
- {
- video.read(image);
- Utils.fastMatToTexture2D(image, texture);
- }
- }
- void OnApplicationQuit()
- {
- if (video != null)
- {
- video.Dispose();
- video = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement