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