1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#pragma once
#include "opencv2/opencv.hpp"
#include "iostream"
#include "Windows.h"
#include "stdlib.h"
#include "stdio.h"
namespace WebCamAN {
using namespace cv;
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//TODO: Add the constructor code here
//
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ Run;
private: System::Windows::Forms::Button^ Stop;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private:
System::ComponentModel::Container ^components;
//char a;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
// Code generated by VisStud2008 IDE - constructors for buttons, pictureBox, etc.
}
#pragma endregion
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
private: System::Void Run_Click(System::Object^ sender, System::EventArgs^ e) {
char a;
//AllocConsole();
//freopen("CONOUT$", "w", stdout);
VideoCapture capture(1);
Mat frame;
while(1)
{
//int a;
//char a;
capture.read(frame);
System::Drawing::Graphics^ graphics2 = pictureBox1->CreateGraphics();
System::IntPtr ptr2(frame.ptr());
System::Drawing::Bitmap^ b2 = gcnew System::Drawing::Bitmap(frame.cols, frame.rows, frame.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr2);
System::Drawing::RectangleF rect2(0,0,pictureBox1->Width, pictureBox1->Height);
graphics2->DrawImage(b2, rect2);
//delete graphics2;
//a = getchar();
// This code is an attempt //printf(a);
// at writing value of variable //if(a=='q'||a=='Q')
// a to Output Window and at //{
// graceful shutdown. //delete b2;
// Doesn't work. //delete pictureBox1->Image;
//pictureBox1->Image = nullptr;
//delete graphics2;
//break;
//}
}
} // End of Run_Click
private: System::Void Stop_Click(System::Object^ sender, System::EventArgs^ e) {
exit(0);
} // End of Stop_Click
};
}
| |