Edit: SOLVED! See my answer below for more details. I could not find the answer to the original question, but found an alternative solution
This question can be asked elsewhere, but I have been looking for days and cannot find anything that will help.
Question: I need to convert "Stream" to "image (bgr, byte)" at a time, is there a way / command to convert directly from System.Drawing.Image.FromStream to Emgu.CV.Image (Bgr, Byte) without conversion from stream to image to bitmap (bgr, byte)?
Info: I am coding in C # in Visual Studio 2010 as part of my dissertation project. I take a stream of images from an IP camera on the network and use many algorithms to detect faces / extracts of facial functions and face recognition. On my laptop, the local camera I can achieve FPS about 25 ~ (give or take), including algorithms, because I do not need to convert the image. For the IP camera stream, I need to convert it many times to achieve the desired format, and the result is about 5-8 frames per second.
(I know that my current method is extremely inefficient, so here I am, I actually convert the image 5 times (even gray scale), in fact, only half the memory of my processors (i7, 8 GB RAM)). This should be an image (bgr, byte), since this is the only format that algorithms will work with.
The code I use to get the image:
//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();
I have many things related to managing connections, data, security, etc., which I have reduced to the above code. My current code is to hide the image until the desired result:
//Convert stream to image then to bitmap Bitmap bmpImage = new Bitmap(System.Drawing.Image.FromStream(stream)); //Convert to emgu image (desired goal) currentFrame = new Emgu.CV.Image<Bgr, Byte>(bmpImage); //gray scale for other uses gray = currentFrame.Convert<Gray, Byte>();
I understand that there is a way to save the image locally temporarily, but I will need to avoid this for security reasons. I am looking more for direct conversion to help conserve computing power. Am I missing something? All help is appreciated.
Thank you for reading. (I will update this if someone asks for more details) -Dave