Ir para conteúdo
Fórum Script Brasil

diegobill

Membros
  • Total de itens

    13
  • Registro em

  • Última visita

Tudo que diegobill postou

  1. Eu sempre trabalhei com projetos CLR, sendo assim quando precisava instanciar um objeto de uma classe de um projeto em outro projeto, bastava adicionar a referencia do projeto e colocar o using namespace. Agora estou fazendo projetos WIN32, mas não estou conseguindo mais fazer isso. Para conseguir fazer a mesma coisa, tive que além de colocar a reference e o namespace, tive que adicionar o .h da classe no additional include directories e tive que adicionar o .cpp da classe no projeto, esse método é o correto? Fazendo isso acabo passando dependência de um projeto, coisa que eu gostaria de evitar.
  2. vlw ae galera... brigadaum... consegui resolver o problema....
  3. é uma função que através dos valores RGB do pixel classifica o pixel em ciano, rosa, verde ou preto utilizando uma rede neural MLP
  4. Está função trabalha em cima de vários frames(Bitmaps) de um vídeo, porém o programa trava quando chega na linha de comando: "classificacao = ClassificarMLP(ptr[pix + 2], ptr[pix + 1], ptr[pix]);" e recebo está mensagem: AccessViolationException was unhandled Tentativa de leitura ou gravação em memória protegida. Normalmente, isso é uma indicação de que outra memória está danificada. Segue o código-fonte: void Orientacao(Bitmap imagem, ArrayList objetos, int qt_objetos, double raio) { int i,j; int classificacao; double raio_temp1,raio_temp2; Posicao ponto = new Posicao(); Bitmap image = (Bitmap)imagem.Clone(); BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* ptr = (byte*)(data.Scan0); Int32 pix; for (i = 0; i < qt_objetos; i++) { if (((Objeto)objetos[i]).rotulo == 0) { for (j = 0; j < 90; j++) { raio_temp2 = j * 4 * 0.01745; raio_temp1 = Math.Cos(raio_temp2); raio_temp2 = Math.Sin(raio_temp2); if ((((Objeto)objetos[i]).ponto.x + (int)(raio * raio_temp1)) < data.Height && (((Objeto)objetos[i]).ponto.x + (int)(raio * raio_temp1)) > 0 && 3 * (((Objeto)objetos[i]).ponto.y + (int)(raio * raio_temp2)) < data.Width && 3 * (((Objeto)objetos[i]).ponto.y + (int)(raio * raio_temp2)) > 0) { pix = ((((Objeto)objetos[i]).ponto.x + (int)(raio * raio_temp1)) * data.Stride + 3 * (((Objeto)objetos[i]).ponto.y + (int)(raio * raio_temp2))); classificacao = ClassificarMLP(ptr[pix + 2], ptr[pix + 1], ptr[pix]); if (classificacao > -1) //ciano, rosa ou ver { j += 3; raio_temp2 = j * 4 * 0.01745; raio_temp1 = Math.Cos(raio_temp2); raio_temp2 = Math.Sin(raio_temp2); pix = ((((Objeto)objetos[i]).ponto.x + (int)(raio * raio_temp1)) * data.Stride + 3 * (((Objeto)objetos[i]).ponto.y + (int)(raio * raio_temp2))); classificacao = ClassificarMLP(ptr[pix + 2], ptr[pix + 1], ptr[pix]); ponto.x = ((Objeto)objetos[i]).ponto.x + (int)(raio * raio_temp1); ponto.y = ((Objeto)objetos[i]).ponto.y + (int)(raio * raio_temp2); if (classificacao > -1) { ponto = CentroideNovo(ponto, image, 1); j += 20; switch (classificacao) { case 0: //((Objeto)objetos[i]).ponto.ang = ((Objeto)objetos[i]).ponto.Angulo(ponto); //ciano break; case 1: ((Objeto)objetos[i]).ponto.ang = ((Objeto)objetos[i]).ponto.Angulo(ponto);//ImagemProcessada->Picture->Bitmap->Canvas->Brush->Color=(TColor)16744703; //rosa break; case 2: //((Objeto)objetos[i]).ponto.ang = ((Objeto)objetos[i]).ponto.Angulo(ponto); //verde break; } } } } else { j++; } } } } } image.UnlockBits(data); }
  5. Como faço para imprimir o valor de uma variável em alguma toolbox usando o visual c++ ?! pode ser textbox, tanto faz...
  6. Como faço para imprimir o valor de uma variável em alguma toolbox usando o visual c++ ?! pode ser textbox, tanto faz...
  7. CÓDIGO DENTRO DE [b]ARQUIVO Form1.h:[/b] ----------------------------------------------------- [code] #pragma once #include "elementos.h" namespace path { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace CLRSketcher; enum class ElementType{robo, obstaculo, objetivo}; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) : drawing(false) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::RadioButton^ radioButton1; protected: private: System::Windows::Forms::RadioButton^ radioButton2; private: System::Windows::Forms::RadioButton^ radioButton3; private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; // Current element type ElementType elementType; // Current drawing color //Color color; // Records when drawing an element is in progress bool drawing; // Temporary store for the element being drawn Element^ tempRobo; Element^ tempObjetivo; private: System::Windows::Forms::Button^ button1; Element^ tempObstaculo; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); this->button1 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // radioButton1 // this->radioButton1->AutoSize = true; this->radioButton1->Location = System::Drawing::Point(12, 237); this->radioButton1->Name = L"radioButton1"; this->radioButton1->Size = System::Drawing::Size(46, 17); this->radioButton1->TabIndex = 0; this->radioButton1->TabStop = true; this->radioButton1->Text = L"robo"; this->radioButton1->UseVisualStyleBackColor = true; this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged); // // radioButton2 // this->radioButton2->AutoSize = true; this->radioButton2->Location = System::Drawing::Point(64, 237); this->radioButton2->Name = L"radioButton2"; this->radioButton2->Size = System::Drawing::Size(71, 17); this->radioButton2->TabIndex = 1; this->radioButton2->TabStop = true; this->radioButton2->Text = L"obstaculo"; this->radioButton2->UseVisualStyleBackColor = true; this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton2_CheckedChanged); // // radioButton3 // this->radioButton3->AutoSize = true; this->radioButton3->Location = System::Drawing::Point(141, 237); this->radioButton3->Name = L"radioButton3"; this->radioButton3->Size = System::Drawing::Size(62, 17); this->radioButton3->TabIndex = 2; this->radioButton3->TabStop = true; this->radioButton3->Text = L"objetivo"; this->radioButton3->UseVisualStyleBackColor = true; this->radioButton3->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton3_CheckedChanged); // // button1 // this->button1->Location = System::Drawing::Point(210, 237); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 3; this->button1->Text = L"trajetoria"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(746, 266); this->Controls->Add(this->button1); this->Controls->Add(this->radioButton3); this->Controls->Add(this->radioButton2); this->Controls->Add(this->radioButton1); this->Name = L"Form1"; this->Text = L"trajetoria"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::robo; } private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::obstaculo; } private: System::Void radioButton3_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::objetivo; } private: System::Void button1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Graphics^ g = e->Graphics; if(tempRobo) tempRobo->Draw(g); if(tempObjetivo) tempObjetivo->Draw(g); if(tempObstaculo) tempObstaculo->Draw(g); } private: System::Void button1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if(e->Button == System::Windows::Forms::MouseButtons::Left) drawing = true; if(drawing) { switch(elementType) { case ElementType::robo: tempRobo = gcnew CLRSketcher::Rectangle(Color::Red, e->Location); break; case ElementType::obstaculo: tempObstaculo = gcnew CLRSketcher::Rectangle(Color::Green, e->Location); break; case ElementType::objetivo: tempObjetivo = gcnew CLRSketcher::Rectangle(Color::Blue, e->Location); break; } Invalidate(); } } private: System::Void button1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { drawing = false; } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { } }; } ARQUIVO elementos.h: --------------------------------------------------------------------- // elementos.h // Defines element types #pragma once using namespace System; using namespace System::Drawing; namespace CLRSketcher { // The base class for all elements public ref class Element abstract { protected: Point position; Color color; System::Drawing::Rectangle boundRect; Pen^ pen; public: virtual void Draw(Graphics^ g) abstract; }; // The class defining a line element public ref class Line : Element { protected: Point end; public: // Constructor Line(Color color, Point start, Point end) { pen = gcnew Pen(color); this->color = color; position = start; this->end = end; boundRect = System::Drawing::Rectangle(Math::Min(position.X, end.X), Math::Min(position.Y, end.Y), Math::Abs(position.X - end.X), Math::Abs(position.Y - end.Y)); // Provide for lines that are horizontal or vertical if(boundRect.Width < 2) boundRect.Width = 2; if(boundRect.Height < 2) boundRect.Height = 2; } // Function to draw a line virtual void Draw(Graphics^ g) override { g->DrawLine(pen, position, end); } }; // The class defining a rectangle element public ref class Rectangle : Element { protected: public: Rectangle(Color color, Point p1) { pen = gcnew Pen(color); this->color = color; position = p1; boundRect = System::Drawing::Rectangle(position, Size(20, 20)); } virtual void Draw(Graphics^ g) override { g->DrawRectangle(pen, position.X-10, position.Y-10, 20, 20); } }; // The class defining a circle element public ref class Circle : Element { protected: int width; int height; public: Circle(Color color, Point center, Point circum) { pen = gcnew Pen(color); this->color = color; int radius = safe_cast<int>(Math::Sqrt( (center.X-circum.X)*(center.X-circum.X) + (center.Y-circum.Y)*(center.Y-circum.Y))); position = Point(center.X - radius, center.Y - radius); width = height = 2*radius; boundRect = System::Drawing::Rectangle(position, Size(width, height)); } virtual void Draw(Graphics^ g) override { g->DrawEllipse(pen, position.X, position.Y, width,height); } }; }
  8. Estou tentando fazer um programa para desenhar com o mouse (dando só um clique) em uma janela windows form usando o visual c++, mas não está funcionando quando clico não desenha... ARQUIVO Form1.h: ----------------------------------------------------- #pragma once #include "elementos.h" namespace path { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace CLRSketcher; enum class ElementType{robo, obstaculo, objetivo}; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) : drawing(false) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::RadioButton^ radioButton1; protected: private: System::Windows::Forms::RadioButton^ radioButton2; private: System::Windows::Forms::RadioButton^ radioButton3; private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; // Current element type ElementType elementType; // Current drawing color //Color color; // Records when drawing an element is in progress bool drawing; // Temporary store for the element being drawn Element^ tempRobo; Element^ tempObjetivo; private: System::Windows::Forms::Button^ button1; Element^ tempObstaculo; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); this->button1 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // radioButton1 // this->radioButton1->AutoSize = true; this->radioButton1->Location = System::Drawing::Point(12, 237); this->radioButton1->Name = L"radioButton1"; this->radioButton1->Size = System::Drawing::Size(46, 17); this->radioButton1->TabIndex = 0; this->radioButton1->TabStop = true; this->radioButton1->Text = L"robo"; this->radioButton1->UseVisualStyleBackColor = true; this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged); // // radioButton2 // this->radioButton2->AutoSize = true; this->radioButton2->Location = System::Drawing::Point(64, 237); this->radioButton2->Name = L"radioButton2"; this->radioButton2->Size = System::Drawing::Size(71, 17); this->radioButton2->TabIndex = 1; this->radioButton2->TabStop = true; this->radioButton2->Text = L"obstaculo"; this->radioButton2->UseVisualStyleBackColor = true; this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton2_CheckedChanged); // // radioButton3 // this->radioButton3->AutoSize = true; this->radioButton3->Location = System::Drawing::Point(141, 237); this->radioButton3->Name = L"radioButton3"; this->radioButton3->Size = System::Drawing::Size(62, 17); this->radioButton3->TabIndex = 2; this->radioButton3->TabStop = true; this->radioButton3->Text = L"objetivo"; this->radioButton3->UseVisualStyleBackColor = true; this->radioButton3->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton3_CheckedChanged); // // button1 // this->button1->Location = System::Drawing::Point(210, 237); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 3; this->button1->Text = L"trajetoria"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(746, 266); this->Controls->Add(this->button1); this->Controls->Add(this->radioButton3); this->Controls->Add(this->radioButton2); this->Controls->Add(this->radioButton1); this->Name = L"Form1"; this->Text = L"trajetoria"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::robo; } private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::obstaculo; } private: System::Void radioButton3_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::objetivo; } private: System::Void button1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Graphics^ g = e->Graphics; if(tempRobo) tempRobo->Draw(g); if(tempObjetivo) tempObjetivo->Draw(g); if(tempObstaculo) tempObstaculo->Draw(g); } private: System::Void button1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if(e->Button == System::Windows::Forms::MouseButtons::Left) drawing = true; if(drawing) { switch(elementType) { case ElementType::robo: tempRobo = gcnew CLRSketcher::Rectangle(Color::Red, e->Location); break; case ElementType::obstaculo: tempObstaculo = gcnew CLRSketcher::Rectangle(Color::Green, e->Location); break; case ElementType::objetivo: tempObjetivo = gcnew CLRSketcher::Rectangle(Color::Blue, e->Location); break; } Invalidate(); } } private: System::Void button1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { drawing = false; } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { } }; } ARQUIVO elementos.h: --------------------------------------------------------------------- // elementos.h // Defines element types #pragma once using namespace System; using namespace System::Drawing; namespace CLRSketcher { // The base class for all elements public ref class Element abstract { protected: Point position; Color color; System::Drawing::Rectangle boundRect; Pen^ pen; public: virtual void Draw(Graphics^ g) abstract; }; // The class defining a line element public ref class Line : Element { protected: Point end; public: // Constructor Line(Color color, Point start, Point end) { pen = gcnew Pen(color); this->color = color; position = start; this->end = end; boundRect = System::Drawing::Rectangle(Math::Min(position.X, end.X), Math::Min(position.Y, end.Y), Math::Abs(position.X - end.X), Math::Abs(position.Y - end.Y)); // Provide for lines that are horizontal or vertical if(boundRect.Width < 2) boundRect.Width = 2; if(boundRect.Height < 2) boundRect.Height = 2; } // Function to draw a line virtual void Draw(Graphics^ g) override { g->DrawLine(pen, position, end); } }; // The class defining a rectangle element public ref class Rectangle : Element { protected: public: Rectangle(Color color, Point p1) { pen = gcnew Pen(color); this->color = color; position = p1; boundRect = System::Drawing::Rectangle(position, Size(20, 20)); } virtual void Draw(Graphics^ g) override { g->DrawRectangle(pen, position.X-10, position.Y-10, 20, 20); } }; // The class defining a circle element public ref class Circle : Element { protected: int width; int height; public: Circle(Color color, Point center, Point circum) { pen = gcnew Pen(color); this->color = color; int radius = safe_cast<int>(Math::Sqrt( (center.X-circum.X)*(center.X-circum.X) + (center.Y-circum.Y)*(center.Y-circum.Y))); position = Point(center.X - radius, center.Y - radius); width = height = 2*radius; boundRect = System::Drawing::Rectangle(position, Size(width, height)); } virtual void Draw(Graphics^ g) override { g->DrawEllipse(pen, position.X, position.Y, width,height); } }; }
  9. Estou tentando fazer um programa para desenhar com o mouse (dando só um clique) em uma janela windows form usando o visual c++, mas não está funcionando quando clico não desenha... ARQUIVO Form1.h: ----------------------------------------------------- #pragma once #include "elementos.h" namespace path { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace CLRSketcher; enum class ElementType{robo, obstaculo, objetivo}; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) : drawing(false) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::RadioButton^ radioButton1; protected: private: System::Windows::Forms::RadioButton^ radioButton2; private: System::Windows::Forms::RadioButton^ radioButton3; private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; // Current element type ElementType elementType; // Current drawing color //Color color; // Records when drawing an element is in progress bool drawing; // Temporary store for the element being drawn Element^ tempRobo; Element^ tempObjetivo; private: System::Windows::Forms::Button^ button1; Element^ tempObstaculo; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); this->button1 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // radioButton1 // this->radioButton1->AutoSize = true; this->radioButton1->Location = System::Drawing::Point(12, 237); this->radioButton1->Name = L"radioButton1"; this->radioButton1->Size = System::Drawing::Size(46, 17); this->radioButton1->TabIndex = 0; this->radioButton1->TabStop = true; this->radioButton1->Text = L"robo"; this->radioButton1->UseVisualStyleBackColor = true; this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged); // // radioButton2 // this->radioButton2->AutoSize = true; this->radioButton2->Location = System::Drawing::Point(64, 237); this->radioButton2->Name = L"radioButton2"; this->radioButton2->Size = System::Drawing::Size(71, 17); this->radioButton2->TabIndex = 1; this->radioButton2->TabStop = true; this->radioButton2->Text = L"obstaculo"; this->radioButton2->UseVisualStyleBackColor = true; this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton2_CheckedChanged); // // radioButton3 // this->radioButton3->AutoSize = true; this->radioButton3->Location = System::Drawing::Point(141, 237); this->radioButton3->Name = L"radioButton3"; this->radioButton3->Size = System::Drawing::Size(62, 17); this->radioButton3->TabIndex = 2; this->radioButton3->TabStop = true; this->radioButton3->Text = L"objetivo"; this->radioButton3->UseVisualStyleBackColor = true; this->radioButton3->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton3_CheckedChanged); // // button1 // this->button1->Location = System::Drawing::Point(210, 237); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 3; this->button1->Text = L"trajetoria"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click_1); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(746, 266); this->Controls->Add(this->button1); this->Controls->Add(this->radioButton3); this->Controls->Add(this->radioButton2); this->Controls->Add(this->radioButton1); this->Name = L"Form1"; this->Text = L"trajetoria"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::robo; } private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::obstaculo; } private: System::Void radioButton3_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { elementType = ElementType::objetivo; } private: System::Void button1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Graphics^ g = e->Graphics; if(tempRobo) tempRobo->Draw(g); if(tempObjetivo) tempObjetivo->Draw(g); if(tempObstaculo) tempObstaculo->Draw(g); } private: System::Void button1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if(e->Button == System::Windows::Forms::MouseButtons::Left) drawing = true; if(drawing) { switch(elementType) { case ElementType::robo: tempRobo = gcnew CLRSketcher::Rectangle(Color::Red, e->Location); break; case ElementType::obstaculo: tempObstaculo = gcnew CLRSketcher::Rectangle(Color::Green, e->Location); break; case ElementType::objetivo: tempObjetivo = gcnew CLRSketcher::Rectangle(Color::Blue, e->Location); break; } Invalidate(); } } private: System::Void button1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { drawing = false; } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { } }; } ARQUIVO elementos.h: --------------------------------------------------------------------- // elementos.h // Defines element types #pragma once using namespace System; using namespace System::Drawing; namespace CLRSketcher { // The base class for all elements public ref class Element abstract { protected: Point position; Color color; System::Drawing::Rectangle boundRect; Pen^ pen; public: virtual void Draw(Graphics^ g) abstract; }; // The class defining a line element public ref class Line : Element { protected: Point end; public: // Constructor Line(Color color, Point start, Point end) { pen = gcnew Pen(color); this->color = color; position = start; this->end = end; boundRect = System::Drawing::Rectangle(Math::Min(position.X, end.X), Math::Min(position.Y, end.Y), Math::Abs(position.X - end.X), Math::Abs(position.Y - end.Y)); // Provide for lines that are horizontal or vertical if(boundRect.Width < 2) boundRect.Width = 2; if(boundRect.Height < 2) boundRect.Height = 2; } // Function to draw a line virtual void Draw(Graphics^ g) override { g->DrawLine(pen, position, end); } }; // The class defining a rectangle element public ref class Rectangle : Element { protected: public: Rectangle(Color color, Point p1) { pen = gcnew Pen(color); this->color = color; position = p1; boundRect = System::Drawing::Rectangle(position, Size(20, 20)); } virtual void Draw(Graphics^ g) override { g->DrawRectangle(pen, position.X-10, position.Y-10, 20, 20); } }; // The class defining a circle element public ref class Circle : Element { protected: int width; int height; public: Circle(Color color, Point center, Point circum) { pen = gcnew Pen(color); this->color = color; int radius = safe_cast<int>(Math::Sqrt( (center.X-circum.X)*(center.X-circum.X) + (center.Y-circum.Y)*(center.Y-circum.Y))); position = Point(center.X - radius, center.Y - radius); width = height = 2*radius; boundRect = System::Drawing::Rectangle(position, Size(width, height)); } virtual void Draw(Graphics^ g) override { g->DrawEllipse(pen, position.X, position.Y, width,height); } }; }
  10. consegui resolver o problema era : Onde tinha : private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { //if (video == nullptr) SAASCapturaNS::SAASCaptura^ video = (gcnew SAASCapturaNS::SAASCaptura()); button2->Enabled = true; button1->Enabled = false; Era pra ser : private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { //if (video == nullptr) video = (gcnew SAASCapturaNS::SAASCaptura()); button2->Enabled = true; button1->Enabled = false;
  11. Estou tentando fazer um programa que exibe em um picturebox os frames capturados por uma webcam, essa biblioteca SAASCapturaNS é que tem as funções de captura, mas o problema do programa está no uso da System::Windows::Forms::Timer, porque já consigo capturar uma única imagem, mas quando tento capturar uma sequencia usando o timer não dá certo. CÓDIGO: #pragma once namespace webcam { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace SAASCapturaNS; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { SAASCapturaNS::SAASCaptura^ video; public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::PictureBox^ pictureBox1; protected: private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::Timer^ timer1; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Required designer variable. /// </summary> #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); this->SuspendLayout(); // // pictureBox1 // this->pictureBox1->Location = System::Drawing::Point(12, 12); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(758, 450); this->pictureBox1->TabIndex = 0; this->pictureBox1->TabStop = false; this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click); // // button1 // this->button1->Location = System::Drawing::Point(12, 468); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 1; this->button1->Text = L"Iniciar"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(93, 468); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(75, 23); this->button2->TabIndex = 2; this->button2->Text = L"Parar"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button3 // this->button3->Location = System::Drawing::Point(174, 468); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(75, 23); this->button3->TabIndex = 3; this->button3->Text = L"button3"; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); // // timer1 // this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(782, 503); this->Controls->Add(this->button3); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->pictureBox1); this->Name = L"Form1"; this->Text = L"Webcam"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); this->ResumeLayout(false); } #pragma endregion private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { //if (video == nullptr) SAASCapturaNS::SAASCaptura^ video = (gcnew SAASCapturaNS::SAASCaptura()); button2->Enabled = true; button1->Enabled = false; video->Inicializar_Webcam(); pictureBox1->Image = video->GetFrame(); this->timer1->Enabled = true; this->timer1->Interval = 33; this->timer1->Start(); } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { button2->Enabled = false; button1->Enabled = true; video->Finalizar(); pictureBox1->Image = nullptr; this->timer1->Stop(); } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Bitmap^ frame = video->GetFrame(); pictureBox1->Image=frame; } }; }
×
×
  • Criar Novo...