Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

_CrtlsValidHeapPointer(block) error when using opencv in c++ winforms application

Dear All,

I am trying to use opencv with windows forms application to display an image. I created two extra classes. one as the model and other as the controller class. I imported opencv libraries in the model class, imported the modal class in the controller class and then the controller class in form.h. see code below` Model class

#include "opencv2\core\core.hpp";
#include "opencv2\imgproc\imgproc.hpp";
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
class ReadImage
{
   private:
      cv::String imagepath;
      Mat Image;
   public:
      ReadImage() :imagepath("C:/") {
      ReadImage4rmfile();
}
void ReadImage4rmfile() {
    Image = imread(imagepath);
}
void setImagepath(cv::String mpath) {
    imagepath = mpath;
}
void ShowImage() {
    imshow("ShowImage", Image);
}

};

Controller class:

en#include "ReadImage.hpp"

   class ImageController
   {
        private:
          ReadImage* rimage;
        public:
          ImageController(cv::String mpath) {
      rimage =  new ReadImage();
      rimage->setImagepath(mpath);
}
void ImconShowImage() {
    rimage->ShowImage();
}
~ImageController() {
    delete rimage;
}

};

forms.h class:

#include "ImageController.hpp"
   private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    System::String^ temp = textBox1->Text;
    IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(temp);
    const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());

    ImageController Imgcon = ImageController(input_location);
    Imgcon.ImconShowImage();

}

When i run the app i get the following error "Debug failed _CrtlsValidHeapPointer(block)" image description

please anyone can help.

_CrtlsValidHeapPointer(block) error when using opencv in c++ winforms application

Dear All,

I am trying to use opencv with windows forms application to display an image. I created two extra classes. one as the model and other as the controller class. I imported opencv libraries in the model class, imported the modal class in the controller class and then the controller class in form.h. see code below` Model class

#include "opencv2\core\core.hpp";
#include "opencv2\imgproc\imgproc.hpp";
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
class ReadImage
{
   private:
      cv::String imagepath;
      Mat Image;
   public:
      ReadImage() :imagepath("C:/") {
      ReadImage4rmfile();
}
void ReadImage4rmfile() {
    Image = imread(imagepath);
}
void setImagepath(cv::String mpath) {
    imagepath = mpath;
}
void ShowImage() {
    imshow("ShowImage", Image);
}

};

Controller class:

en#include "ReadImage.hpp"

   class ImageController
   {
        private:
          ReadImage* rimage;
        public:
          ImageController(cv::String mpath) {
      rimage =  new ReadImage();
      rimage->setImagepath(mpath);
}
void ImconShowImage() {
    rimage->ShowImage();
}
~ImageController() {
    delete rimage;
}

};

forms.h class:

#include "ImageController.hpp"
   private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    System::String^ temp = textBox1->Text;
    IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(temp);
    const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());

    ImageController Imgcon = ImageController(input_location);
    Imgcon.ImconShowImage();

}

When i run the app i get the following error "Debug failed _CrtlsValidHeapPointer(block)" image description

The funny thing is the opencv settings such as the linker input and the likes was used on console application and it works well and using it winforms am getting this error.

please anyone can help.

_CrtlsValidHeapPointer(block) error when using opencv in c++ winforms application

Dear All,

I am trying to use opencv with windows forms application to display an image. I created two extra classes. one as the model and other as the controller class. I imported opencv libraries in the model class, imported the modal class in the controller class and then the controller class in form.h. see code below` Model class

#include "opencv2\core\core.hpp";
#include "opencv2\imgproc\imgproc.hpp";
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
class ReadImage
{
   private:
      cv::String imagepath;
      Mat Image;
   public:
      ReadImage() :imagepath("C:/") {
       ReadImage4rmfile();
}
      }
      void ReadImage4rmfile() {
     Image = imread(imagepath);
}
      }
      void setImagepath(cv::String mpath) {
     imagepath = mpath;
}
      }
      void ShowImage() {
     imshow("ShowImage", Image);
}
      }
};

};

Controller class:

en#include #include "ReadImage.hpp"

   class ImageController
   {
        private:
          ReadImage* rimage;
        public:
          ImageController(cv::String mpath) {
       rimage =  new ReadImage();
       rimage->setImagepath(mpath);
}
          }
          void ImconShowImage() {
     rimage->ShowImage();
}
          }
          ~ImageController() {
     delete rimage;
}
         }

 };

};

forms.h class:

#include "ImageController.hpp"
   private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    System::String^ temp = textBox1->Text;
    IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(temp);
    const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());

    ImageController Imgcon = ImageController(input_location);
    Imgcon.ImconShowImage();

}

When i run the app i get the following error "Debug failed _CrtlsValidHeapPointer(block)" image description

The funny thing is the opencv settings such as the linker input and the likes was used on console application and it works well and using it winforms am getting this error.

please anyone can help.