Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unable to link opencv to windows form application

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error 1 error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc Error 2 error C3861: 'cvLoadImage': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc

click to hide/show revision 2
retagged

updated 2013-10-15 02:36:37 -0600

berak gravatar image

Unable to link opencv to windows form application

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error 1 error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc Error 2 error C3861: 'cvLoadImage': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc

Unable to link opencv to windows form application

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error 1 error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc Error 2 error C3861: 'cvLoadImage': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc

pragma once

include "highgui.h"

include <opencv2 imgproc="" imgproc.hpp=""> // Gaussian Blur

include <opencv2 core="" core.hpp=""> // Basic OpenCV structures (cv::Mat, Scalar)

include <opencv2 highgui="" highgui.hpp="">

namespace abc {

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 System::IO;


/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
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::Button^  button1;
private: System::Windows::Forms::TextBox^  path;
private: System::Windows::Forms::Button^  summary;
protected: 


    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

    #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->button1 = (gcnew System::Windows::Forms::Button());
        this->path = (gcnew System::Windows::Forms::TextBox());
        this->summary = (gcnew System::Windows::Forms::Button());
        this->SuspendLayout();
        // 
        // button1
        // 
        this->button1->Location = System::Drawing::Point(392, 68);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(75, 23);
        this->button1->TabIndex = 0;
        this->button1->Text = L"browse";
        this->button1->UseVisualStyleBackColor = true;
        this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
        // 
        // path
        // 
        this->path->Location = System::Drawing::Point(23, 68);
        this->path->Name = L"path";
        this->path->Size = System::Drawing::Size(304, 20);
        this->path->TabIndex = 1;
        // 
        // summary
        // 
        this->summary->Location = System::Drawing::Point(153, 156);
        this->summary->Name = L"summary";
        this->summary->Size = System::Drawing::Size(159, 27);
        this->summary->TabIndex = 2;
        this->summary->Text = L"summaize video";
        this->summary->UseVisualStyleBackColor = true;
        this->summary->Click += gcnew System::EventHandler(this, &Form1::summary_Click);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(568, 262);
        this->Controls->Add(this->summary);
        this->Controls->Add(this->path);
        this->Controls->Add(this->button1);
        this->Name = L"Form1";
        this->Text = L"Form1";
        this->ResumeLayout(false);
        this->PerformLayout();

    }

pragma endregion

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    Stream^ myStream;
    OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

    openFileDialog1->InitialDirectory = "c:\\";
    openFileDialog1->Filter = "txt files (*.avi)|*.avi|All files (*.*)|*.*";
    openFileDialog1->FilterIndex = 2;
    openFileDialog1->RestoreDirectory = true;

    if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
    {
        if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
        {
            path->Text = Convert::ToString(openFileDialog1->FileName);

            // Insert code to read the stream here.
            String ^ temp = "you have successfully browsed a video";
            System::Windows::Forms::MessageBox::Show(temp);

            myStream->Close();
        }
    }
}

private: System::Void summary_Click(System::Object^ sender, System::EventArgs^ e) { // Set up images IplImage* img = cvLoadImage("MGC.jpg"); IplImage* back_img = cvCreateImage( cvGetSize( img ), IPL_DEPTH_8U, 1 );

// Compute HSV image and separate into colors
IplImage* hsv = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
cv:cvCvtColor( img, hsv, CV_BGR2HSV );

IplImage* h_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
IplImage* s_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
IplImage* v_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
IplImage* planes[] = { h_plane, s_plane };
cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );

// Build and fill the histogram
int h_bins = 30, s_bins = 32;
CvHistogram* hist;
{
    int hist_size[] = { h_bins, s_bins };
    float h_ranges[] = { 0, 180 };
    float s_ranges[] = { 0, 255 };
    float* ranges[] = { h_ranges, s_ranges };
    hist = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
}
cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
cvNormalizeHist( hist, 20*255 ); // Normalize it

cvCalcBackProject( planes, back_img, hist );// Calculate back projection
cvNormalizeHist( hist, 1.0 ); // Normalize it



// Create an image to visualize the histogram
int scale = 10;
IplImage* hist_img = cvCreateImage( cvSize( h_bins * scale, s_bins * scale ), 8, 3 );
cvZero ( hist_img );

// populate the visualization
float max_value = 0;
cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );

for( int h = 0; h < h_bins; h++ ){
    for( int s = 0; s < s_bins; s++ ){
        float bin_val = cvQueryHistValue_2D( hist, h, s );
        int intensity = cvRound( bin_val * 255 / max_value );
        cvRectangle( hist_img, cvPoint( h*scale, s*scale ),
                    cvPoint( (h+1)*scale - 1, (s+1)*scale - 1 ),
                    CV_RGB( intensity, intensity, intensity ),
                    CV_FILLED );
    }
}

// Show original
cvNamedWindow( "Source", 1) ;
cvShowImage( "Source", img );

// Show back projection
cvNamedWindow( "Back Projection", 1) ;
cvShowImage( "Back Projection", back_img );

// Show histogram equalized
cvNamedWindow( "H-S Histogram", 1) ;
cvShowImage( "H-S Histogram", hist_img );

cvWaitKey(0);

cvReleaseImage( &img );
cvReleaseImage( &back_img );
cvReleaseImage( &hist_img );

     }

}; }

click to hide/show revision 4
hi there ;) the "101010" button helps to format code !

updated 2013-10-16 05:00:53 -0600

berak gravatar image

Unable to link opencv to windows form application

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error 1 error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc
Error 2 error C3861: 'cvLoadImage': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 130 1 abc

pragma once

include "highgui.h"

include <opencv2 imgproc="" imgproc.hpp=""> abc #pragma once #include "highgui.h" #include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur

include <opencv2 core="" core.hpp=""> Blur #include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)

include <opencv2 highgui="" highgui.hpp="">

Scalar) #include <opencv2/highgui/highgui.hpp> namespace abc {

{
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 System::IO;
 /// <summary>
 /// Summary for Form1
 /// </summary>
 public ref class Form1 : public System::Windows::Forms::Form
 {
 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::Button^ button1;
 private: System::Windows::Forms::TextBox^ path;
 private: System::Windows::Forms::Button^ summary;
 protected:
 private:
  /// <summary>
  /// Required designer variable.
 /// </summary>
 System::ComponentModel::Container ^components;
  #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->button1 = (gcnew System::Windows::Forms::Button());
 this->path = (gcnew System::Windows::Forms::TextBox());
 this->summary = (gcnew System::Windows::Forms::Button());
 this->SuspendLayout();
//
 //
 // button1
//
 //
 this->button1->Location = System::Drawing::Point(392, 68);
 this->button1->Name = L"button1";
  this->button1->Size = System::Drawing::Size(75, 23);
 this->button1->TabIndex = 0;
 this->button1->Text = L"browse";
 this->button1->UseVisualStyleBackColor = true;
  this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
 //
 // path
//
 //
 this->path->Location = System::Drawing::Point(23, 68);
 this->path->Name = L"path";
  this->path->Size = System::Drawing::Size(304, 20);
 this->path->TabIndex = 1;
//
 //
 // summary
//
 //
 this->summary->Location = System::Drawing::Point(153, 156);
 this->summary->Name = L"summary";
  this->summary->Size = System::Drawing::Size(159, 27);
 this->summary->TabIndex = 2;
  this->summary->Text = L"summaize video";
 this->summary->UseVisualStyleBackColor = true;
  this->summary->Click += gcnew System::EventHandler(this, &Form1::summary_Click);
//
 //
 // Form1
//
 //
 this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  this->ClientSize = System::Drawing::Size(568, 262);
 this->Controls->Add(this->summary);
 this->Controls->Add(this->path);
 this->Controls->Add(this->button1);
 this->Name = L"Form1";
 this->Text = L"Form1";
 this->ResumeLayout(false);
 this->PerformLayout();
 }

pragma endregion

#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
 Stream^ myStream;
 OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
 openFileDialog1->InitialDirectory = "c:\\";
  openFileDialog1->Filter = "txt files (*.avi)|*.avi|All files (*.*)|*.*";
 openFileDialog1->FilterIndex = 2;
 openFileDialog1->RestoreDirectory = true;
  if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
 {
  if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
 {
 path->Text = Convert::ToString(openFileDialog1->FileName);
  // Insert code to read the stream here.
 String ^ temp = "you have successfully browsed a video";
 System::Windows::Forms::MessageBox::Show(temp);
 myStream->Close();
 }
 }
 }

private: System::Void summary_Click(System::Object^ sender, System::EventArgs^ e) { // Set up images IplImage* img = cvLoadImage("MGC.jpg"); IplImage* back_img = cvCreateImage( cvGetSize( img ), IPL_DEPTH_8U, 1 );

);
// Compute HSV image and separate into colors
 IplImage* hsv = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
 cv:cvCvtColor( img, hsv, CV_BGR2HSV );
 IplImage* h_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
 IplImage* s_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
 IplImage* v_plane = cv::cvCreateImage( cvGetSize( img ), 8, 1 );
 IplImage* planes[] = { h_plane, s_plane };
 cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
 // Build and fill the histogram
 int h_bins = 30, s_bins = 32;
 CvHistogram* hist;
 {
  int hist_size[] = { h_bins, s_bins };
 float h_ranges[] = { 0, 180 };
 float s_ranges[] = { 0, 255 };
 float* ranges[] = { h_ranges, s_ranges };
  hist = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
 }
 cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
 cvNormalizeHist( hist, 20*255 ); // Normalize it
 cvCalcBackProject( planes, back_img, hist );// Calculate back projection
 cvNormalizeHist( hist, 1.0 ); // Normalize it
 // Create an image to visualize the histogram
 int scale = 10;
 IplImage* hist_img = cvCreateImage( cvSize( h_bins * scale, s_bins * scale ), 8, 3 );
 cvZero ( hist_img );
 // populate the visualization
 float max_value = 0;
 cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
 for( int h = 0; h < h_bins; h++ ){
 for( int s = 0; s < s_bins; s++ ){
 float bin_val = cvQueryHistValue_2D( hist, h, s );
  int intensity = cvRound( bin_val * 255 / max_value );
 cvRectangle( hist_img, cvPoint( h*scale, s*scale ),
  cvPoint( (h+1)*scale - 1, (s+1)*scale - 1 ),
 CV_RGB( intensity, intensity, intensity ),
 CV_FILLED );
 }
 }
 // Show original
 cvNamedWindow( "Source", 1) ;
 cvShowImage( "Source", img );
 // Show back projection
 cvNamedWindow( "Back Projection", 1) ;
 cvShowImage( "Back Projection", back_img );
 // Show histogram equalized
 cvNamedWindow( "H-S Histogram", 1) ;
 cvShowImage( "H-S Histogram", hist_img );
 cvWaitKey(0);
 cvReleaseImage( &img );
 cvReleaseImage( &back_img );
 cvReleaseImage( &hist_img );
 }
};
}

}; }