|
|
@ -14,14 +14,15 @@ using namespace std; |
|
|
|
|
|
|
|
|
class Traite_image { |
|
|
class Traite_image { |
|
|
public: |
|
|
public: |
|
|
const static int SENSITIVITY_VALUE = 10; |
|
|
const static int THRESHOLD_DETECT_SENSITIVITY = 10; |
|
|
const static int BLUR_SIZE = 5; |
|
|
const static int BLUR_SIZE = 5; |
|
|
|
|
|
const static int THRESHOLD_MOV = 5; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat prev; |
|
|
Mat prev; |
|
|
Mat last_T; |
|
|
Mat last_T; |
|
|
bool first = true; |
|
|
bool first = true; |
|
|
int resize_f = 1; |
|
|
int resize_f = 2; |
|
|
|
|
|
|
|
|
int theObject[2] = {0,0}; |
|
|
int theObject[2] = {0,0}; |
|
|
Rect objectBoundingRectangle = Rect(0,0,0,0); |
|
|
Rect objectBoundingRectangle = Rect(0,0,0,0); |
|
|
@ -138,10 +139,10 @@ class Traite_image { |
|
|
// Subtract the 2 last frames and threshold them
|
|
|
// Subtract the 2 last frames and threshold them
|
|
|
Mat thres; |
|
|
Mat thres; |
|
|
absdiff(prev_grey,cur_grey,thres); |
|
|
absdiff(prev_grey,cur_grey,thres); |
|
|
threshold(thres, thres, SENSITIVITY_VALUE, 255, THRESH_BINARY); |
|
|
threshold(thres, thres, THRESHOLD_DETECT_SENSITIVITY, 255, THRESH_BINARY); |
|
|
// Blur to eliminate noise
|
|
|
// Blur to eliminate noise
|
|
|
blur(thres, thres, Size(BLUR_SIZE, BLUR_SIZE)); |
|
|
blur(thres, thres, Size(BLUR_SIZE, BLUR_SIZE)); |
|
|
threshold(thres, thres, SENSITIVITY_VALUE, 255, THRESH_BINARY); |
|
|
threshold(thres, thres, THRESHOLD_DETECT_SENSITIVITY, 255, THRESH_BINARY); |
|
|
|
|
|
|
|
|
//notice how we use the '&' operator for objectDetected and output. This is because we wish
|
|
|
//notice how we use the '&' operator for objectDetected and output. This is because we wish
|
|
|
//to take the values passed into the function and manipulate them, rather than just working with a copy.
|
|
|
//to take the values passed into the function and manipulate them, rather than just working with a copy.
|
|
|
@ -195,10 +196,10 @@ class Traite_image { |
|
|
split(flow, flow_coord); |
|
|
split(flow, flow_coord); |
|
|
cartToPolar(flow_coord[0], flow_coord[1], flow_norm, angle); |
|
|
cartToPolar(flow_coord[0], flow_coord[1], flow_norm, angle); |
|
|
|
|
|
|
|
|
//threshold(flow_norm, flow_norm, SENSITIVITY_VALUE, 255, THRESH_BINARY);
|
|
|
//threshold(flow_norm, flow_norm, THRESHOLD_DETECT_SENSITIVITY, 255, THRESH_BINARY);
|
|
|
// Blur to eliminate noise
|
|
|
// Blur to eliminate noise
|
|
|
blur(flow_norm, flow_norm, Size(BLUR_SIZE, BLUR_SIZE)); |
|
|
blur(flow_norm, flow_norm, Size(BLUR_SIZE, BLUR_SIZE)); |
|
|
threshold(flow_norm, flow_norm, SENSITIVITY_VALUE, 255, THRESH_BINARY); |
|
|
threshold(flow_norm, flow_norm, THRESHOLD_DETECT_SENSITIVITY, 255, THRESH_BINARY); |
|
|
flow_norm.convertTo(flow_norm, CV_8U); |
|
|
flow_norm.convertTo(flow_norm, CV_8U); |
|
|
|
|
|
|
|
|
bool objectDetected = false; |
|
|
bool objectDetected = false; |
|
|
@ -236,11 +237,6 @@ class Traite_image { |
|
|
//write the position of the object to the screen
|
|
|
//write the position of the object to the screen
|
|
|
putText(output,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2); |
|
|
putText(output,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void get_norm(Mat coord, Mat &norm) |
|
|
|
|
|
{ |
|
|
|
|
|
//for(i=0; i<
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline bool isFlowCorrect(Point2f u) |
|
|
inline bool isFlowCorrect(Point2f u) |
|
|
@ -256,11 +252,11 @@ class Traite_image { |
|
|
|
|
|
|
|
|
geometry_msgs::Twist twist = geometry_msgs::Twist(); |
|
|
geometry_msgs::Twist twist = geometry_msgs::Twist(); |
|
|
|
|
|
|
|
|
if(centre_rect.x < centre_image.x) |
|
|
if(centre_rect.x < centre_image.x-THRESHOLD_MOV) |
|
|
{ |
|
|
{ |
|
|
twist.angular.z = 0.2; |
|
|
twist.angular.z = 0.2; |
|
|
} |
|
|
} |
|
|
else if(centre_rect.x > centre_image.x) |
|
|
else if(centre_rect.x > centre_image.x+THRESHOLD_MOV) |
|
|
{ |
|
|
{ |
|
|
twist.angular.z = -0.2; |
|
|
twist.angular.z = -0.2; |
|
|
} |
|
|
} |
|
|
|