From e899d382258e34ef4905e12b492c0864ae209e04 Mon Sep 17 00:00:00 2001 From: Andrew Leifer Date: Thu, 11 Dec 2014 18:46:49 -0500 Subject: [PATCH] user can specify desired roi. compiles. records. tested. --- MyLibs/Talk2FrameGrabber.cpp | 5 +++-- MyLibs/Talk2FrameGrabber.h | 2 +- MyLibs/WormAnalysis.c | 7 ++++++- MyLibs/experiment.c | 40 ++++++++++++++++++++++++++++++++---- MyLibs/experiment.h | 3 +++ calibrateFG.cpp | 2 +- main.cpp | 22 ++++++++++++-------- 7 files changed, 63 insertions(+), 18 deletions(-) diff --git a/MyLibs/Talk2FrameGrabber.cpp b/MyLibs/Talk2FrameGrabber.cpp index 697ee9d..e6b86e3 100644 --- a/MyLibs/Talk2FrameGrabber.cpp +++ b/MyLibs/Talk2FrameGrabber.cpp @@ -73,11 +73,12 @@ FrameGrabber* CreateFrameGrabberObject(){ * and prepares the FrameGrabber for Acuisiation * */ -FrameGrabber* TurnOnFrameGrabber(){ +FrameGrabber* TurnOnFrameGrabber(int desiredWidth, int desiredHeight){ FrameGrabber* fg= CreateFrameGrabberObject(); InitializeFrameGrabber(fg); //FrameGrabberSetRegionOfInterest(fg,0,127,1024,768); - //FrameGrabberSetRegionOfInterest(fg,0,0,1024,768); + + FrameGrabberSetRegionOfInterest(fg,0,0,desiredWidth,desiredHeight); PrepareFrameGrabberForAcquire(fg); return fg; } diff --git a/MyLibs/Talk2FrameGrabber.h b/MyLibs/Talk2FrameGrabber.h index 22d1ae3..dac4daf 100644 --- a/MyLibs/Talk2FrameGrabber.h +++ b/MyLibs/Talk2FrameGrabber.h @@ -94,7 +94,7 @@ FrameGrabber* CreateFrameGrabberObject(); * and prepares the FrameGrabber for Acuisiation * */ -FrameGrabber* TurnOnFrameGrabber(); +FrameGrabber* TurnOnFrameGrabber(int desiredWidth, int desiredHeight); /* * Initializes the frame grabber with a fg object diff --git a/MyLibs/WormAnalysis.c b/MyLibs/WormAnalysis.c index 6acbf43..6262c9c 100644 --- a/MyLibs/WormAnalysis.c +++ b/MyLibs/WormAnalysis.c @@ -1091,12 +1091,17 @@ int CreateWormHUDS(IplImage* TempImage, WormAnalysisData* Worm, WormAnalysisPara //cvDrawContours(TempImage, Worm->Boundary, cvScalar(255,0,0),cvScalar(0,255,0),100); DrawSequence(&TempImage,Worm->Boundary); - + // DrawSequence(&TempImage,Worm->Segmented->LeftBound); // DrawSequence(&TempImage,Worm->Segmented->RightBound); + if (!(Worm->Tail==NULL) && !(Worm->Head==NULL)) { + + cvCircle(TempImage,*(Worm->Tail),CircleDiameterSize,cvScalar(255,255,255),1,CV_AA,0); cvCircle(TempImage,*(Worm->Head),CircleDiameterSize/2,cvScalar(255,255,255),1,CV_AA,0); + + } /** Prepare Text **/ CvFont font; diff --git a/MyLibs/experiment.c b/MyLibs/experiment.c index e0fe6d0..60dcb90 100644 --- a/MyLibs/experiment.c +++ b/MyLibs/experiment.c @@ -119,6 +119,9 @@ Experiment* CreateExperimentStruct() { /** Input Dimensions **/ exp->inputWidth=0; exp->inputHeight=0; + exp->desiredInputSizeProvided=0; // 1 means the user provided only a width or height, 2 means the user provided both a width and a height + exp->desiredInputWidth=0; + exp->desiredInputHeight=0; /** FrameGrabber Input **/ exp->fg = NULL; @@ -234,6 +237,9 @@ void displayHelp() { printf("\t-t\n\t\tUse USB stage tracker.\n\n"); printf("\t-x\n\tx 512\t Target x position of worm for stage feedback loop. 0 is left.\n\n"); printf("\t-y\n\ty 384\t Target y position of worm for stage feedback loop. 0 is top.\n\n"); + printf("\t-w 1088 \n\t\t Set the desired camera ROI width to 1088 (note this only works for the framegrabber) and must be consistent with pylon.\n\n"); + printf("\t-h 1088 \n\t\t Set the desired camera ROI height to 1088 (note this only works for the framegrabber) and must be consistent with pylon.\n\n"); + printf( "\t-p protocol.yml\n\t\tIlluminate according to a YAML protocol file.\n\n"); printf("\t-?\n\t\tDisplay this help.\n\n"); @@ -251,7 +257,7 @@ int HandleCommandLineArguments(Experiment* exp) { opterr = 0; int c; - while ((c = getopt(exp->argc, exp->argv, "sri:d:o:p:gtx:y:?")) != -1) { + while ((c = getopt(exp->argc, exp->argv, "sri:d:o:p:gtx:y:w:h:?")) != -1) { switch (c) { case 'i': /** specify input video file **/ exp->VidFromFile = 1; @@ -327,6 +333,20 @@ int HandleCommandLineArguments(Experiment* exp) { } printf("Stage feedback target y= %d pixels.\n",exp->stageFeedbackTarget.y ); break; + + case 'w': /** Pass in a desired camera input width **/ + if (optarg != NULL) { + exp->desiredInputWidth = atoi(optarg); + exp->desiredInputSizeProvided=exp->desiredInputSizeProvided + 1; + } + break; + + case 'h': /** Pass in a desired camera input width **/ + if (optarg != NULL) { + exp->desiredInputHeight = atoi(optarg); + exp->desiredInputSizeProvided=exp->desiredInputSizeProvided + 1; + } + break; case '?': @@ -1046,12 +1066,24 @@ void RollVideoInput(Experiment* exp) { /** Use source from camera **/ if (exp->UseFrameGrabber) { /**Use Frame Grabber **/ - exp->fg = TurnOnFrameGrabber(); + + if (exp->desiredInputSizeProvided==2){ + // if the user provided a desired width and hegiht + exp->inputWidth=exp->desiredInputWidth; + exp->inputHeight=exp->desiredInputHeight; + + }else{ + + exp->inputWidth=exp->fg->xsize; + exp->inputHeight=exp->fg->ysize; + } + + + exp->fg = TurnOnFrameGrabber(exp->inputWidth, exp->inputHeight); printf("Query frame grabber for size of images..\n"); - exp->inputWidth=exp->fg->xsize; - exp->inputHeight=exp->fg->ysize; + diff --git a/MyLibs/experiment.h b/MyLibs/experiment.h index 678347b..57d983d 100644 --- a/MyLibs/experiment.h +++ b/MyLibs/experiment.h @@ -113,6 +113,9 @@ typedef struct ExperimentStruct{ /** Input Dimensions **/ int inputWidth; int inputHeight; + int desiredInputSizeProvided; // 1 means the user provided only a width or height, 2 means the user provided both a width and a height + int desiredInputWidth; + int desiredInputHeight; /** MostRecently Observed CameraFrameNumber **/ unsigned long lastFrameSeenOutside; diff --git a/calibrateFG.cpp b/calibrateFG.cpp index 8c276c1..f12b11f 100644 --- a/calibrateFG.cpp +++ b/calibrateFG.cpp @@ -522,7 +522,7 @@ int main (int argc, char** argv){ c->LoopsPerPt=20; // Number of frames we use to calibrate a given point /** Start Camera **/ - c->fg= TurnOnFrameGrabber(); + c->fg= TurnOnFrameGrabber(NSIZEX,NSIZEY); /** Set the acquisition timeout to be very long to give the camera time to take long exposures, as is typical with calibration **/ setAcquisitionTimeout(c->fg,200); diff --git a/main.cpp b/main.cpp index b58b778..a5b9752 100644 --- a/main.cpp +++ b/main.cpp @@ -223,7 +223,6 @@ int main (int argc, char** argv){ /** Handle head-tail illumination sweep **/ HandleIlluminationSweep(exp); - /** Load Image into Our Worm Objects **/ @@ -232,36 +231,37 @@ int main (int argc, char** argv){ /** Apply Levels**/ //Note this is slightly redundant with LoadWormImg if (exp->e == 0) exp->e=simpleAdjustLevels(exp->fromCCD->iplimg, exp->Worm->ImgOrig, exp->Params->LevelsMin, exp->Params->LevelsMax); - + TICTOC::timer().tic("EntireSegmentation"); /** Do Segmentation **/ - DoSegmentation(exp); + if (exp->RecordOnly==0) DoSegmentation(exp); TICTOC::timer().toc("EntireSegmentation"); - /** Real-Time Curvature Phase Analysis, and phase induced illumination **/ HandleCurvaturePhaseAnalysis(exp); + /** If the DLP is not displaying right now, than turn off the mirrors */ ClearDLPifNotDisplayingNow(exp); + /* Transform the segmented worm coordinates into DLP space */ /* Note that this is much more computationally efficient than to transform the original image or to transform the resulting illumination pattern */ - + TICTOC::timer().tic("TransformSegWormCam2DLP"); - if (exp->e == 0 && exp->RecordOnly!=0){ + if (exp->e == 0 && exp->RecordOnly==0){ TransformSegWormCam2DLP(exp->Worm->Segmented, exp->segWormDLP,exp->Calib); } TICTOC::timer().toc("TransformSegWormCam2DLP"); /** Handle the Choise of Illumination Protocol Here**/ /** ANDY: write this here **/ - if (exp->RecordOnly!=0) HandleTimedSecondaryProtocolStep(exp->p,exp->Params); - + if (exp->RecordOnly==0) HandleTimedSecondaryProtocolStep(exp->p,exp->Params); + /*** Do Some Illumination ***/ @@ -269,7 +269,7 @@ int main (int argc, char** argv){ SetFrame(exp->forDLP,0); SetFrame(exp->IlluminationFrame,0); - if (exp->e == 0 && exp->RecordOnly!=0) { + if (exp->e == 0 && exp->RecordOnly==0) { if (exp->Params->IllumFloodEverything) { SetFrame(exp->IlluminationFrame,128); // Turn all of the pixels on SetFrame(exp->forDLP,128); // Turn all of the pixels o @@ -301,6 +301,7 @@ int main (int argc, char** argv){ } + TICTOC::timer().tic("SendFrameToDLP"); if (exp->e == 0 && exp->Params->DLPOn && !(exp->SimDLP)) T2DLP_SendFrame((unsigned char *) exp->forDLP->binary, exp->myDLP); // Send image to DLP TICTOC::timer().toc("SendFrameToDLP"); @@ -308,9 +309,12 @@ int main (int argc, char** argv){ /*** DIsplay Some Monitoring Output ***/ if (exp->e == 0) CreateWormHUDS(exp->HUDS,exp->Worm,exp->Params,exp->IlluminationFrame); + + if (exp->e==0 && exp->stageIsPresent==1) MarkRecenteringTarget(exp); + if (exp->e == 0 && EverySoOften(exp->Worm->frameNum,exp->Params->DispRate) ){ TICTOC::timer().tic("DisplayOnScreen"); /** Setup Display but don't actually send to screen **/