Skip to content

Commit

Permalink
Fix issues introduced in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Apr 10, 2024
1 parent ed78d68 commit 5c245b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
16 changes: 8 additions & 8 deletions modules/io/src/image/private/vpImageIoLibjpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ void readJPEGLibjpeg(vpImage<unsigned char> &I, const std::string &filename)
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer, 1);
for (unsigned int i = 0; i < width; ++i) {
*(++output) = buffer[0][i * 3];
*(++output) = buffer[0][i * 3 + 1];
*(++output) = buffer[0][i * 3 + 2];
*(++output) = vpRGBa::alpha_default;
*(output++) = buffer[0][i * 3];
*(output++) = buffer[0][i * 3 + 1];
*(output++) = buffer[0][i * 3 + 2];
*(output++) = vpRGBa::alpha_default;
}
}
vpImageConvert::convert(Ic, I);
Expand Down Expand Up @@ -308,10 +308,10 @@ void readJPEGLibjpeg(vpImage<vpRGBa> &I, const std::string &filename)
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer, 1);
for (unsigned int i = 0; i < width; ++i) {
*(++output) = buffer[0][i * 3];
*(++output) = buffer[0][i * 3 + 1];
*(++output) = buffer[0][i * 3 + 2];
*(++output) = vpRGBa::alpha_default;
*(output++) = buffer[0][i * 3];
*(output++) = buffer[0][i * 3 + 1];
*(output++) = buffer[0][i * 3 + 2];
*(output++) = vpRGBa::alpha_default;
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions modules/io/src/image/private/vpImageIoLibpng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,35 +381,35 @@ void readPNGLibpng(vpImage<unsigned char> &I, const std::string &filename)
case 1:
output = (unsigned char *)I.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i];
*(output++) = data[i];
}
break;

case 2:
output = (unsigned char *)I.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 2];
*(output++) = data[i * 2];
}
break;

case 3:
output = (unsigned char *)Ic.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 3];
*(++output) = data[i * 3 + 1];
*(++output) = data[i * 3 + 2];
*(++output) = vpRGBa::alpha_default;
*(output++) = data[i * 3];
*(output++) = data[i * 3 + 1];
*(output++) = data[i * 3 + 2];
*(output++) = vpRGBa::alpha_default;
}
vpImageConvert::convert(Ic, I);
break;

case 4:
output = (unsigned char *)Ic.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 4];
*(++output) = data[i * 4 + 1];
*(++output) = data[i * 4 + 2];
*(++output) = data[i * 4 + 3];
*(output++) = data[i * 4];
*(output++) = data[i * 4 + 1];
*(output++) = data[i * 4 + 2];
*(output++) = data[i * 4 + 3];
}
vpImageConvert::convert(Ic, I);
break;
Expand Down Expand Up @@ -558,36 +558,36 @@ void readPNGLibpng(vpImage<vpRGBa> &I, const std::string &filename)
case 1:
output = (unsigned char *)Ig.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i];
*(output++) = data[i];
}
vpImageConvert::convert(Ig, I);
break;

case 2:
output = (unsigned char *)Ig.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 2];
*(output++) = data[i * 2];
}
vpImageConvert::convert(Ig, I);
break;

case 3:
output = (unsigned char *)I.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 3];
*(++output) = data[i * 3 + 1];
*(++output) = data[i * 3 + 2];
*(++output) = vpRGBa::alpha_default;
*(output++) = data[i * 3];
*(output++) = data[i * 3 + 1];
*(output++) = data[i * 3 + 2];
*(output++) = vpRGBa::alpha_default;
}
break;

