I have a picture box on a windows forms project. I use an OpenFileDialog class to let the user pick a video file and then I load the Video into an Emgu CV VideoCapture object. Immediately the method to play video gets called then the memory profiler under diagnostic tools skyrockets and then the program quits. I learnt that this is a memory usage issue and I may not be managing the Bitmaps in my program so well. I am reading frames from the video into a single Mat variable initialized in the class. Why is my method causing memory issues. Check out my code below
private void PlayVideo(){
//mat has been instantiated at the class level
using(mat){
while(video.Grab()){
if(video.Read(mat)){
//convert mat to bitmap and display in picture box
pictureBox1.Image = ToBitmap(mat);
//delay for 33 seconds to create video impression to user
Task.Delay(33);
}
}
}
}
Help me get rid of this memory issue in my code.