Browse Source

Trapez skalierung (mit fehlern?)

master
Julian Graf 2 years ago
parent
commit
c00a7336c7
2 changed files with 35 additions and 7 deletions
  1. 29
    6
      src/ofApp.cpp
  2. 6
    1
      src/ofApp.h

+ 29
- 6
src/ofApp.cpp View File

ofSetColor(color); ofSetColor(color);
ofDrawRectangle(webcam.getWidth(), 0, 128, 128); ofDrawRectangle(webcam.getWidth(), 0, 128, 128);
if (color_picked == 1 && key_pressed == 0) { if (color_picked == 1 && key_pressed == 0) {
SetCursorPos((center.x - x_offset) * x_scale, (center.y - y_offset) * y_scale);
scaleTrapeze();
scaleRectangel();
SetCursorPos(cp_cursor_position.x, cp_cursor_position.y);
} }
} }
if (calibrated == 4) { if (calibrated == 4) {
color = webcam.getPixels().getColor(x, y); color = webcam.getPixels().getColor(x, y);
printf("%i, %i, %i\n", color.r, color.g, color.b); printf("%i, %i, %i\n", color.r, color.g, color.b);
printf("%f, %f, %f, %f \n", y_offset, y_scale, x_offset, x_scale);
color_picked = 1; color_picked = 1;
} }
if (calibrated != 4) {
if (calibrated != 4 && key_pressed == 0) {
if (calibrated == 0) { if (calibrated == 0) {
GetCursorPos(&cp_top_left); GetCursorPos(&cp_top_left);
} }
} }
if (calibrated == 3) { if (calibrated == 3) {
GetCursorPos(&cp_bottom_left); GetCursorPos(&cp_bottom_left);
y_offset = (cp_top_left.y + cp_top_right.y) / 2.0;

y_scale = 1080 / ((cp_bottom_left.y + cp_bottom_right.y) / 2.0);


x_offset = (cp_top_left.x + cp_bottom_left.x) / 2.0; x_offset = (cp_top_left.x + cp_bottom_left.x) / 2.0;


x_scale = 1920 / ((cp_top_right.x + cp_bottom_right.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);
} }
calibrated++; calibrated++;
} }
void ofApp::dragEvent(ofDragInfo dragInfo){ void ofApp::dragEvent(ofDragInfo dragInfo){


} }


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));
}
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));
}
}

void ofApp::scaleRectangel(void) {
cp_cursor_position.x = center.x * x_scale - x_offset;
cp_cursor_position.y = center.y * y_scale - y_offset;
}

+ 6
- 1
src/ofApp.h View File

void windowResized(int w, int h); void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo); void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg); void gotMessage(ofMessage msg);
void scaleRectangel(void);
void scaleTrapeze(void);


ofVideoGrabber webcam; ofVideoGrabber webcam;
ofxCv::ContourFinder contour; ofxCv::ContourFinder contour;
float y_offset; float y_offset;
float x_scale; float x_scale;
float x_offset; float x_offset;
float left_pitch;
float right_pitch;
float middle;
POINT cp_top_left, cp_top_right, cp_bottom_left, cp_bottom_right;
POINT cp_top_left, cp_top_right, cp_bottom_left, cp_bottom_right, cp_cursor_position;


}; };

Loading…
Cancel
Save