Permalink
Browse files

tweetstache.js now calls stache successfully

* What is needed now is the right trigger event
  • Loading branch information...
1 parent 910ca5f commit 1fcb6f5f3e78cdd53d5b1cdfa83943ad003d647b @jadonk committed Dec 20, 2012
Showing with 30 additions and 9 deletions.
  1. +8 −6 stache.cpp
  2. +22 −3 tweetstache.js
View
14 stache.cpp
@@ -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\
@@ -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);
@@ -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()) {
@@ -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()
View
25 tweetstache.js
@@ -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.