Ask Your Question
6

Visual Studio 2012 and RtlFreeHeap error

asked 2013-01-25 10:51:13 -0600

Maurizio Lo Bosco gravatar image

HI All, I have a small issue with VS2012 and the memory clean up. I'm able to get frames from my webcam and apply some filters like Canny, so the installation should be fine, but when I try to use the HoughLinesP I got an exception at the end of the program stating

HEAP[OpenCVTest01.exe]: Invalid address specified to RtlFreeHeap( 00000000003E0000, 00000000027A8080 )
OpenCVTest01.exe has triggered a breakpoint.

I have googled and this error seams to be related to a discrepancy between the CRL used to build the openCV and my program, but using the dumpbin, it doesn't seam to be the case, they are both using the multi-threaded version.

that's the code I'm executing

#include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
int _tmain(int, char**)
{
  VideoCapture cap(1); // my webcam is not at zero
  if(!cap.isOpened()) return -1;

  Mat frame, edges;
  vector<Vec4i> lines;
  namedWindow("Frame",1);

  for(;;)
  {
    cap >> frame;
    cvtColor(frame, edges, CV_BGR2GRAY);

    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);

    HoughLinesP(edges, lines, 1, CV_PI/180, 50, 50, 10 );
    imshow("Frame", frame);
    if(waitKey(30) >= 0) break;
  }
  return 0;
}

the exception is thrown after the for loop during the cleanup process. If I comment the HoughLinesP call, everything is working fine.

Can some please point me in the right direction?

Thanks.

edit retag flag offensive close merge delete

6 answers

Sort by ยป oldest newest most voted
10

answered 2013-01-28 19:02:52 -0600

Hongbo Miao gravatar image

updated 2013-03-04 07:17:14 -0600

Note: This is a tutorial for using OpenCV 2.44 and OpenCV 2.43 in Vsiual Studio 2012. If you use old OpenCV 2.43, please skip over the part for OpenCV 2.44.

Using OpenCV 2.44 in Vsiual Studio 2012


First

Open Windows Explorer. Click on Computer and then System properties.

image description

Choose Advanced system settings.

image description

Click Environment Variables...

image description

Add only this to Environment Variables -> System variables -> Path

C:\OpenCV\build\x64\vc11\bin

image description

image description


Second

After creating your own project in Visual Studio 2012...

Build menu -> Configuration Manager

Change the Active solution platform. Click on Win32, Select New.... Use the settings below and click OK.

image description


Third

For Release:

View -> Property Manager

Double click Release | x64

  1. C/C++ -> General -> Additional Include Directories

C:\OpenCV\build\include\opencv

C:\OpenCV\build\include

  1. Linker -> General -> Additional Library Directories

C:\OpenCV\build\x64\vc11\lib

  • Linker -> Input -> Additional Dependencies

opencv_calib3d244.lib

opencv_contrib244.lib

opencv_core244.lib

opencv_features2d244.lib

opencv_flann244.lib

opencv_gpu244.lib

opencv_haartraining_engine.lib

opencv_highgui244.lib

opencv_imgproc244.lib

opencv_legacy244.lib

opencv_ml244.lib

opencv_nonfree244.lib

opencv_objdetect244.lib

opencv_photo244.lib

opencv_stitching244.lib

opencv_ts244.lib

opencv_video244.lib

opencv_videostab244.lib


For Debug:

View -> Property Manager

Double click Debug | x64

  1. C/C++ -> General -> Additional Include Directories

C:\OpenCV\build\include\opencv

C:\OpenCV\build\include

  1. Linker -> General -> Additional Library Directories

C:\OpenCV\build\x64\vc11\lib

  1. Linker -> Input -> Additional Dependencies

opencv_calib3d244d.lib

opencv_contrib244d.lib

opencv_core244d.lib

opencv_features2d244d.lib

opencv_flann244d.lib

opencv_gpu244d.lib

opencv_haartraining_engined.lib

opencv_highgui244d.lib

opencv_imgproc244d.lib

opencv_legacy244d.lib

opencv_ml244d.lib

opencv_nonfree244d.lib

opencv_objdetect244d.lib

opencv_photo244d.lib

opencv_stitching244d.lib

opencv_ts244d.lib

opencv_video244d.lib

