-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory allocation error in Wrapper.h #174
Comments
this might be a change in the newer version of opencv being used in OF 0.9.0. you could try replacing the line with it could also be that dstMat is unallocated for some reason, and that's why i can't look into this right now, but if you find a solution please send a PR! otherwise i'll take a deeper look when i get the chance. |
hi, I am sorry I didn't catch the meaning of PR! But yeah, I found a tweak to avoid the error in add function. template <class S, class D>
void CLD(S& src, D& dst, int halfw = 4, int smoothPasses = 2, double sigma1 = .4, double sigma2 = 3, double tau = .97, int black = 0) {
copy(src, dst);
int width = getWidth(src), height = getHeight(src);
//imatrix img;
//img.init(height, width);
//KASP-sol-01
imatrix img = new imatrix(height,width);
Mat dstMat = toCv(dst);
if(black != 0) {
add(dstMat, cv::Scalar(black), dstMat);
}
// copy from dst (unsigned char) to img (int)
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
img[y][x] = dstMat.at<unsigned char>(y, x);
}
}
//ETF etf;
//etf.init(height, width);
//KASP-sol-01
ETF etf = new ETF(height, width);
etf.set(img);
etf.Smooth(halfw, smoothPasses);
GetFDoG(img, etf, sigma1, sigma2, tau);
// copy result from img (int) to dst (unsigned char)
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
dstMat.at<unsigned char>(y, x) = img[y][x];
}
}
} This avoids error from void ETF::Smooth(int half_w, int M)
{
int i, j, k;
int MAX_GRADIENT = -1;
double weight;
int s, t;
int x, y;
double mag_diff;
int image_x = getRow();
int image_y = getCol();
//ETF e2;
//e2.init(image_x, image_y);
//KASP-sol-01
ETF *e2 = new ETF(image_x,image_y);
e2->copy(*this);
double v[2], w[2], g[2];
double angle;
double factor;
for (k = 0; k < M; k++) {
////////////////////////
// horizontal
for (j = 0; j < image_y; j++) {
for (i = 0; i < image_x; i++) {
g[0] = g[1] = 0.0;
v[0] = p[i][j].tx;
v[1] = p[i][j].ty;
for (s = -half_w; s <= half_w; s++) {
////////////////////////////////////////
x = i+s; y = j;
if (x > image_x-1) x = image_x-1;
else if (x < 0) x = 0;
if (y > image_y-1) y = image_y-1;
else if (y < 0) y = 0;
////////////////////////////////////////
mag_diff = p[x][y].mag - p[i][j].mag;
//////////////////////////////////////////////////////
w[0] = p[x][y].tx;
w[1] = p[x][y].ty;
////////////////////////////////
factor = 1.0;
angle = v[0] * w[0] + v[1] * w[1];
if (angle < 0.0) {
factor = -1.0;
}
weight = mag_diff + 1;
//////////////////////////////////////////////////////
g[0] += weight * p[x][y].tx * factor;
g[1] += weight * p[x][y].ty * factor;
}
make_unit(g[0], g[1]);
//e2[i][j].tx = g[0];
//e2[i][j].ty = g[1];
//KASP-sol-01
(*e2)[i][j].tx = g[0];
(*e2)[i][j].ty = g[1];
}
}
//this->copy(e2);
//KASP-sol-01
this->copy(*e2);
/////////////////////////////////
// vertical
for (j = 0; j < image_y; j++) {
for (i = 0; i < image_x; i++) {
g[0] = g[1] = 0.0;
v[0] = p[i][j].tx;
v[1] = p[i][j].ty;
for (t = -half_w; t <= half_w; t++) {
////////////////////////////////////////
x = i; y = j+t;
if (x > image_x-1) x = image_x-1;
else if (x < 0) x = 0;
if (y > image_y-1) y = image_y-1;
else if (y < 0) y = 0;
////////////////////////////////////////
mag_diff = p[x][y].mag - p[i][j].mag;
//////////////////////////////////////////////////////
w[0] = p[x][y].tx;
w[1] = p[x][y].ty;
////////////////////////////////
factor = 1.0;
///////////////////////////////
angle = v[0] * w[0] + v[1] * w[1];
if (angle < 0.0) factor = -1.0;
/////////////////////////////////////////////////////////
weight = mag_diff + 1;
//////////////////////////////////////////////////////
g[0] += weight * p[x][y].tx * factor;
g[1] += weight * p[x][y].ty * factor;
}
make_unit(g[0], g[1]);
//e2[i][j].tx = g[0];
//e2[i][j].ty = g[1];
//KASP-sol-01
(*e2)[i][j].tx = g[0];
(*e2)[i][j].ty = g[1];
}
}
//this->copy(e2);
//KASP-sol-01
this->copy(*e2);
}
////////////////////////////////////////////
} however it still keeps giving me errors. So, try to have a look at it. Anyways, all that I have done about is allocating memory dynamically Please send me an email on [email protected]. I'll forward if I fixed anything else. |
Hi Kyle,
I have successfully run several examples in ofxCv. But I have been trying to run example-blink in ofxFaceTracker . And I ran in to several issues. To help others I will post my answer here for issue 1.
Kyle I need your insight on issue 2.
I am working on Visual Studio 2015 on Windows 7. I have also Installed the Windows 8.1 SDK.
Solution. There exists two files with the name Tracker.h in ofxFaceTracker and ofxCv. There were many methods to workaround this one. None of them worked for. I had to change the name of one file. And also refactor the code accordingly.
I have backtracked the error and found it originates from this line in Wrapper.h
I think the problem is add function taking
Mat&
type andcv::Scalar
types as inputs and trying to give aMat&
output. Please provide a solution.Thanks a lot.
The text was updated successfully, but these errors were encountered: