Ask Your Question

Tankard's profile - activity

2017-11-10 15:53:51 -0500 received badge  Student (source)
2016-09-28 09:17:47 -0500 received badge  Scholar (source)
2016-09-28 09:06:24 -0500 asked a question cv::OutOfMemoryError while calculating (surf)descriptors

I'm trying to set up an object recognition system with 12x30 images with 1280x1024 pixels.

I'm using Visual Studio 2013, Windows 8.1 x64 with 8GB RAM and compile as x86. I get the following error message:

C:\opencv\sources\modules\core\src\alloc.cpp:52: error: (-4) Failed to allocate 74747652 bytes in function cv::OutOfMemoryError

According to the Task Manager, my software needs less than 1.600.000K memory and the RAM is at 84%. So I think that should not be the problem.

This is the code, where I get the error:

cv::Ptr<cv::SurfFeatureDetector> detector = cv::SurfFeatureDetector::create("SURF");
cv::Ptr<cv::SurfDescriptorExtractor> extractor = cv::SurfDescriptorExtractor::create("SURF");
std::map<std::string, std::vector<cv::Mat>> imageList;

// Filling the imageList

printMessageSlot("Starting: Compute Descriptors");

std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
cv::Mat training_descriptors(1, extractor->descriptorSize(), extractor->descriptorType());

for (const auto &imgList : imageList)
    for (const auto &img : imgList.second)
        detector->detect(img, keypoints);
        extractor->compute(img, keypoints, descriptors);

printMessageSlot("Ending: Compute Descriptors");

I'm not really sure what causes the problem. I tried to set the Heap and Stack Reservation Size in Visual Studio to 2GB, but I get the error message that there is not enought memory for that command.

I really don't know how to solve this. I could try to read just one folder (corresponding to object class) of Images, calculate the descriptors and than override the Images with the next folder/class. But that feels like more complicated than it should be.

How does it works, when I have more than that few (360) Images?

2016-02-23 07:12:23 -0500 asked a question What algorithm does cv::findChessboardCorners use?


I wonder what algorithm is used in cv::findChessboardCorners. I found explanations for a lot of funcrions in openCV but no information about cv::findChessboardCorners. Is it something like a Harris coner detector or some other standard algorithm?


2015-04-09 09:56:36 -0500 asked a question StereoCalibrate - error: (-206) in function cvReleaseMat


I try to calibrate two cameras. When I call cv::stereoCalibrate I get the following error

C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\core\src\array.cpp:190: error: (-206) in function cvReleaseMat

I have really no clue why this happens and how to solve it. And I have no idea what error -206 means.

Here is the part of my code:

StereoCalibrationStruct stereoCali;

    stereoCali.cameraMatrix1 = img1It->second.cameraMatrix;
    stereoCali.distortion1 = img1It->second.distortion;
    stereoCali.cameraMatrix2 = img2It->second.cameraMatrix;
    stereoCali.distortion2 = img2It->second.distortion;
    stereoCali.imageSize = img1It->second.imageSize;

        stereoCali.error = cv::stereoCalibrate(objIt->second,
            img1It->second.corners, img2It->second.corners,
            stereoCali.cameraMatrixMesa, stereoCali.distortionMesa,
            stereoCali.cameraMatrixIds, stereoCali.distortionIds,
            stereoCali.imageSize, stereoCali.R, stereoCali.T, stereoCali.E, stereoCali.T,
            cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 30, 1e-6), CV_CALIB_FIX_INTRINSIC);

objIt->second is a vector with the vectors of the 44 objectpoints as x/y/z with z=0 (I use a 4x11 asym circle pattern) img1/2It->second.coners is a vector of the 44 found objectpoints as x/y. StereoCalibrationStruct looks like that:

typedef struct {
    cv::Mat cameraMatrix1;
    cv::Mat cameraMatrix2;
    cv::Mat distortion1;
    cv::Mat distortion2;
    cv::Mat R;
    cv::Mat T;
    cv::Mat E;
    cv::Mat F;
    double error;
    cv::Size imageSize;
} StereoCalibrationStruct;

