remove opencv_contrib dependancy from planar_tracking.cpp
This commit is contained in:
@@ -12,6 +12,7 @@ void drawBoundingBox(Mat image, vector<Point2f> bb);
|
||||
void drawStatistics(Mat image, const Stats& stats);
|
||||
void printStatistics(string name, Stats stats);
|
||||
vector<Point2f> Points(vector<KeyPoint> keypoints);
|
||||
Rect2d selectROI(const String &video_name, const Mat &frame);
|
||||
|
||||
void drawBoundingBox(Mat image, vector<Point2f> bb)
|
||||
{
|
||||
@@ -56,4 +57,58 @@ vector<Point2f> Points(vector<KeyPoint> keypoints)
|
||||
return res;
|
||||
}
|
||||
|
||||
Rect2d selectROI(const String &video_name, const Mat &frame)
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
Point center;
|
||||
Rect2d box;
|
||||
|
||||
static void mouseHandler(int event, int x, int y, int flags, void *param)
|
||||
{
|
||||
Data *data = (Data*)param;
|
||||
switch( event )
|
||||
{
|
||||
// start to select the bounding box
|
||||
case EVENT_LBUTTONDOWN:
|
||||
data->box = cvRect( x, y, 0, 0 );
|
||||
data->center = Point2f((float)x,(float)y);
|
||||
break;
|
||||
// update the selected bounding box
|
||||
case EVENT_MOUSEMOVE:
|
||||
if(flags == 1)
|
||||
{
|
||||
data->box.width = 2 * (x - data->center.x);
|
||||
data->box.height = 2 * (y - data->center.y);
|
||||
data->box.x = data->center.x - data->box.width / 2.0;
|
||||
data->box.y = data->center.y - data->box.height / 2.0;
|
||||
}
|
||||
break;
|
||||
// cleaning up the selected bounding box
|
||||
case EVENT_LBUTTONUP:
|
||||
if( data->box.width < 0 )
|
||||
{
|
||||
data->box.x += data->box.width;
|
||||
data->box.width *= -1;
|
||||
}
|
||||
if( data->box.height < 0 )
|
||||
{
|
||||
data->box.y += data->box.height;
|
||||
data->box.height *= -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} data;
|
||||
|
||||
setMouseCallback(video_name, Data::mouseHandler, &data);
|
||||
while(waitKey(1) < 0)
|
||||
{
|
||||
Mat draw = frame.clone();
|
||||
rectangle(draw, data.box, Scalar(255,0,0), 2, 1);
|
||||
imshow(video_name, draw);
|
||||
}
|
||||
return data.box;
|
||||
}
|
||||
|
||||
#endif // UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user