opencv_videostab244d.lib

Note the file names has extra "d" which means debug



Using OpenCV 2.43 in Vsiual Studio 2012


First

Download CMake. Open CMake and use settings below. Then click Configure.

image description

Choose Visual Studio 11 Win64. Click Finish.

image description

After a while, click Configure again. Wait a moment and then click Generate.

Close CMake and go to C:\MyOpenCV, open OpenCV.sln.

Choose Debug.

image description

Right click INSTALL. And choose Build.

image description

After a long period of time, go back and choose Release. Similarly, right click INSTALL. And choose Build.

Close Visual Studio 2012.

Copy C:\MyOpenCV\install folder to C:\OpenCV.

So now you have a C:\OpenCV\install folder. You can delete C:\MyOpenCV whole folder if you want.


Second

Open Windows Explorer. Click on Computer and then System properties.

image description

Choose Advanced system settings.

image description

Click Environment Variables...

image description

Add only this to Environment Variables -> System variables -> Path

C:\OpenCV\install\bin

image description

image description


Third

After creating your own project in Visual Studio 2012...

Build menu -> Configuration Manager

Change the Active solution platform. Click on Win32, Select New.... Use the settings below and click OK.

image description


Fourth

For Release:

View -> Property Manager

Double click Release | x64

  1. C/C++ -> General -> Additional Include Directories

C:\OpenCV\build\include\opencv

C:\OpenCV\build\include

  1. Linker -> General -> Additional Library Directories

C:\OpenCV\build\x64\vc10\lib

  1. Linker -> Input -> Additional Dependencies

opencv_calib3d243.lib

opencv_contrib243.lib

opencv_core243.lib

opencv_features2d243.lib

opencv_flann243.lib

opencv_gpu243.lib

opencv_haartraining_engine.lib

opencv_highgui243.lib

opencv_imgproc243.lib

opencv_legacy243.lib

opencv_ml243.lib

opencv_nonfree243.lib ...

(more)
edit flag offensive delete link more

Comments

Really nice tutorial... have you included CUDA in your build? I followed your step but I can't compile OpenCV due to some strange errors with Cuda 5.0...

For more detail please read: http://answers.opencv.org/question/6734/building-opencv-243-in-visual-studio-2012-and-cuda/

Nicola17 gravatar imageNicola17 ( 2013-01-31 06:03:44 -0600 )edit

If you have CUDA, in CMake, before second time clicking Configure button, I think you need set some buttons into checked state. Since here I cannot add picture, so I added screenshot at the end of page. Because my computer doesn't have CUDA...so I'm not very sure how to set up them. Hope it can help you guys who has CUDA.

Hongbo Miao gravatar imageHongbo Miao ( 2013-01-31 11:27:25 -0600 )edit

Thank you for the very helpful images. My only problem is that when trying to run a test program, it says that "opencv_core243d.dll is missing from my computer, but it's not because i can see it in the folders! I have done something wrong, is there anyway to fix this?

Thanks.

syco_link gravatar imagesyco_link ( 2013-02-01 18:03:01 -0600 )edit
1

Hi, @Hongbo Miao, great answer! But why OpenCV official tutorial doesn't fit? Please, tell your thoughts. It's very important to improve OpenCV tutorials! (link to tutorial: http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-making-your-own-libraries-from-the-source-files)

Daniil Osokin gravatar imageDaniil Osokin ( 2013-02-02 10:47:35 -0600 )edit

@syco_link, did you use CMake to rebuild OpenCV according to tutorial? It seems that you forgot to add "C:\OpenCV\install\bin" in "Environment Variables -> System variables -> Path".

Hongbo Miao gravatar imageHongbo Miao ( 2013-02-03 06:21:54 -0600 )edit
2

Hi, @Daniil Osokin, first time I configure my OpenCV according to official tutorial. I used three days to do that, but always has something wrong. I mostly gave up, since the official tutorial is too complex which makes me so upset. So I try to figure it by myself according to other old tutorials online.

And actually if you use VS2010, it is not necessary to use CMake to rebuild OpenCV. Only VS2012 needs this process since OpenCV 2.43 does not work well with VS2012. If you don't rebuild it, many functions will have weird problems. For example, when you use "std::cout" on a "cv::Mat", it always fails.

