int main(int argc, char * argv[]) { char imgFilePath[100]; char conf[100]; strcpy(conf,"./config.txt"); char tmpDirPath[MAX_PATH+1]; // CT framework CompressiveTracker ct; Mat frame; Mat grayImg; Rect box; // [x y width height] tracking position //Check if --challenge was passed as an argument bool challengeMode = false; for (int i = 1; i < argc; i++) { if (strcmp("--challenge", argv[i]) == 0) { challengeMode = true; } } if (challengeMode) { //load region, images and prepare for output VOT vot("region.txt", "images.txt", "output.txt"); Rect box = vot.getInitRectangle(); //output init also bbox vot.outputBoundingBox(box); vot.getNextImage(frame); cvtColor(frame, grayImg, CV_RGB2GRAY); ct.init(grayImg, box); while (vot.getNextImage(frame) == 1){ cvtColor(frame, grayImg, CV_RGB2GRAY); ct.processFrame(grayImg, box);// Process frame vot.outputBoundingBox(box); } return 0; } vector <string> imgNames; readConfig(conf,imgFilePath,box); readImageSequenceFiles(imgFilePath,imgNames); sprintf(tmpDirPath, "%s/", imgFilePath); imgNames[0].insert(0,tmpDirPath); frame = imread(imgNames[0]); cvtColor(frame, grayImg, CV_RGB2GRAY); ct.init(grayImg, box); char strFrame[20]; FILE* resultStream; resultStream = fopen("TrackingResults.txt", "w"); fprintf (resultStream,"%i %i %i %i\n",(int)box.x,(int)box.y,(int)box.width,(int)box.height); for(int i = 1; i < imgNames.size()-1; i ++) { sprintf(tmpDirPath, "%s/", imgFilePath); imgNames[i].insert(0,tmpDirPath); frame = imread(imgNames[i]);// get frame cvtColor(frame, grayImg, CV_RGB2GRAY); ct.processFrame(grayImg, box);// Process frame rectangle(frame, box, Scalar(200,0,0),2);// Draw rectangle fprintf (resultStream,"%i %i %i %i\n",(int)box.x,(int)box.y,(int)box.width,(int)box.height); sprintf(strFrame, "#%d ",i) ; putText(frame,strFrame,cvPoint(0,20),2,1,CV_RGB(25,200,25)); imshow("CT", frame);// Display waitKey(1); } fclose(resultStream); return 0; }
int main(int argc, char * argv[]) { //init UART senderInit(); VideoCapture capture; capture.open(0); // Init camera if (!capture.isOpened()) { cout << "capture device failed to open!" << endl; return 1; } namedWindow("CT", CV_WINDOW_NORMAL); setWindowProperty("CT", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); // CT framework CompressiveTracker ct; capture.set(CV_CAP_PROP_FRAME_WIDTH, 320); capture.set(CV_CAP_PROP_FRAME_HEIGHT, 240); //box Init box = Rect(130, 130, 60, 70);//Rect(x,y,width,height) int x0=box.x; int y0=box.y; int dx=0,dy=0; // Run-time if(!open_error_flag) write(fd,unlock, strlen(unlock)); while(capture.read(frame)) { if(first_flag){ cvtColor(frame, first_frame, CV_RGB2GRAY); first_flag=0; } skinmask = cvCreateMat(frame.rows, frame.cols, CV_8UC1); // get frame cvtColor(frame, current_gray, CV_RGB2GRAY); absdiff(first_frame,current_gray,fore_frame); //imshow("foreFrame",fore_frame); if(!gotHand){ gotHand=getHand(); if(gotHand){ ctInitFlag=1; } if ((c = waitKey(15)) == 27){ return 0; } continue; } // Process Frame skintracker(frame,skinmask); fore_frame = fore_frame.mul(skinmask); // CT initialization if(ctInitFlag){ ct.init(fore_frame, box); ctInitFlag=0; } //imshow("fore&skinmasked", fore_frame); ct.processFrame(fore_frame, box); rectangle(frame, box, Scalar(rgb_b,rgb_g,rgb_r)); // Display flip(frame, frame, 1); imshow("CT", frame); dx=x0-box.x; dy=y0-box.y; getGasValue(dy); getDirValue(dx); calControlStr(gasValue,dirValue); sendControlStr(); if ((c = waitKey(15)) == 27){ if(!open_error_flag) write(fd,lock, strlen(lock)); sleep(1); break; } } return 0; }