Browse Source

Convert to HSV (ohen tolle filterung)

Mouse Click mit Pfeiltasten
Coole_verbesserung
Julian Graf 2 years ago
parent
commit
ee084dd3b9
2 changed files with 30 additions and 5 deletions
  1. 27
    5
      src/ofApp.cpp
  2. 3
    0
      src/ofApp.h

+ 27
- 5
src/ofApp.cpp View File

webcam.update(); webcam.update();


if (webcam.isFrameNew()) { if (webcam.isFrameNew()) {

rgb_immage.setFromPixels(webcam.getPixels());
rgb_immage.blurGaussian(5);
hsv_immage = rgb_immage;
hsv_immage.convertRgbToHsv();

contour.setTargetColor(color); contour.setTargetColor(color);
contour.setThreshold(30); contour.setThreshold(30);
contour.findContours(webcam);
contour.findContours(hsv_immage);
selection = 0; selection = 0;
if (contour.size() != 0) { if (contour.size() != 0) {
for (i = 1; i < contour.size(); i++) { for (i = 1; i < contour.size(); i++) {
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::draw(){ void ofApp::draw(){
ofSetColor(255); ofSetColor(255);
webcam.draw(0, 0);
rgb_immage.draw(0, 0);


contour.draw(); contour.draw();
ofFill(); ofFill();
ofSetColor(color); 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_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_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_right.x, cp_bottom_right.y, cp_bottom_left.x, cp_bottom_left.y);
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::keyPressed(int key){ void ofApp::keyPressed(int key){
key_pressed = 1; 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){ void ofApp::keyReleased(int key){
key_pressed = 0; 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);
}
} }


//-------------------------------------------------------------- //--------------------------------------------------------------


//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::mousePressed(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("%i, %i, %i\n", color.r, color.g, color.b);
printf("%f, %f, %f, %f \n", y_offset, y_scale, x_offset, x_scale); printf("%f, %f, %f, %f \n", y_offset, y_scale, x_offset, x_scale);
color_picked = 1; color_picked = 1;

+ 3
- 0
src/ofApp.h View File

void scaleTrapeze(void); void scaleTrapeze(void);


ofVideoGrabber webcam; ofVideoGrabber webcam;
ofxCvColorImage rgb_immage;
ofxCvColorImage hsv_immage;
ofxCv::ContourFinder contour; ofxCv::ContourFinder contour;
cv::Point2f center_trapeze; cv::Point2f center_trapeze;
cv::Point2f center_rect; cv::Point2f center_rect;
int biggest_contour; int biggest_contour;
unsigned int selection; unsigned int selection;
int calibrated; int calibrated;
int select_colour;
float y_scale; float y_scale;
float y_offset; float y_offset;
float x_scale; float x_scale;

Loading…
Cancel
Save