case 4:
output = (unsigned char *)I.bitmap;
for (unsigned int i = 0; i < width * height; ++i) {
*(++output) = data[i * 4];
*(++output) = data[i * 4 + 1];
*(++output) = data[i * 4 + 2];
*(++output) = data[i * 4 + 3];
*(output++) = data[i * 4];
*(output++) = data[i * 4 + 1];
*(output++) = data[i * 4 + 2];
*(output++) = data[i * 4 + 3];
}
break;
}
Expand Down
21 changes: 11 additions & 10 deletions modules/tracker/blob/src/dots/vpDot2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void vpDot2::initTracking(const vpImage<unsigned char> &I, unsigned int size)
unsigned int i = static_cast<unsigned int>(cog.get_i());
unsigned int j = static_cast<unsigned int>(cog.get_j());

double Ip = pow(static_cast<double>(I[i][j] / 255), 1 / gamma);
double Ip = pow(static_cast<double>(I[i][j]) / 255, 1 / gamma);

if ((Ip - (1 - grayLevelPrecision)) < 0) {
gray_level_min = 0;
Expand Down Expand Up @@ -572,6 +572,7 @@ void vpDot2::track(const vpImage<unsigned char> &I, bool canMakeTheWindowGrow)
gray_level_max = 255;
}

// printf("%i %i \n",gray_level_max,gray_level_min);
if (graphics) {
// display a red cross at the center of gravity's location in the image.
vpDisplay::displayCross(I, this->cog, (3 * thickness) + 8, vpColor::red, thickness);
Expand Down Expand Up @@ -1343,12 +1344,12 @@ bool vpDot2::isValid(const vpImage<unsigned char> &I, const vpDot2 &wantedDot)
// a2^2 = 2 / m00 * (mu02 + mu20 - sqrt( (mu20 - mu02)^2 + 4mu11^2) )

// we compute parameters of the estimated ellipse
double tmp1 = (((m01 * m01) - (m10 * m10)) / m00) + (m20 - m02);
double tmp2 = (m11 - m10) * (m01 / m00);
double Sqrt = sqrt((tmp1 * tmp1) + (4 * tmp2 * tmp2));
double a1 = sqrt((2 / m00) * ((m20 + m02) - (((m10 * m10) + (m01 * m01)) / m00) + Sqrt));
double a2 = sqrt((2 / m00) * ((m20 + m02) - (((m10 * m10) + (m01 * m01)) / m00) - Sqrt));
double alpha = 0.5 * atan2(2 * ((m11 * m00) - (m10 * m01)), (((m20 - m02) * m00) - (m10 * m10) + (m01 * m01)));
double tmp1 = (m01 * m01 - m10 * m10) / m00 + (m20 - m02);
double tmp2 = m11 - m10 * m01 / m00;
double Sqrt = sqrt(tmp1 * tmp1 + 4 * tmp2 * tmp2);
double a1 = sqrt(2 / m00 * ((m20 + m02) - (m10 * m10 + m01 * m01) / m00 + Sqrt));
double a2 = sqrt(2 / m00 * ((m20 + m02) - (m10 * m10 + m01 * m01) / m00 - Sqrt));
double alpha = 0.5 * atan2(2 * (m11 * m00 - m10 * m01), ((m20 - m02) * m00 - m10 * m10 + m01 * m01));

// to be able to track small dots, minorize the ellipsoid radius for the
// inner test
Expand All @@ -1371,6 +1372,7 @@ bool vpDot2::isValid(const vpImage<unsigned char> &I, const vpDot2 &wantedDot)
"%d not in [%u, %u]\n",
u, v, cog_u, cog_v, I[v][u], gray_level_min, gray_level_max);
#endif
// return false;
nb_bad_points++;
}
if (graphics) {
Expand Down Expand Up @@ -1486,11 +1488,10 @@ bool vpDot2::hasGoodLevel(const vpImage<unsigned char> &I, const unsigned int &u
bool vpDot2::hasReverseLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const
{

if (!isInArea(u, v)) {
if (!isInArea(u, v))
return false;
}

if ((I[v][u] < gray_level_min) || (I[v][u] > gray_level_max)) {
if (I[v][u] < gray_level_min || I[v][u] > gray_level_max) {
return true;
}
else {
Expand Down

0 comments on commit 5c245b0

Please sign in to comment.