Expression: "(_Ptr_user&(_BIG_ALLOCATION_ALIGNMENT - 1)) ==0" && 0 - visual-studio

I am working with Visual Studio and OpenCV. I have a simple code that detects keypoints and computes descriptors of two images.
void extractfeatures::extractKeypoints(cv::Mat _frame, cv::Mat _object)
{
//Extract keypoints
cv::Ptr<cv::FeatureDetector> detector;
cv::Ptr<cv::AKAZE> akaze = cv::AKAZE::create();
std::vector<cv::KeyPoint> object_keypoints, background_keypoints;
cv::Mat desc1, desc2;
akaze->detectAndCompute(_object, cv::noArray(), object_keypoints, desc1);
akaze->detectAndCompute(_frame, cv::noArray(), background_keypoints, desc2);
}
The code works fine and it almost the same as the one give in the OpenCV Akaze documentation: http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/akaze_matching/akaze_matching.html
However, when it gets out of the function it gives me this error:
Expression: "(_Ptr_user&(_BIG_ALLOCATION_ALIGNMENT - 1)) ==0" && 0
Thank you in advance!

Because the memory of vector is limited, there are too many keypoints.
If the keypoints are about 10000:
object_keypoints.reserve(10000);
background_keypoints.reserve(10000)

Once I met such problem. It turned out that the program didn't link the right opencv's dll. When I moved the right dll, such as opencv_world310d.dll, to my program's Debug folder, this error disappeared.

Related

Parameters for dlib::find_min_bobyqa

I'm working on the C++ version of Matt Zucker's Page dewarping. So far everything works fine, but I have a problem with optimization. In line 748 of Github repo Matt uses optimize function from Scipy. My C++ equivalent is find_min_bobyqa from dlib.net. The code is:
auto f = [&](const column_vector& ppts) { return objective( dstpoints, ppts, keypoint_index); };
dlib::find_min_bobyqa(f,
params,
2 * params.nr() + 1, // npt - number of interpolation points: x.size() + 2 <= npt && npt <= (x.size()+1)*(x.size()+2)/2
dlib::uniform_matrix<double>(params.nr(), 1, -2), // lower bound constraint
dlib::uniform_matrix<double>(params.nr(), 1, 2), // upper bound constraint
1, // initial trust region radius
1e-5, // stopping trust region radius
4000 // max number of objective function evaluations
);
In my concrete example params is a dlib::column_vector with double values and length = 189. Every element of params is less than 2.0 and greater than -2.0. Function objective() returns double value and "alone" it works properly because I get the same value as in the Python version. But after running fin_min_bobyqa function I usually get the message:
Terminate called after throwing an instance of 'dlib:bobyqa_failure', return from BOBYQA because the objective function has been called max_f_evals times.
I set max_f_evals to quite big value to see if it optimizes at all, but it doesn't. I did some tweaking with parameters but without good results. How should I set the parameters of find_min_bobyqa to get the right solution?
I am very interested in this issue as well. Zucker's work, with very minor tweaks, is ideal for straightening sheet music images, and I was looking for ways to implement it in a mobile platform when I came across your question.
My research so far suggests that BOBYQA is not the equivalent of Powell's method in scipy. BOBYQA is constrained, and the one in scipy is not.
See these links for more information, and a possible way to compile the right supporting library - I would try UOBYQA or NEWUOA.
https://github.com/jacobwilliams/PowellOpt
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#rdd2e1855725e-3
(See the Notes section)
EDIT: see C version here:
https://github.com/emmt/Algorithms/tree/master/newuoa
I wanted to post this as a comment, but I don't have enough points for that.
I am very interested in your progress. If you're willing, please keep me posted.
I finally solved this problem. I used PRAXIS library, because it doesn't need derivative information and is fast.
I modified the code a little to my needs and now it is faster around few seconds than original version written in Python.

C++ Function does not take 2 arguments

