编辑:已解决!有关详细信息,请参阅下面的答案.我无法找到原始问题的答案,但我找到了另一种解决方案
这个问题可能会在其他地方被问到,但我一直在寻找几天,找不到任何有用的东西.
问题:我需要一次性将"Stream"转换为"image(bgr,byte)",是否有一种方法/命令可以直接从System.Drawing.Image.FromStream转换为Emgu.CV.Image(Bgr,Byte)在不脱离转换流至图像以位图,以图像(BGR,字节)?
信息:我在Visual Studio 2010中使用c#进行编码,这是我的论文项目的一部分.我正在从网络上的IP摄像机拍摄图像流,并应用许多算法来检测面部/提取面部特征并识别个人面部.在我的笔记本电脑本地相机上我可以实现约25~(给或拿)的FPS,包括算法,因为我不需要转换图像.对于IP摄像机流,我需要多次转换才能达到所需的格式,结果大约为5-8fps.
(我知道我目前的方法是非常低效的,这就是为什么我在这里,我实际上是将图像总共转换5次(甚至是灰度缩放),实际上只使用了我处理器内存的一半(i7,8gb RAM)).它必须是图像(bgr,byte),因为这是算法将使用的唯一格式.
我用来获取图像的代码:
//headers
using System.IO
using System.Threading;
using System.Net;
//request a connection
req = (HttpWebRequest)HttpWebRequest.Create(cameraUrl);
//gives chance for timeout for errors to occur or loss of connection
req.AllowWriteStreamBuffering = true;
req.Timeout = 20000;
//retrieve response (if successfull)
res = req.GetResponse();
//image returned
stream = res.GetResponseStream();
Run Code Online (Sandbox Code Playgroud)
我在后台管理连接,数据,安全等方面有很多东西,我已经缩短到上面的代码.我目前的代码将图像转换为所需的输出:
//Convert stream to image then to bitmap
Bitmap bmpImage = new Bitmap(System.Drawing.Image.FromStream(stream));
//Convert to emgu image …Run Code Online (Sandbox Code Playgroud) 编辑:问题回答.伊戈尔完美地解释了答案.(谢谢!)
问题:如何从同一程序中的另一个类访问/控制线程?我将激活多个线程(不是一次全部),我需要检查一个是否处于活动状态(这不是主线程).
我正在用C#编程,我正在尝试使用线程.我有2个类,我的线程在主类中启动,在另一个类中调用一个函数.在我的其他课程中,我想看看"thread.isAlive == true",但我认为它不公开.我不知道能够使用来自另一个类的线程的语法/代码?我很难让它发挥作用.
我可以调用另一个类,但我不能在类之间调用线程.(不能在类之外声明一个线程)抛出的错误是:
Error 1 The name 'testThread' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
示例代码:
//Headers
using System.Threading;
using System.Threading.Tasks;
namespace testProgram
{
public class Form1 : Form
{
public void main()
{
//Create thread referencing other class
TestClass test = new TestClass();
Thread testThread = new Thread(test.runFunction)
//Start the thread
testThread.Start();
}//Main End
}//Form1 Class End
public class TestClass
{
public void runFunction()
{
//Check if the thread is active
//This …Run Code Online (Sandbox Code Playgroud)