Convert to HSV (ohen tolle filterung)
Mouse Click mit Pfeiltasten
This commit is contained in:
parent
5aefc9c0b3
commit
ee084dd3b9
@ -17,9 +17,15 @@ void ofApp::update(){
|
||||
webcam.update();
|
||||
|
||||
if (webcam.isFrameNew()) {
|
||||
|
||||
rgb_immage.setFromPixels(webcam.getPixels());
|
||||
rgb_immage.blurGaussian(5);
|
||||
hsv_immage = rgb_immage;
|
||||
hsv_immage.convertRgbToHsv();
|
||||
|
||||
contour.setTargetColor(color);
|
||||
contour.setThreshold(30);
|
||||
contour.findContours(webcam);
|
||||
contour.findContours(hsv_immage);
|
||||
selection = 0;
|
||||
if (contour.size() != 0) {
|
||||
for (i = 1; i < contour.size(); i++) {
|
||||
@ -39,13 +45,13 @@ void ofApp::update(){
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::draw(){
|
||||
ofSetColor(255);
|
||||
webcam.draw(0, 0);
|
||||
rgb_immage.draw(0, 0);
|
||||
|
||||
contour.draw();
|
||||
|
||||
ofFill();
|
||||
ofSetColor(color);
|
||||
ofDrawRectangle(webcam.getWidth(), 0, 128, 128);
|
||||
ofDrawRectangle(rgb_immage.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);
|
||||
@ -62,11 +68,27 @@ void ofApp::draw(){
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::keyPressed(int key){
|
||||
key_pressed = 1;
|
||||
|
||||
if (key == 57358) {
|
||||
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
|
||||
}
|
||||
else if (key == 57356) {
|
||||
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
|
||||
}
|
||||
else if (key == 57357) {
|
||||
select_colour = select_colour ^ 0x0001;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::keyReleased(int key){
|
||||
key_pressed = 0;
|
||||
if (key == 57358) {
|
||||
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
|
||||
}
|
||||
else if (key == 57356) {
|
||||
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@ -81,8 +103,8 @@ void ofApp::mouseDragged(int x, int y, int button){
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mousePressed(int x, int y, int button) {
|
||||
if (calibrated == 4) {
|
||||
color = webcam.getPixels().getColor(x, y);
|
||||
if (calibrated == 4 && select_colour == 0x0001) {
|
||||
color = hsv_immage.getPixels().getColor(x, y);
|
||||
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;
|
||||
|
@ -30,6 +30,8 @@ class ofApp : public ofBaseApp{
|
||||
void scaleTrapeze(void);
|
||||
|
||||
ofVideoGrabber webcam;
|
||||
ofxCvColorImage rgb_immage;
|
||||
ofxCvColorImage hsv_immage;
|
||||
ofxCv::ContourFinder contour;
|
||||
cv::Point2f center_trapeze;
|
||||
cv::Point2f center_rect;
|
||||
@ -41,6 +43,7 @@ class ofApp : public ofBaseApp{
|
||||
int biggest_contour;
|
||||
unsigned int selection;
|
||||
int calibrated;
|
||||
int select_colour;
|
||||
float y_scale;
|
||||
float y_offset;
|
||||
float x_scale;
|
||||
|
Loading…
x
Reference in New Issue
Block a user