I'm following a tutorial on creating a video game using C++. And I've got stuck on this step:
spriteBg -> setAnchorPoint(0,0);
I've got an error of: Function does not take 2 arguments
But anchor points are usually two digits pair (x,y) or Vec2::ZERO according with the docs, so what it's wrong with this line?
The guy on the tutorial has a red curvy line under the second 0 as well I have that red line under my second zero in setAnchorPoint(0,0), nevertheless he can build the project without errors but I can't due this error of 2 arguments.
He is using Visual Studio 2012 and I'm using Visual Studio 2013 for what it's worth. The Project was generated with Cocos2d.
This is the whole method.
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
auto spriteBg = Sprite::create("images/bg.png");
spriteBg ->setAnchorPoint(0,0);
spriteBg ->setPosition(0,0);
addChild(spriteBg , 0);
return true;
}
This is the whole error:
error C2660: 'cocos2d::Sprite::setAnchorPoint': function does not take 2 arguments
So far the same result with 5 approaches:
spriteBg ->setAnchorPoint(0,0);
spriteBg ->setAnchorPoint({0,0});
spriteBg ->setAnchorPoint(Vec2::ZERO);
spriteBg ->setAnchorPoint(Vec2(0,0));
spriteBg ->setAnchorPoint(Point(0,0));
This is the tutorial and this particular step is at 18:27. The tutorial is in Spanish but you clearly can see the guy coding and is just a few lines.
https://www.youtube.com/watch?v=v7d3ic_lmGw
Greetings.
Not sure what the problem is without the exact error message, but if you say it takes Vec2::ZERO maybe try:
spriteBg -> setAnchorPoint(Vec2(0,0));
As clearly mentioned in your error :- error C2660: 'cocos2d::Sprite::setAnchorPoint': function does not take 2 arguments
it takes only one argument of 'Vec2' type.
Try spriteBg -> setAnchorPoint(Vec2(0,0));
Jump to the definition of sprite and look at the function definition for setAnchorPoint. Depending on what version of Cocos2D-x you're using I know for a fact that setAnchorPoint takes a Vec2 object.
The parameter of setAnchorPoint in cpp should be a Point(Vec2). Of course you will get the error if the parameters are two number.
It is easy to understand the error by checking the declaration of the function.
Not sure if this works completely, try using:
sprite->setAnchorPoint(ccp(0,0));

surface feature detection on image processing

An example of detectSURFFeatures in comparison of 2 image is in below. I couldn't make detectSURFFeatures function work in my MATLAB. no help or doc detectSURFFeatures gives any clue. the error says " > UncalibratedSterio
Undefined function 'detectSURFFeatures' for input arguments of type 'uint8'." but the function itself can cover uint8 as i know. what should i do?
%Rectified Sterio Image Uncalibrated
% There is no calibration of cameras
I1 = rgb2gray(imread('right_me.jpg'));
I2 = rgb2gray(imread('left_me.jpg'));
Value = 2000.0;
blobs1 = detectSURFFeatures(I1, 'MetricThreshold', Value);
blobs2 = detectSURFFeatures(I2, 'MetricThreshold', Value);
figure;
imshow(I1);
hold on;
plot(selectStrongest(blobs1, 30));
title('Thirty strongest SURF features in I1');
figure;
imshow(I2);
hold on;
plot(selectStrongest(blobs2, 30));
title('Thirty strongest SURF features in I2');
You are getting that error because detectSURFFeatures does not exist in your MATLAB distribution. You must have at least R2011b, as that was when detectSURFFeatures was available: http://www.mathworks.com/help/vision/release-notes.html#R2011b
I suspect you have an older version of MATLAB than R2011b and so if you want to make it easy on yourself, you need to upgrade your version of MATLAB. However, if I may make a suggestion, I suggest the mexopencv project by Kota Yamaguchi: http://kyamagu.github.io/mexopencv/
He wrote OpenCV wrappers that can directly interface with MATLAB and so you can actually call OpenCV's SURF feature detection and matching methods from MATLAB but you will need to install OpenCV to do that. It will be a bit of work to get it working, but this is one solution I can provide if you don't want to upgrade your version of MATLAB.
Good luck!

