Hi I want to open camera in windows forms in cpp.
I have an application to load images from files for processing, but I need to load live images from a camera. I edited the code but I am getting errors. Here I cite the original code and my edited version. Opencv 3.1.
Older Code
private: System::Void btnLoad_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ dgOpen = gcnew OpenFileDialog();
dgOpen->Filter = "Image(*.bmp; *.jpg)|*.bmp;*.jpg|All files (*.*)|*.*||";
if (dgOpen->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
{
return;
}
Bitmap^ bmpSrc = gcnew Bitmap(dgOpen->FileName);
ptbSrc->Image = bmpSrc;
ptbSrc->Refresh();
srcImg = imread(stringTochar.ConvertString2Char(dgOpen->FileName));
int dbSize_H = srcImg.rows;
int dbSize_W = srcImg.cols;
System::String^ h = gcnew System::String(to_string(dbSize_H).c_str());
System::String^ w = gcnew System::String(to_string(dbSize_W).c_str());
imgSize->Text = w + "x" + h;}
Edited code
//CvCapture* capture;
VideoCapture capture;
Mat frame, srcImg;
private: System::Void btnLoad_Click(System::Object^ sender, System::EventArgs^ e) {
capture.open(0);
if (capture.isOpened())
capture.read(frame);
ptbSrc->Image = gcnew;
System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
ptbSrc->Refresh();
srcImg = frame;
int dbSize_H = srcImg.rows;
int dbSize_W = srcImg.cols;
System::String^ h = gcnew System::String(to_string(dbSize_H).c_str());
System::String^ w = gcnew System::String(to_string(dbSize_W).c_str());
imgSize->Text = w + "x" + h;}
Here frame is for picture box 'ptbSrc' and srcImg for further processing.
any chance, we can talk you out of this idea ?
opencv and managed c++ do never go well together (entirely orthogonal programming models)
being a noob, you'll run into more trouble than nessecary. can't you just stick with opencv's highgui window to show the video ?
Actually i have an application for reading characters from license plate by loading images from file by clicking a load button. Now I need to replace the image load button by a camera button. The problem comes in System::Drawing::Bitmap(frame.width,frame.height,frame.widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame.imageData); where the error showing that class cv::Mat has no member width, height, widthStep, imageData. Moreover is there any substitute for Bitmap^ bmpSrc = gcnew Bitmap(dgOpen->FileName); in video class?
http://docs.opencv.org/master/d3/d63/...