Skip to content

Commit

Permalink
tweetstache.js now calls stache successfully
Browse files Browse the repository at this point in the history
* What is needed now is the right trigger event
  • Loading branch information
Jason Kridner committed Dec 20, 2012
1 parent 910ca5f commit 1fcb6f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
14 changes: 8 additions & 6 deletions stache.cpp
Expand Up @@ -14,7 +14,7 @@
using namespace std;
using namespace cv;

string copyright = "\
const char copyright[] = "\
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. \n\
\n\
By downloading, copying, installing or using the software you agree to this license.\n\
Expand Down Expand Up @@ -93,14 +93,14 @@ int main(int argc, const char** argv) {
if(argc > 7) camFPS = atoi(argv[7]);

//-- 0. Print the copyright
cout << copyright;
fprintf(stderr, "%s", copyright);

//-- 1. Load the cascade
if( !face_cascade.load(face_cascade_name) ){ printf("--(!)Error loading\n"); return -1; };
if( !face_cascade.load(face_cascade_name) ){ fprintf(stderr, "--(!)Error loading\n"); return -1; };

//-- 1a. Load the mustache mask
mask = cvLoadImage(stacheMaskFile);
if(!mask) { printf("Could not load %s\n", stacheMaskFile); exit(-1); }
if(!mask) { fprintf(stderr, "Could not load %s\n", stacheMaskFile); exit(-1); }

//-- 2. Read the video stream
capture = cvCaptureFromCAM(numCamera);
Expand All @@ -117,7 +117,7 @@ int main(int argc, const char** argv) {
if(!frame.empty()) {
detectAndDisplay( frame );
} else {
printf(" --(!) No captured frame -- Break!"); break;
fprintf(stderr, " --(!) No captured frame -- Break!"); break;
}

if(int c = inputAvailable()) {
Expand Down Expand Up @@ -170,8 +170,10 @@ void saveFrame(Mat frame) {
IplImage iplFrame = frame;
sprintf(filename, "captured%03d.jpg", savedFrames);
cvSaveImage(filename, &iplFrame);
printf("Saved %s\n", filename);
fprintf(stdout, "{\"tweet\":\"New BeagleStache captured!\",\"filename\":\"%s\"}\n", filename);
fflush(stdout);
savedFrames++;
if(savedFrames >= 1000) savedFrames = 0;
}

int inputAvailable()
Expand Down
25 changes: 22 additions & 3 deletions tweetstache.js
Expand Up @@ -104,6 +104,25 @@ function sendTweet(tweet, photoName) {
request.end();
};

var photoName = 'captured000.jpg';
var tweet = 'Test tweet from tweetstache.js';
sendTweet(tweet, photoName);
function stacheMessage(data) {
//console.log('stacheMessage = ' + data);
try {
data = JSON.parse(data);
if(data.tweet && data.filename) {
console.log('stacheMessage = ' + JSON.stringify(data));
//sendTweet(data.tweet, data.filename);
}
} catch(ex) {
}
};
var stache = child_process.spawn('./stache', [], {stdio:['pipe', 'pipe', process.stderr]});
stache.stdout.setEncoding('ascii');
stache.stdout.on('data', stacheMessage);

function requestStache() {
console.log('requestStache');
stache.stdin.write('s');
};

setInterval(requestStache, 5000);

0 comments on commit 1fcb6f5

Please sign in to comment.