term does not evaluate to a function taking 1 arguments

Please have a look at the following OpenCV code
Mat *curent;
current = new Mat();
cv::Rect bRect = cv::boundingRect(Mat(*points).reshape(2));
Mat roi = *current(bRect);
Here, I am trying to get a ROI to the Mat called roi. But whenever I try to get execute the last line of the above code I get the error term does not evaluate to a function taking 1 arguments. I have followed the same technique of getting an ROI without pointers number of times before in C++ and they worked. I guess the issue is with pointer current ? current must be a pointer because local variable slowed the application in an unbelievable way.
So, how can I solve this issue and get the ROI ?
please, throw out those pointers!
you're going to wreck havoc on the internal Mat refcounts, produce undefined behaviour and memleaks
"local variable slowed the application in an unbelievable way."
really, you think, copying a 58 byte struct is the reason ? i just don't believe you.
well i'll give you a hint, anyway - the ( ) operator has a higher precedence than the * operator.

C++/CLI seems to skip a line of code and debugging does not show the variable declared and defined in that line

I have only been developing in C++/CLI and C++ for a few months now but it seems to me that the programming language should not matter regarding this issue.
In the following lines of code, double k = (yEnd - yStart) / (xEnd - xStart); appears to be not executed.
//double k = 1.0;
if (xEnd - xStart == 0)
{
selected = true;
return true;
}
// Checks if Y-coordinate corresponds to X-coordinate
else
{
// Calculating the slope of the line
double k = (yEnd - yStart) / (xEnd - xStart);
if (fabs(y - (yStart + k * (x - xStart))) < (double)selectionTolerance)
{
selected = true;
return true;
}
}
I have tried to debug it line by line with F11 and have also set breakpoints, though these breakpoints move when running the debugger from the said line to if (fabs(y - (yStart + k * (x - xStart))) < (double)selectionTolerance) after it.
I have checked in the options of Visual Studio not to skip properties/operations, but it also didn't help. When the debugger halts the program at the if, I can not see any value of k, but can see all the other ones without problems (with the exception of char selectionTolerance and bool selected, all of them are double as well).
Thank you for the help, I have searched the web and stackoverflow for a long time but could not find a problem with a line as simple (and probably general) as this.
Update:
Thanks to David Yaw and G K, I was able to see the value of k. I am still puzzled by an issue illustrated here:
http://i.imgur.com/MyVGTwJ.png (cannot yet post images)
Even though yEnd, yStart, xEnd, xStart are all of type double and have the values as seen in the image above, when the program halts at line 254 before executing k=ydif/xdif;, k equals 0.0000000000000000. I added the three lines
double ydif= (yEnd-YStart);
double xdif=xEnd-xStart;
k=ydif/xdif;
to see the if k would be calculated as wanted, but it got the same value after pressing F11 again (program halts at line 256).
I found a question which is related to the jumping breakpoint issue here: Visual Studio breakpoints being moved
What is the problem with calculating k the way I try it, and what would be the correct way to do it?
You didn't mention that the calculation was incorrect, just that the line of code wasn't getting hit. I'm assuming the calculation is correct.
The local variable was likely optimized out by the compiler. Since you only used k in one spot, it eliminated the local variable, and did the slope calculation inline, in the if statement.
I've seen the C++/CLI compiler do similar things with method calls: I've gotten exceptions where the stack trace lists a method I don't call: The method I call was inlined, and the stack trace pointed to the method that it called.
I am using the Visual Studio 10.0 C++ compiler. The debug configuration uses the following command line switches when debugging /Gm /Od /RTCs /Zi /LDd Sorry I do not remember what each does. You can run the compiler in CLI and get a listing of what all the command line switches do. Those basicly turn of all optimizations.

Resources