Compare commits
No commits in common. "337f3e25bd0aba44062eec156330b77743efd511" and "8c514a0cc3b5796daf155e861b9d6de12abe9801" have entirely different histories.
337f3e25bd
...
8c514a0cc3
@ -47,9 +47,7 @@ void ofApp::draw(){
|
|||||||
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) {
|
||||||
scaleTrapeze();
|
SetCursorPos((center.x - x_offset) * x_scale, (center.y - y_offset) * y_scale);
|
||||||
scaleRectangel();
|
|
||||||
SetCursorPos(cp_cursor_position.x, cp_cursor_position.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -79,10 +77,9 @@ void ofApp::mousePressed(int x, int y, int button) {
|
|||||||
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 && key_pressed == 0) {
|
if (calibrated != 4) {
|
||||||
if (calibrated == 0) {
|
if (calibrated == 0) {
|
||||||
GetCursorPos(&cp_top_left);
|
GetCursorPos(&cp_top_left);
|
||||||
}
|
}
|
||||||
@ -94,15 +91,14 @@ void ofApp::mousePressed(int x, int y, int button) {
|
|||||||
}
|
}
|
||||||
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 = ofGetScreenWidth() / (cp_bottom_right.x - x_offset);
|
x_scale = 1920 / ((cp_top_right.x + cp_bottom_right.x) / 2.0);
|
||||||
|
|
||||||
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++;
|
||||||
}
|
}
|
||||||
@ -137,22 +133,3 @@ void ofApp::gotMessage(ofMessage msg){
|
|||||||
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;
|
|
||||||
}
|
|
@ -23,8 +23,6 @@ class ofApp : public ofBaseApp{
|
|||||||
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;
|
||||||
@ -41,11 +39,8 @@ class ofApp : public ofBaseApp{
|
|||||||
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, cp_cursor_position;
|
POINT cp_top_left, cp_top_right, cp_bottom_left, cp_bottom_right;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user