Skip to content

Commit

Permalink
Updated manifest.xml (because Mac botched the job). Added singular bo…
Browse files Browse the repository at this point in the history
…unding boxes to Candidate
  • Loading branch information
hbristow committed Aug 10, 2012
1 parent c0a887e commit 46bb69c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
40 changes: 40 additions & 0 deletions include/Candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#ifndef CANDIDATE_HPP_
#define CANDIDATE_HPP_
#include <algorithm>
#include <iostream>
#include <limits>
#include <opencv2/core/core.hpp>
#include "types.hpp"
Expand Down Expand Up @@ -85,6 +86,45 @@ class Candidate {
static void sort(vectorCandidate& candidates) {
std::sort(candidates.begin(), candidates.end(), descending);
}

/*! @brief create a single bounding box around the detection taken from the part limit
*
* @return a single bounding Rect
*/
cv::Rect boundingBox(void) const {
int minx = std::numeric_limits<int>::max();
int miny = std::numeric_limits<int>::max();
int maxx = -std::numeric_limits<int>::max();
int maxy = -std::numeric_limits<int>::max();
const int nparts = parts_.size();
for (int n = 0; n < nparts; ++n) {
const cv::Rect p = parts_[n];
if (p.x + p.width/2 < minx) minx = p.x + p.width/2;
if (p.x + p.width/2 > maxx) maxx = p.x + p.width/2;
if (p.y + p.height/2 < miny) miny = p.y + p.height/2;
if (p.y + p.height/2 > maxy) maxy = p.y + p.height/2;
}
return cv::Rect(minx, miny, maxx-minx, maxy-miny);
}

/*! @brief create a single bounding box around the detection from mean and standard deviation
*
* @return
*/
cv::Rect boundingBoxNorm(void) const {
const int nparts = parts_.size();
cv::Mat_<int> xpts(cv::Size(1,nparts));
cv::Mat_<int> ypts(cv::Size(1,nparts));
for (int n = 0; n < nparts; ++n) {
const cv::Point centroid = (parts_[n].tl() + parts_[n].br())*0.5;
xpts(n) = centroid.x;
ypts(n) = centroid.y;
}
cv::Scalar xmean, ymean, xstd, ystd;
cv::meanStdDev(xpts, xmean, xstd);
cv::meanStdDev(ypts, ymean, ystd);
return cv::Rect(xmean(0)-1.5*xstd(0), ymean(0)-1.5*ystd(0), 3*xstd(0), 3*ystd(0));
}
};

#endif /* CANDIDATE_HPP_ */
15 changes: 8 additions & 7 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<manifest>
<description brief="thing">
THING
<package>
<description brief="Parts-based object recognition">
This package provides an implementation of parts-based object recognition
using mixtures of deformable parts, inspired by the works of Deva Ramanan.
</description>
<author>Not me!</author>
<license>Driver's</license>
<review status="unreviewed" notes="Yeah, right."/>
<author>Hilton Bristow</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>

<export>
<cpp cflags="-I${prefix}/include"
lflags="-L${prefix}/lib -lobject_recognition_by_parts"/>
</export>
</manifest>
</package>
1 change: 1 addition & 0 deletions src/Visualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void Visualize::candidates(const Mat& im, const vectorCandidate& candidates, int
rectangle(canvas, box, colors[p], LINE_THICKNESS);
if (display_confidence) putText(canvas, confidence, Point(box.x, box.y-5), FONT_HERSHEY_SIMPLEX, 0.5f, black, 2);
}
rectangle(canvas, candidate.boundingBoxNorm(), Scalar(255, 0, 0), LINE_THICKNESS);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int main(int argc, char** argv) {
Mat im = imread(argv[2]);
if (argc == 4) {
depth = imread(argv[3], CV_LOAD_IMAGE_ANYDEPTH);
// convert the depth image from mm to m
depth = depth / 1000.0f;
}

Expand All @@ -107,7 +108,7 @@ int main(int argc, char** argv) {
if (candidates.size() > 0) {
Mat canvas;
Candidate::sort(candidates);
visualize.candidates(im, candidates, canvas, true);
visualize.candidates(im, candidates, 1, canvas, true);
visualize.image(canvas);
waitKey();
}
Expand Down

0 comments on commit 46bb69c

Please sign in to comment.