Advertisement
MobileHackerz

Untitled

Jul 7th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using OpenCVForUnity;
  4.  
  5. public class webcam : MonoBehaviour
  6. {
  7.     public int Width = 1920;
  8.     public int Height = 1080;
  9.     public int FPS = 30;
  10.     public Material material;
  11.  
  12.     VideoCapture video;
  13.     public int VideoIndex = 1;
  14.     Texture2D texture;
  15.  
  16.     void Start()
  17.     {
  18.         video = new VideoCapture(VideoIndex);
  19.         video.set(Videoio.CAP_PROP_FOURCC, VideoWriter.fourcc('M', 'J', 'P', 'G')); // ←この行があるかどうかでフレームレートが変わる
  20.         video.set(Videoio.CAP_PROP_FRAME_WIDTH, Width);
  21.         video.set(Videoio.CAP_PROP_FRAME_HEIGHT, Height);
  22.  
  23.         texture = new Texture2D(Width, Height, TextureFormat.RGB24, false);
  24.         material.mainTexture = texture;
  25.     }
  26.  
  27.     void Update()
  28.     {
  29.         using (Mat image = new Mat())
  30.         {
  31.             video.read(image);
  32.             Utils.fastMatToTexture2D(image, texture);
  33.         }
  34.     }
  35.  
  36.     void OnApplicationQuit()
  37.     {
  38.         if (video != null)
  39.         {
  40.             video.Dispose();
  41.             video = null;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement