Skip to content

Commit

Permalink
Merge pull request #30 from the-grid/fix-nonabs-values
Browse files Browse the repository at this point in the history
Safe check for non-absolute values
  • Loading branch information
automata committed Mar 16, 2016
2 parents 7db3c58 + f1d43c1 commit 4ca3265
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions components/GetSaliency-node.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ runSaliency = (tmpFile, callback) ->
exec "#{bin} #{tmpFile.path}", (err, stdout, stderr) ->
tmpFile.unlink()
if err
console.log 'GetSaliency ERROR:', err
callback err
return
else
Expand Down
39 changes: 25 additions & 14 deletions saliency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ string jsonify(Rect &bigRect,
float entropy) {
ostringstream out;

if (contours_poly.size() <= 0) {
out << "{\"saliency\": null}" << endl;
return out.str();
}

out << "{\"saliency\": ";
float x = bigRect.tl().x;
float y = bigRect.tl().y;
Expand Down Expand Up @@ -266,22 +271,28 @@ int main(int argc, char *argv[]) {
ymax = 0;
xmin = INFINITY;
ymin = INFINITY;
for (size_t j=0, max = boundRect.size(); j<max; ++j) {
int xminB = boundRect[j].x;
int yminB = boundRect[j].y;
int xmaxB = boundRect[j].x + boundRect[j].width;
int ymaxB = boundRect[j].y + boundRect[j].height;
if (xminB < xmin)
xmin = xminB;
if (yminB < ymin)
ymin = yminB;
if (xmaxB > xmax)
xmax = xmaxB;
if (ymaxB > ymax)
ymax = ymaxB;
if (boundRect.size() > 0) {
for (size_t j=0, max = boundRect.size(); j<max; ++j) {
int xminB = boundRect[j].x;
int yminB = boundRect[j].y;
int xmaxB = boundRect[j].x + boundRect[j].width;
int ymaxB = boundRect[j].y + boundRect[j].height;
if (xminB < xmin)
xmin = xminB;
if (yminB < ymin)
ymin = yminB;
if (xmaxB > xmax)
xmax = xmaxB;
if (ymaxB > ymax)
ymax = ymaxB;
}
} else {
xmin = 0;
ymin = 0;
xmax = 0;
ymax = 0;
}
Rect bigRect = Rect(xmin, ymin, xmax-xmin, ymax-ymin);

#ifdef DEBUG
// Draw polygonal contour + bonding rects + circles
Mat drawing = Mat::zeros( filtered.size(), CV_8UC3 );
Expand Down

0 comments on commit 4ca3265

Please sign in to comment.