工作我试图让在Unity3D的平面上的摄像头表演。我使用的代码从AForge文档:http://www.aforgenet.com/framework/docs/html/f4d3c2ba-605c-f066-f969-68260ce5e141.htm 除了我将通过统一,而不是通常的AForges方式一个摄像头,它希望让FilterInfoCollection。如果我没有错,Unity需要识别摄像头。制作AForge VideoCaptureDevice使用Unity
但是我的代码是不工作什么那么,摄像头开始(因为我webCam.Play的()),但没有什么事情发生。通过调试,我发现程序没有达到我的video_NewFrame函数,我相信在使用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'的问题(在我的情况下,事件从未提出过)。 –