Projektdateien hinzufügen.

This commit is contained in:
grafj
2022-05-05 14:45:14 +02:00
parent 3918f00df8
commit 3f73c10dee
8 changed files with 1972 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
+135
View File
@@ -0,0 +1,135 @@
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
webcam.setup(1280, 720);
contour.setMinAreaRadius(1);
contour.setMaxAreaRadius(5);
color_red_laser.set(185, 160, 160);
calibrated = 0;
key_pressed = 0;
}
//--------------------------------------------------------------
void ofApp::update(){
webcam.update();
if (webcam.isFrameNew()) {
contour.setTargetColor(color);
contour.setThreshold(30);
contour.findContours(webcam);
selection = 0;
if (contour.size() != 0) {
for (i = 1; i < contour.size(); i++) {
if (contour.getContourArea(i) > contour.getContourArea(selection)) {
selection = i;
}
}
if ((color_picked == 1) && (contour.getContourArea(selection) != 0)) {
center = contour.getCenter(selection);
}
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
webcam.draw(0, 0);
contour.draw();
ofFill();
ofSetColor(color);
ofDrawRectangle(webcam.getWidth(), 0, 128, 128);
if (color_picked == 1 && key_pressed == 0) {
SetCursorPos((center.x - x_offset) * x_scale, (center.y - y_offset) * y_scale);
}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
key_pressed = 1;
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
key_pressed = 0;
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
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);
printf("%i, %i, %i\n", color.r, color.g, color.b);
color_picked = 1;
}
if (calibrated != 4) {
if (calibrated == 0) {
GetCursorPos(&cp_top_left);
}
if (calibrated == 1) {
GetCursorPos(&cp_top_right);
}
if (calibrated == 2) {
GetCursorPos(&cp_bottom_right);
}
if (calibrated == 3) {
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_scale = 1920 / ((cp_top_right.x + cp_bottom_right.x) / 2.0);
}
calibrated++;
}
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include "ofMain.h"
#include "ofxOpenCv.h"
#include "ofxCv.h"
#include "windows.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofVideoGrabber webcam;
ofxCv::ContourFinder contour;
cv::Point2f center;
ofColor color;
ofColor color_red_laser;
int color_picked;
int key_pressed;
int i;
int biggest_contour;
unsigned int selection;
int calibrated;
float y_scale;
float y_offset;
float x_scale;
float x_offset;
POINT cp_top_left, cp_top_right, cp_bottom_left, cp_bottom_right;
};