Skip to content

Instantly share code, notes, and snippets.

@AlexAbraham1
Created July 17, 2014 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexAbraham1/24315d90ae9d4d6c1277 to your computer and use it in GitHub Desktop.
Save AlexAbraham1/24315d90ae9d4d6c1277 to your computer and use it in GitHub Desktop.
#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() );
return 0;
}
#ifdef TARGET_ANDROID
#include <jni.h>
//========================================================================
extern "C"{
void Java_cc_openframeworks_OFAndroid_init( JNIEnv* env, jobject thiz ){
main();
}
}
#endif
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofBackground(255, 255, 255);
ofSetLogLevel (OF_LOG_VERBOSE);
screenWidth = ofGetScreenWidth();
screenHeight = ofGetScreenHeight();
// this makes the camera directly return grayscale image, faster!
grabber.setPixelFormat(OF_PIXELS_MONO);
grabber.initGrabber(screenWidth, screenHeight);
//gray.allocate(grabber.getWidth(),grabber.getHeight());
bg.allocate(grabber.getWidth(), grabber.getHeight());
//diff.allocate(grabber.getWidth(),grabber.getHeight());
one_second_time = ofGetSystemTime();
camera_fps = 0;
frames_one_sec = 0;
captureBg = false;
captureBgCount = 3;
circleRadius = 3;
}
//--------------------------------------------------------------
void ofApp::update() {
grabber.update();
if (grabber.isFrameNew()) {
frames_one_sec++;
if (ofGetSystemTime() - one_second_time >= 1000) {
camera_fps = frames_one_sec;
frames_one_sec = 0;
one_second_time = ofGetSystemTime();
}
//gray.setFromPixels(grabber.getPixels(),grabber.getWidth(),grabber.getHeight());
if (captureBg) {
if (captureBgCount == 3) {
captureBgCount = 0;
bg = gray;
captureBg = true;
gray.absDiff(bg);
} else {
captureBgCount++;
}
}
//gray.threshold(70);
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofSetHexColor(0xFFFFFF);
//gray.draw(0,0);
grabber.getTextureReference().drawSubsection(0, 0, screenWidth, screenHeight, 0, 0);
// int x = (screenWidth/2) + circleRadius;
// int y = circleRadius;
// while (x + circleRadius < screenWidth) {
// while (y + circleRadius < screenHeight) {
// ofColor c = grabber.getPixelsRef().getColor(x-(screenWidth/2), y);
// ofSetColor(c);
// ofCircle(x, y, circleRadius);
// y += circleRadius;
// }
// x += circleRadius;
// }
ofColor c2 = grabber.getPixelsRef().getColor(600,600);
ofSetColor(c2);
ofCircle(30,30,30);
// ofSetColor(0x000000);
// ofDrawBitmapString("screenWidth: " + screenWidth, 700, 700);
// ofDrawBitmapString("screenHeight: " + screenHeight, 700 , 720);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key) {
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h) {
}
//--------------------------------------------------------------
void ofApp::touchDown(int x, int y, int id) {
}
//--------------------------------------------------------------
void ofApp::touchMoved(int x, int y, int id) {
}
//--------------------------------------------------------------
void ofApp::touchUp(int x, int y, int id) {
}
//--------------------------------------------------------------
void ofApp::touchDoubleTap(int x, int y, int id) {
}
//--------------------------------------------------------------
void ofApp::touchCancelled(int x, int y, int id) {
}
//--------------------------------------------------------------
void ofApp::swipe(ofxAndroidSwipeDir swipeDir, int id) {
}
//--------------------------------------------------------------
void ofApp::pause() {
}
//--------------------------------------------------------------
void ofApp::stop() {
}
//--------------------------------------------------------------
void ofApp::resume() {
}
//--------------------------------------------------------------
void ofApp::reloadTextures() {
}
//--------------------------------------------------------------
bool ofApp::backPressed() {
return false;
}
//--------------------------------------------------------------
void ofApp::okPressed() {
}
//--------------------------------------------------------------
void ofApp::cancelPressed() {
}
#pragma once
#include "ofMain.h"
#include "ofxAndroid.h"
#include "ofxOpenCv.h"
class ofApp : public ofxAndroidApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void windowResized(int w, int h);
void touchDown(int x, int y, int id);
void touchMoved(int x, int y, int id);
void touchUp(int x, int y, int id);
void touchDoubleTap(int x, int y, int id);
void touchCancelled(int x, int y, int id);
void swipe(ofxAndroidSwipeDir swipeDir, int id);
void pause();
void stop();
void resume();
void reloadTextures();
bool backPressed();
void okPressed();
void cancelPressed();
ofVideoGrabber grabber;
ofxCvGrayscaleImage gray, bg;//, diff;
bool captureBg;
int one_second_time;
int camera_fps;
int frames_one_sec;
int captureBgCount;
int circleRadius;
int screenWidth;
int screenHeight;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment