私はUnity3Dで航空機にカメラショーを作ろうとしています。私はAForgeのドキュメントのコードを使用しています:http://www.aforgenet.com/framework/docs/html/f4d3c2ba-605c-f066-f969-68260ce5e141.htm を除いて、私はUnityからAForgesの代わりにFilterInfoCollectionを作成したいという通常の方法でWebcamを挿入します。私が間違っていない場合、これはUnityがWebカメラを認識するために必要です。AForge VideoCaptureDeviceをUnityと連携させるには
しかし、私のコードはこれまでどおりに動作していません。ウェブカメラが(webCam.Play()のために)起動しますが、何も起こりません。私がUnityを使用しているときに何らかの方法で初期化する必要があると私は考えていました。
これを正しく設定するにはどうすればよいですか?
using UnityEngine;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Imaging.Filters;
using AForge.Imaging;
using AForge;
public class LoadVideo : MonoBehaviour {
public VideoCaptureDevice videoSource;
WebCamTexture webCam;
void Start(){
webCam = new WebCamTexture();
webCam.Play();
}
// Update is called once per frame
object b;
public WebCamDevice wc;
public GameObject originalFeed;
void Update() {
videoSource = new VideoCaptureDevice(webCam.deviceName);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.Start();
originalFeed.GetComponent<Renderer>().material.mainTexture = originalFeedTexture;
}
public delegate void EventPrototype(System.EventArgs args);
Texture2D originalFeedTexture;
void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Debug.Log("you here mate");
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
MemoryStream memoryStream = new MemoryStream();
video.Save(memoryStream, ImageFormat.Jpeg);
byte[] bitmapRecord = memoryStream.ToArray();
originalFeedTexture.LoadImage(bitmapRecord);
}
}
使用している 'AForge'のバージョンは何? –
@ AlessandroD'Andria 2.2.5 –
私は '2.2.5'に問題があり、2.2.0'にダウングレードしています(私の場合、イベントは発生しませんでした)。 –