I think people shouldn't spend their most time configuring OpenCV, they should spend their time on their project. So I try to write a tutorial to make things simple.

Hongbo Miao gravatar imageHongbo Miao ( 2013-02-03 06:48:31 -0600 )edit
1

Thanks for your answer! I'm think, that tutorials should be clear understandable too. Please, suggest an improvements to official tutorial, you can do it better!

Daniil Osokin gravatar imageDaniil Osokin ( 2013-02-03 07:04:23 -0600 )edit

Thank you very much for your tutorial, really helpful. I had a lot of trouble when dealing with vectors till I came across your tutorial. Just take into account that this tutorial is focused on a 64bit MCVS 2012, in case you have a 32bit installed (like my case) some steps might be different. When choosing which generator to use on CMake you should choose, pick the normal Microsoft Visual Studio 11 instead of Microsoft Visual Studio 11 Win64. Also you should skip step number three. Thanks again for the tutorial ;)

Borja Lacabex gravatar imageBorja Lacabex ( 2013-02-28 06:59:36 -0600 )edit

Great tutorial, seemed to work great but now I am getting the error "error LNK1181: cannot open input file 'opencv_calib3d243.lib" Any ideas?

Aristoi gravatar imageAristoi ( 2013-03-02 01:45:55 -0600 )edit

Hi, @Aristoi, are you using OpenCV 2.43 or OpenCV 2.44? I think maybe you are using the latest OpenCV 2.44, so you should change the file names in fourth step according to the file folder in OpenCV\build\x64\vc10\lib or OpenCV\build\x64\vc11\lib.

Hongbo Miao gravatar imageHongbo Miao ( 2013-03-02 19:32:02 -0600 )edit
1

answered 2013-06-25 07:03:33 -0600

herohuyongtao gravatar image

updated 2013-06-25 07:08:08 -0600

The problem still exists to use OpenCV 2.4.4 when compiled under x64+Debug+vc11 (though no problem under x64+Release+vc11). For example, if you want to call the following function, it will cause RtlFreeHeap error when it returns.

vector<float> get_color_histogram_of_image(Mat img)

{

vector<float> result;

/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split( img, bgr_planes );

/// Establish the number of bins
int histSize = 8;

/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 } ; //0~255 the upper boundary is exclusive
const float * histRange = { range };

bool uniform = true; 
bool accumulate = false;

Mat b_hist, g_hist, r_hist;

/// Compute the histograms:
calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );

/// stored in result
for (int i=0; i<histSize; i++)
    result.push_back(r_hist.at<float>(i, 0));
for (int i=0; i<histSize; i++)
    result.push_back(g_hist.at<float>(i, 0));
for (int i=0; i<histSize; i++)
    result.push_back(b_hist.at<float>(i, 0));

// release
//delete [2]histRange;

return result;

}

edit flag offensive delete link more

Comments

Please let me know if you can solve this problem. Thanks.

herohuyongtao gravatar imageherohuyongtao ( 2013-06-25 07:06:22 -0600 )edit
1

answered 2013-01-27 09:18:19 -0600

Hongbo Miao gravatar image

updated 2013-01-27 20:24:17 -0600

Hi, your code works well on my computer. Since OpenCV 2.43 does not work well with Visual Studio 2012, you have to use CMake to rebuild OpenCV 2.43. Have you done it? If you don't know how to rebuild it, tell me.

edit flag offensive delete link more

Comments

Thanks for your answer, I'll give it a try and let you know

Maurizio Lo Bosco gravatar imageMaurizio Lo Bosco ( 2013-01-28 16:24:19 -0600 )edit

Hi, actually, it used me a lot of time to make all things work. So let me give you a simple tutorial.

Hongbo Miao gravatar imageHongbo Miao ( 2013-01-28 18:40:09 -0600 )edit
0

answered 2014-07-08 18:31:15 -0600

A great help. Thanks a lot. I had spent lot of time, though learned the hard way.

Only getting one problem in Debug : My system is windows 7 , 64 bit using VS 2010 and OpenCV 2.4.8

Error 1 error LNK1181: cannot open input file 'opencv_calib3d248d.dll' C:\Users\world\project\ver1\LINK ver1

image description I am trying this code : taken from web site

