|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if ((color_picked == 1) && (contour.getContourArea(selection) != 0)) { |
|
|
if ((color_picked == 1) && (contour.getContourArea(selection) != 0)) { |
|
|
center = contour.getCenter(selection); |
|
|
|
|
|
|
|
|
center_trapeze = contour.getCenter(selection); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ofFill(); |
|
|
ofFill(); |
|
|
ofSetColor(color); |
|
|
ofSetColor(color); |
|
|
ofDrawRectangle(webcam.getWidth(), 0, 128, 128); |
|
|
ofDrawRectangle(webcam.getWidth(), 0, 128, 128); |
|
|
|
|
|
ofDrawLine(cp_top_left.x, cp_top_left.y, cp_top_right.x, cp_top_right.y); |
|
|
|
|
|
ofDrawLine(cp_top_right.x, cp_top_right.y, cp_bottom_right.x, cp_bottom_right.y); |
|
|
|
|
|
ofDrawLine(cp_bottom_right.x, cp_bottom_right.y, cp_bottom_left.x, cp_bottom_left.y); |
|
|
|
|
|
ofDrawLine(cp_bottom_left.x, cp_bottom_left.y, cp_top_left.x, cp_top_left.y); |
|
|
|
|
|
ofDrawLine(middle, cp_top_left.y, middle, cp_bottom_right.y); |
|
|
if (color_picked == 1 && key_pressed == 0) { |
|
|
if (color_picked == 1 && key_pressed == 0) { |
|
|
scaleTrapeze(); |
|
|
scaleTrapeze(); |
|
|
scaleRectangel(); |
|
|
scaleRectangel(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (calibrated == 3) { |
|
|
if (calibrated == 3) { |
|
|
GetCursorPos(&cp_bottom_left); |
|
|
GetCursorPos(&cp_bottom_left); |
|
|
|
|
|
if (cp_top_left.x > cp_bottom_left.x) |
|
|
|
|
|
{ |
|
|
|
|
|
x_offset = cp_bottom_left.x; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
x_offset = cp_top_left.x; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
x_offset = (cp_top_left.x + cp_bottom_left.x) / 2.0; |
|
|
|
|
|
|
|
|
|
|
|
x_scale = ofGetScreenWidth() / (cp_bottom_right.x - x_offset); |
|
|
|
|
|
|
|
|
|
|
|
y_offset = (cp_top_left.y + cp_top_right.y) / 2.0; |
|
|
|
|
|
|
|
|
|
|
|
y_scale = ofGetScreenHeight() / ((cp_bottom_left.y + cp_bottom_right.y) / 2.0 - y_offset); |
|
|
|
|
|
|
|
|
if (cp_top_right.x < cp_bottom_right.x) |
|
|
|
|
|
{ |
|
|
|
|
|
x_scale = ofGetScreenWidth() / (cp_bottom_right.x - x_offset); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
x_scale = ofGetScreenWidth() / (cp_top_right.x - x_offset); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cp_top_left.y > cp_top_right.y) |
|
|
|
|
|
{ |
|
|
|
|
|
y_offset = cp_top_right.y; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
y_offset = cp_top_left.y; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cp_bottom_left.y < cp_bottom_right.y) |
|
|
|
|
|
{ |
|
|
|
|
|
y_scale = ofGetScreenHeight() / (cp_bottom_right.y - y_offset); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
y_scale = ofGetScreenHeight() / (cp_bottom_left.y - y_offset); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("Y:%f \nX:%f\n", y_offset, x_offset); |
|
|
} |
|
|
} |
|
|
calibrated++; |
|
|
calibrated++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ofApp::scaleTrapeze(void) { |
|
|
void ofApp::scaleTrapeze(void) { |
|
|
left_pitch = (cp_top_left.y - cp_bottom_left.y) / (cp_top_left.x - cp_bottom_left.x); |
|
|
|
|
|
right_pitch = (cp_top_right.y - cp_bottom_right.y) / (cp_top_right.x - cp_bottom_right.x); |
|
|
|
|
|
middle = cp_top_right.x - cp_top_left.x; |
|
|
|
|
|
|
|
|
|
|
|
if (center.x > middle) { |
|
|
|
|
|
center.x = center.x + (((center.y - cp_top_right.y) / right_pitch) * ((cp_bottom_right.x - middle) - ((center.y - cp_top_right.y) / right_pitch)) / (center.x - middle)); |
|
|
|
|
|
|
|
|
left_pitch = (float)(cp_bottom_left.y - cp_top_left.y) / (float)(cp_bottom_left.x - cp_top_left.x); |
|
|
|
|
|
right_pitch = (float) (cp_bottom_right.y - cp_top_right.y) / (float)(cp_bottom_right.x - cp_top_right.x); |
|
|
|
|
|
middle = (cp_top_right.x + cp_top_left.x)/2; |
|
|
|
|
|
stringstream out; |
|
|
|
|
|
out.precision(2); |
|
|
|
|
|
out << "Middle:" << middle; |
|
|
|
|
|
string message = out.str(); |
|
|
|
|
|
ofDrawBitmapString(message, 100, 100); |
|
|
|
|
|
out.str(""); |
|
|
|
|
|
out << "rightpitch:" << right_pitch; |
|
|
|
|
|
message = out.str(); |
|
|
|
|
|
ofDrawBitmapString(message, 100, 120); |
|
|
|
|
|
out.str(""); |
|
|
|
|
|
out << "leftpitch:" << left_pitch; |
|
|
|
|
|
message = out.str(); |
|
|
|
|
|
ofDrawBitmapString(message, 100, 140); |
|
|
|
|
|
if (center_trapeze.x > middle) { |
|
|
|
|
|
center_rect.x = center_trapeze.x - (((center_trapeze.y - cp_top_right.y) / right_pitch));// * (((cp_bottom_right.x - middle) - ((center_trapeze.y - cp_top_right.y) / right_pitch)) / (center_trapeze.x - middle))); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
center.x = center.x + (((center.y - cp_top_left.y) / left_pitch) * ((middle - cp_bottom_left.x) - ((center.y - cp_top_left.y) / left_pitch)) / (middle - center.x)); |
|
|
|
|
|
|
|
|
center_rect.x = center_trapeze.x - (((center_trapeze.y - cp_top_left.y) / left_pitch));//* (((middle - cp_bottom_left.x) - ((center_trapeze.y - cp_top_left.y) / left_pitch)) / (middle - center_trapeze.x))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ofApp::scaleRectangel(void) { |
|
|
void ofApp::scaleRectangel(void) { |
|
|
cp_cursor_position.x = center.x * x_scale - x_offset; |
|
|
|
|
|
cp_cursor_position.y = center.y * y_scale - y_offset; |
|
|
|
|
|
|
|
|
cp_cursor_position.x = (center_rect.x - x_offset) * x_scale; |
|
|
|
|
|
cp_cursor_position.y = (center_trapeze.y - y_offset )* y_scale ; |
|
|
|
|
|
stringstream out; |
|
|
|
|
|
out.precision(2); |
|
|
|
|
|
out << "Cursor:" << "x" << cp_cursor_position.x << " | y"<< cp_cursor_position.y; |
|
|
|
|
|
string message = out.str(); |
|
|
|
|
|
ofDrawBitmapString(message, 100, 160); |
|
|
|
|
|
out.str(""); |
|
|
} |
|
|
} |