The 4 matrices look like they have non default values. So it seems that function do the work but then crashes.

Any ideas how to fix it or why this happens?

2015-03-19 06:52:41 -0500 received badge  Enthusiast
2015-03-18 09:53:26 -0500 asked a question Matching/Rectify Images with different Sizes


I want to match the Pixels of two different Cameras.

I already have the camera matrix of both cameras and the rvecs and tvecs. I also have the images undistorted. Now, after I have the matrices R and T, i would call cv::stereoRectify. The problem is, that this functions needs a image size as parameter but my cameras have different image sizes and worse, different aspect ratios.

Is there a way to rectify/match the images with different sizes and aspect ratios? I cannot just scale one image up to the size of the other, because this would deform the image (due to the aspect ratio).


2015-01-14 09:57:27 -0500 received badge  Supporter (source)
2015-01-14 09:57:24 -0500 commented answer cv::fastNlMeansDenoising does not return

Thanks a lot. This worked for the images I have so far. I had no idea about cv::minMaxLoc.

2015-01-14 08:45:33 -0500 commented answer cv::fastNlMeansDenoising does not return

The norm value for this image is 33289.517779625465. 256/norm or pixelCount/norm don't work. I don't really know what would be a "normal" value for alpha.

2015-01-14 07:23:58 -0500 commented answer cv::fastNlMeansDenoising does not return

I tried to use norm + Mat::convertTo, as it is mentioned in the doc to normalize. The result is a almost all withe image: almoste_all_white.png

This is the code I used

cv::Mat roi(gray, cv::Rect(gray.rows / 2 - 350, gray.cols / 2 - 350, 700, 700));
double norm = cv::norm(/*gray*/roi, CV_L2/*, roi*/);
gray.convertTo(grayFiltered, grayFiltered.type(), norm);

I must confess, I don't really understand how to use the Lx Norms on images. When I understand the documentation of normalize correctly, I cannot use normalize directly with an input mask to modify the whole image. So I have to use the norm + convertTo combination. One problem is, that norm does not allow NORM_MINMAX. So I don't really know if I use it the right way.

2015-01-13 08:35:52 -0500 commented answer cv::fastNlMeansDenoising does not return

I tried normalize (with MINMAX and [0 255]) and it works as long as I don't have reflexions in the background. I tried to remove these reflexions (threshold + inpaint), but the regions around the reflexions are very bright so normalize makes no noticeable changes. I don't know if it is really possible to remove such bright spots in the background.

Here is an example for an image with reflexion. bright_spots.png

2015-01-12 08:07:36 -0500 asked a question cv::fastNlMeansDenoising does not return


I have some problems with cv::findCirclesGrid. Some of my image have very poor contrast and cv::findCircleGrid sometimes takes forever (several minutes) before it returns false.

Therefore, I want to make a better contrast using cv::equalizeHist. The problem with this is, that the image gets really noisy. I tried to denoise it with cv::fastNlMeansDenoising.

I waited several minutes, but the function did not return and I have no idea what to do now.

Has anyone an idea how I could denoise (or generally prepare) my images before using cv::findCirclesGrid? I use Visual Studio 2013 Pro and OpenCv 2.4.9 (x86).

I attach one sample image bevor and after cv::equalizeHist. And here is my code:

for (auto &img : images)
    cv::Mat gray;

    cv::cvtColor(img, gray, CV_BGRA2GRAY);

    cv::Mat grayFiltered(gray.rows, gray.cols, gray.type());

    //cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();

    //clahe->apply(gray, gray);
    cv::equalizeHist(gray, gray);

    cv::fastNlMeansDenoising(gray, grayFiltered);
    //cv::threshold(gray, gray, 160, 255, CV_THRESH_BINARY); // Needs a different threshold, depending on the actual image