Revision 186 ofxNCoreVision.cpp
| ofxNCoreVision.cpp (revision 186) | ||
|---|---|---|
| 32 | 32 |
RemoveMenu(hMnu, SC_CLOSE, MF_BYCOMMAND); |
| 33 | 33 |
#endif |
| 34 | 34 |
|
| 35 |
|
|
| 36 |
if(printfToFile) {
|
|
| 37 |
/***************************************************************************************************** |
|
| 38 |
* LOGGING |
|
| 39 |
******************************************************************************************************/ |
|
| 40 |
/* alright first we need to get time and date so our logs can be ordered */ |
|
| 41 |
time ( &rawtime ); |
|
| 42 |
timeinfo = localtime ( &rawtime ); |
|
| 43 |
strftime (fileName,80,"../logs/log_%B_%d_%y_%H_%M_%S.txt",timeinfo); |
|
| 44 |
FILE *stream ; |
|
| 45 |
sprintf(fileName, ofToDataPath(fileName).c_str()); |
|
| 46 |
if((stream = freopen(fileName, "w", stdout)) == NULL){}
|
|
| 47 |
/******************************************************************************************************/ |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
printf("printfToFile %i!\n", printfToFile);
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 | 35 |
//Setup Window Properties |
| 55 | 36 |
ofSetWindowShape(winWidth,winHeight); |
| 56 | 37 |
ofSetVerticalSync(false); //Set vertical sync to false for better performance? |
| ... | ... | |
| 154 | 135 |
filter->bVerticalMirror = XML.getValue("CONFIG:BOOLEAN:VMIRROR",0);
|
| 155 | 136 |
filter->bHorizontalMirror = XML.getValue("CONFIG:BOOLEAN:HMIRROR",0);
|
| 156 | 137 |
|
| 157 |
//Logging |
|
| 158 |
printfToFile = XML.getValue("CONFIG:BOOLEAN:PRINTFTOFILE",0);
|
|
| 159 |
|
|
| 160 | 138 |
//Filters |
| 161 | 139 |
filter->bTrackDark = XML.getValue("CONFIG:BOOLEAN:TRACKDARK", 0);
|
| 162 | 140 |
filter->bHighpass = XML.getValue("CONFIG:BOOLEAN:HIGHPASS",1);
|
| ... | ... | |
| 203 | 181 |
XML.setValue("CONFIG:BOOLEAN:LEARNBG", filter->bLearnBakground);
|
| 204 | 182 |
XML.setValue("CONFIG:BOOLEAN:VMIRROR", filter->bVerticalMirror);
|
| 205 | 183 |
XML.setValue("CONFIG:BOOLEAN:HMIRROR", filter->bHorizontalMirror);
|
| 206 |
XML.setValue("CONFIG:BOOLEAN:PRINTFTOFILE", printfToFile);
|
|
| 207 | 184 |
XML.setValue("CONFIG:BOOLEAN:TRACKDARK", filter->bTrackDark);
|
| 208 | 185 |
XML.setValue("CONFIG:BOOLEAN:HIGHPASS", filter->bHighpass);
|
| 209 | 186 |
XML.setValue("CONFIG:BOOLEAN:AMPLIFY", filter->bAmplify);
|
| ... | ... | |
| 233 | 210 |
* Init Device |
| 234 | 211 |
************************************************/ |
| 235 | 212 |
//Init Device (camera/video) |
| 236 |
void ofxNCoreVision::initDevice(){
|
|
| 237 |
|
|
| 238 |
//save/update log file |
|
| 239 |
if(printfToFile) if((stream = freopen(fileName, "a", stdout)) == NULL){}
|
|
| 240 |
|
|
| 213 |
void ofxNCoreVision::initDevice() |
|
| 214 |
{
|
|
| 241 | 215 |
//Pick the Source - camera or video |
| 242 | 216 |
if (bcamera) |
| 243 | 217 |
{
|
| 244 | 218 |
//check if a firefly, ps3 camera, or other is plugged in |
| 245 | 219 |
#ifdef TARGET_WIN32 |
| 246 | 220 |
/****PS3 - PS3 camera only****/ |
| 247 |
if(ofxPS3::getDeviceCount() > 0 && PS3 == NULL){
|
|
| 221 |
if(ofxPS3::getDeviceCount() > 0 && PS3 == NULL) |
|
| 222 |
{
|
|
| 248 | 223 |
PS3 = new ofxPS3(); |
| 249 | 224 |
PS3->listDevices(); |
| 250 | 225 |
PS3->initPS3(camWidth, camHeight, camRate); |
| ... | ... | |
| 254 | 229 |
return; |
| 255 | 230 |
} |
| 256 | 231 |
/****ffmv - firefly camera only****/ |
| 257 |
else if(ofxffmv::getDeviceCount() > 0 && ffmv == NULL){
|
|
| 232 |
else if(ofxffmv::getDeviceCount() > 0 && ffmv == NULL) |
|
| 233 |
{
|
|
| 258 | 234 |
ffmv = new ofxffmv(); |
| 259 | 235 |
ffmv->listDevices(); |
| 260 | 236 |
ffmv->initFFMV(camWidth,camHeight); |
| ... | ... | |
| 263 | 239 |
camHeight = ffmv->getCamHeight(); |
| 264 | 240 |
return; |
| 265 | 241 |
} |
| 266 |
else if( vidGrabber == NULL ) {
|
|
| 242 |
else if( vidGrabber == NULL ) |
|
| 243 |
{
|
|
| 267 | 244 |
vidGrabber = new ofVideoGrabber(); |
| 268 | 245 |
vidGrabber->listDevices(); |
| 269 | 246 |
vidGrabber->setVerbose(true); |
| ... | ... | |
| 273 | 250 |
camHeight = vidGrabber->height; |
| 274 | 251 |
return; |
| 275 | 252 |
} |
| 276 |
else if( dsvl == NULL) {
|
|
| 253 |
else if( dsvl == NULL) |
|
| 254 |
{
|
|
| 277 | 255 |
dsvl = new ofxDSVL(); |
| 278 | 256 |
dsvl->initDSVL(); |
| 279 | 257 |
printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, dsvl->getCamWidth(), dsvl->getCamHeight());
|
| ... | ... | |
| 282 | 260 |
return; |
| 283 | 261 |
} |
| 284 | 262 |
#else |
| 285 |
if( vidGrabber == NULL ) {
|
|
| 286 |
vidGrabber = new ofVideoGrabber(); |
|
| 287 |
vidGrabber->listDevices(); |
|
| 288 |
vidGrabber->setVerbose(true); |
|
| 289 |
vidGrabber->initGrabber(camWidth,camHeight); |
|
| 290 |
printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, vidGrabber->width, vidGrabber->height);
|
|
| 291 |
camWidth = vidGrabber->width; |
|
| 292 |
camHeight = vidGrabber->height; |
|
| 293 |
return; |
|
| 294 |
} |
|
| 263 |
if( vidGrabber == NULL ) |
|
| 264 |
{
|
|
| 265 |
vidGrabber = new ofVideoGrabber(); |
|
| 266 |
vidGrabber->listDevices(); |
|
| 267 |
vidGrabber->setVerbose(true); |
|
| 268 |
vidGrabber->initGrabber(camWidth,camHeight); |
|
| 269 |
printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, vidGrabber->width, vidGrabber->height);
|
|
| 270 |
camWidth = vidGrabber->width; |
|
| 271 |
camHeight = vidGrabber->height; |
|
| 272 |
return; |
|
| 273 |
} |
|
| 295 | 274 |
#endif |
| 296 |
}else{
|
|
| 297 |
if( vidPlayer == NULL ) {
|
|
| 275 |
} |
|
| 276 |
else |
|
| 277 |
{
|
|
| 278 |
if( vidPlayer == NULL ) |
|
| 279 |
{
|
|
| 298 | 280 |
vidPlayer = new ofVideoPlayer(); |
| 299 | 281 |
vidPlayer->loadMovie( videoFileName ); |
| 300 | 282 |
vidPlayer->play(); |
| ... | ... | |
| 312 | 294 |
*****************************************************************************/ |
| 313 | 295 |
void ofxNCoreVision::_update(ofEventArgs &e) |
| 314 | 296 |
{
|
| 315 |
//save/update log file |
|
| 316 |
if(printfToFile) if((stream = freopen(fileName, "a", stdout)) == NULL){}
|
|
| 317 |
|
|
| 318 |
|
|
| 319 | 297 |
if(exited) return; |
| 320 | 298 |
|
| 321 | 299 |
bNewFrame = false; |
| 322 | 300 |
|
| 323 |
if (bcamera) //if camera |
|
| 301 |
if(bcamera) //if camera |
|
| 324 | 302 |
{
|
| 325 | 303 |
#ifdef TARGET_WIN32 |
| 326 | 304 |
if(PS3!=NULL)//ps3 camera |
| ... | ... | |
| 353 | 331 |
} |
| 354 | 332 |
|
| 355 | 333 |
//if no new frame, return |
| 356 |
if(!bNewFrame){
|
|
| 334 |
if(!bNewFrame) |
|
| 335 |
{
|
|
| 357 | 336 |
return; |
| 358 | 337 |
} |
| 359 | 338 |
else//else process camera frame |
| ... | ... | |
| 413 | 392 |
* Input Device Stuff |
| 414 | 393 |
************************************************/ |
| 415 | 394 |
//get pixels from camera |
| 416 |
void ofxNCoreVision::getPixels(){
|
|
| 417 |
|
|
| 395 |
void ofxNCoreVision::getPixels() |
|
| 396 |
{
|
|
| 418 | 397 |
#ifdef TARGET_WIN32 |
| 419 |
if(PS3!=NULL){
|
|
| 420 |
sourceImg.setFromPixels(PS3->getPixels(), camWidth, camHeight); |
|
| 421 |
//convert to grayscale |
|
| 422 |
processedImg = sourceImg; |
|
| 398 |
if(PS3!=NULL) |
|
| 399 |
{
|
|
| 400 |
//already grayscale |
|
| 401 |
processedImg.setFromPixels(PS3->getPixels(), camWidth, camHeight); |
|
| 423 | 402 |
} |
| 424 |
else if(ffmv != NULL){
|
|
| 403 |
else if(ffmv != NULL) |
|
| 404 |
{
|
|
| 425 | 405 |
processedImg.setFromPixels(ffmv->fcImage[ffmv->getDeviceID()].pData, camWidth, camHeight); |
| 426 | 406 |
} |
| 427 |
else if(vidGrabber != NULL ) {
|
|
| 407 |
else if(vidGrabber != NULL ) |
|
| 408 |
{
|
|
| 428 | 409 |
sourceImg.setFromPixels(vidGrabber->getPixels(), camWidth, camHeight); |
| 429 | 410 |
//convert to grayscale |
| 430 | 411 |
processedImg = sourceImg; |
| ... | ... | |
| 436 | 417 |
//convert to grayscale |
| 437 | 418 |
processedImg = sourceImg; |
| 438 | 419 |
} |
| 439 |
else{//if grayscale
|
|
| 420 |
else |
|
| 421 |
{ //if grayscale
|
|
| 440 | 422 |
processedImg.setFromPixels(dsvl->getPixels(), camWidth, camHeight); |
| 441 | 423 |
} |
| 442 | 424 |
} |
| ... | ... | |
| 540 | 522 |
} |
| 541 | 523 |
} |
| 542 | 524 |
|
| 543 |
void ofxNCoreVision::drawFullMode(){
|
|
| 544 |
|
|
| 525 |
void ofxNCoreVision::drawFullMode() |
|
| 526 |
{
|
|
| 545 | 527 |
ofSetColor(0xFFFFFF); |
| 546 | 528 |
//Draw Background Image |
| 547 | 529 |
background.draw(0, 0); |
| ... | ... | |
| 611 | 593 |
else |
| 612 | 594 |
sprintf(buf, "Could not bind or send TCP to:\nPort: %i", myTUIO.TUIOFlashPort); |
| 613 | 595 |
} |
| 614 |
|
|
| 615 | 596 |
verdana.drawString(buf, 740, 480); |
| 616 | 597 |
} |
| 617 |
|
|
| 618 | 598 |
ofSetColor(0xFF0000); |
| 619 | 599 |
verdana.drawString("Press spacebar to toggle fast mode", 730, 572);
|
| 620 | 600 |
} |
| ... | ... | |
| 625 | 605 |
ofSetColor(0,0,0); |
| 626 | 606 |
ofRect(0,0,ofGetWidth(), ofGetHeight()); |
| 627 | 607 |
//draw outlines |
| 628 |
if (bDrawOutlines){
|
|
| 608 |
if (bDrawOutlines) |
|
| 609 |
{
|
|
| 629 | 610 |
for (int i=0; i<contourFinder.nBlobs; i++) |
| 630 | 611 |
{
|
| 631 | 612 |
contourFinder.blobs[i].drawContours(0,0, camWidth, camHeight+175, ofGetWidth(), ofGetHeight()); |
| ... | ... | |
| 643 | 624 |
//draw text |
| 644 | 625 |
ofSetColor(250,250,250); |
| 645 | 626 |
verdana.drawString("Calc. Time [ms]: " + ofToString(differenceTime,0),10, ofGetHeight() - 70 );
|
| 646 |
if (bcamera){
|
|
| 627 |
if (bcamera) |
|
| 628 |
{
|
|
| 647 | 629 |
verdana.drawString("Camera [fps]: " + ofToString(fps,0),10, ofGetHeight() - 50 );
|
| 648 | 630 |
} |
| 649 |
else {
|
|
| 631 |
else |
|
| 632 |
{
|
|
| 650 | 633 |
verdana.drawString("Video [fps]: " + ofToString(fps,0),10, ofGetHeight() - 50 );
|
| 651 | 634 |
} |
| 652 | 635 |
verdana.drawString("Blob Count: " + ofToString(contourFinder.nBlobs,0),10, ofGetHeight() - 29 );
|
| 653 | 636 |
verdana.drawString("Sending TUIO: " ,10, ofGetHeight() - 9 );
|
| 654 | 637 |
|
| 655 | 638 |
//draw green tuio circle |
| 656 |
if((myTUIO.bIsConnected || myTUIO.bOSCMode) && bTUIOMode)//green = connected |
|
| 657 |
ofSetColor(0x00FF00); |
|
| 639 |
if((myTUIO.bIsConnected || myTUIO.bOSCMode) && bTUIOMode) |
|
| 640 |
ofSetColor(0x00FF00); //green = connected |
|
| 658 | 641 |
else |
| 659 |
ofSetColor(0xFF0000); //red = not connected |
|
| 642 |
ofSetColor(0xFF0000); //red = not connected |
|
| 660 | 643 |
ofFill(); |
| 661 | 644 |
ofCircle(ofGetWidth() - 17 , ofGetHeight() - 10, 5); |
| 662 | 645 |
ofNoFill(); |
| ... | ... | |
| 795 | 778 |
if ( e.key == 'c' && !bCalibration) |
| 796 | 779 |
{
|
| 797 | 780 |
bShowInterface = false; |
| 798 |
//Enter/Exit Calibration |
|
| 781 |
// Enter/Exit Calibration |
|
| 799 | 782 |
bCalibration = true; |
| 800 | 783 |
calib.calibrating = true; |
| 801 | 784 |
tracker.isCalibrating = true; |
| ... | ... | |
| 820 | 803 |
if (showConfiguration) |
| 821 | 804 |
{
|
| 822 | 805 |
controls->mousePressed(e.x, e.y, e.button); //guilistener |
| 823 |
if (e.x > 722 && e.y > 586){ofLaunchBrowser("http://tbeta.nuigroup.com");}
|
|
| 806 |
if (e.x > 722 && e.y > 586) |
|
| 807 |
ofLaunchBrowser("http://tbeta.nuigroup.com");
|
|
| 824 | 808 |
} |
| 825 | 809 |
} |
| 826 | 810 |
|
| ... | ... | |
| 834 | 818 |
* Getters |
| 835 | 819 |
*****************************************************************************/ |
| 836 | 820 |
|
| 837 |
std::map<int, Blob> ofxNCoreVision::getBlobs(){
|
|
| 838 |
|
|
| 821 |
std::map<int, Blob> ofxNCoreVision::getBlobs() |
|
| 822 |
{
|
|
| 839 | 823 |
return tracker.getTrackedBlobs(); |
| 840 | 824 |
} |
| 841 | 825 |
|
| ... | ... | |
| 844 | 828 |
*****************************************************************************/ |
| 845 | 829 |
void ofxNCoreVision::_exit(ofEventArgs &e) |
| 846 | 830 |
{
|
| 847 |
//save/update log file |
|
| 848 |
if((stream = freopen(fileName, "a", stdout)) == NULL){}
|
|
| 849 |
|
|
| 850 | 831 |
saveSettings(); |
| 851 |
|
|
| 852 | 832 |
#ifdef TARGET_WIN32 |
| 853 | 833 |
if(PS3!=NULL) delete PS3; |
| 854 | 834 |
if(ffmv!=NULL) delete ffmv; |
| ... | ... | |
| 858 | 838 |
if(vidGrabber!=NULL) delete vidGrabber; |
| 859 | 839 |
if(vidPlayer !=NULL) delete vidPlayer; |
| 860 | 840 |
// -------------------------------- SAVE STATE ON EXIT |
| 861 |
|
|
| 862 | 841 |
printf("Vision module has exited!\n");
|
| 863 | 842 |
} |
| 864 | 843 |
|
Also available in: Unified diff
