I tried to use imwrite
to successfully to display an image on a Windows Form, but it damages the disk, so I need a better way to do this.
Below, is my current code, which writes the image temporarily to the hard drive:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
namedWindow("video",0);
VideoCapture cap(0);
flag = true;
while(flag){
Mat frame;
cap >> frame; // get a new frame from camera
**imwrite("vdo.jpg",frame);**
this->panel1->BackgroundImage = System::Drawing::Image::FromFile("vdo.jpg");
waitKey(5);
delete panel1->BackgroundImage;
this->panel1->BackgroundImage = nullptr;
}
}
When I try to use the OpenCV Mat
that is in memory, I cannot get it to work. The following code snippets are what I have tried so far:
this->panel1->BackgroundImage = System::Drawing::Bitmap(frame);
or
this->panel1->BackgroundImage = gcnew System::Drawing::Bitmap( frame.widht,frame.height,System::Drawing::Imaging::PixelFormat::Undefined, ( System::IntPtr ) frame.imageData);
I want to display frame
in this code without using imwrite
. How do I accomplish this?