include "stdafx.h"

include <cv.h>

include <highgui.h>

include <math.h>

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

using namespace cv;

int main() { int k; VideoCapture cap = VideoCapture(0); while(1) { Mat img; cap >> img; imshow("image",img);

    k = waitKey(10);
    if (k == 27)         {
        break;
    }
}
return 0;

}

This program builds successfully in 64 bit , but on when I try to start without debugging I get this error OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ......\opencv248\opencv\sources\modules\highgui\src\window.cpp, line 261 Press any key to continue . . . image description Similarly, I had developed a project in university times using 32 bit on the same system i.e., Win7, 32 bit with VS2010 , it works fine in VS2010 with same configuration but when I try to build it in 64 bit it gives same error message. Can you guide me. Rest all is OK. Thanks

edit flag offensive delete link more

Comments

Please open your own question for this problem ... there is no use in reviving old topics just for solving a new problem. Probably you are linking 32 bit libs to a 64 bit system...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-09 07:25:03 -0600 )edit
0

answered 2013-09-17 11:39:12 -0600

Tariq gravatar image

updated 2013-09-17 11:40:37 -0600

Hi, Thanks for tutorial. I am following the steps mentioned in your tutorial. I keep on getting the following three message boxes during building "INSTALL.sln" project. These message boxes are generated by Visual Studio 2010. I have already closed my CMake window. I have Windows 7+ VS 2010+ CUDA 5.5 DIALOG-1: image description

DIALOG-2: image description

DIALOG-3: image description

My build process continues after these three dialog boxes. Only few projects are built after repeating this process for couple of hours.

Can anybody suggest any solution/idea to do it?

Regards,

Tariq

P.S: Its not a solution to the question originally asked. My problem is related to your tutorial....I can't add images in comments.!

edit flag offensive delete link more

Comments

Actually I had the same but after rebuilding twice I got all the libraries built correctly, even with these errors popping up. However, I am also curious if someone knows why this happens.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-17 16:09:20 -0600 )edit

Thanks Steven. what do u mean by "rebuilding twice"? Do you mean building twice in visual studio or repeating above dialog boxes two times? I have seen above dialog boxes countless times.......I am kind of clueless on what to do next to get out of this now

Tariq gravatar imageTariq ( 2013-09-18 03:34:19 -0600 )edit

Building in VS2012 I keep getting errors both times, but when I build binaries, they come out, so I am guessing it is not the binaries that give problems, but rather some examples or such.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-18 03:48:07 -0600 )edit

I did not include c examples in my build in CMake options. I am still getting the reload message boxes. My configuration in CMake is Visual Studio 2010 [Win 64], Windows 7[64-bit], CUDA 5.5 Any idea what to do next? Is it possible to share your CMake output?

Regards, Tairq

Tariq gravatar imageTariq ( 2013-09-18 04:29:21 -0600 )edit

I do not have the configuration on my system anymore. Just reduce all modules that you do not need explicitly and all extras like PvAPI support and such.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-18 04:33:16 -0600 )edit
0

answered 2013-01-31 11:29:34 -0600

Hongbo Miao gravatar image

If you have CUDA, in CMake, before second time clicking Configure button, I think you need set some buttons into checked state. Because my computer doesn't have CUDA...so I'm not very sure how to set up them. Hope it can help you guys who has CUDA.

image description

edit flag offensive delete link more

Comments

This isn't the problem... If you have correctly installed CUDA everithing will already checked.

Please relate to my post to read all the details:

answers.opencv.org/question/6734/building-opencv-243-in-visual-studio-2012-and-cuda/

Nicola17 gravatar imageNicola17 ( 2013-02-01 07:10:13 -0600 )edit

Hi, @Nicola17, I really want to help you, but my computer does not have CUDA... So I cannot test it. Sorry about that. Hope you can find answer from other guys.

Hongbo Miao gravatar imageHongbo Miao ( 2013-02-03 06:12:14 -0600 )edit

Thank you very much. This was very helpful to compile openCV 2.4.4 with VS2012 on 64bit win7.

MMLuqman gravatar imageMMLuqman ( 2013-03-27 11:09:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-01-25 10:51:13 -0600

Seen: 18,228 times

Last updated: Jul 08 '14