// startTracking() // void startTracking(IplImage * pImg, CvRect pHandRect,KalmanFilter &kfilter) { float maxVal = 0.f; // Make sure internal data structures have been allocated if( !pHist ) createTracker(pImg); // Create a new hue image updateHueImage(pImg); if(!((pHandRect.x<0)||(pHandRect.y<0)||((pHandRect.x+pHandRect.width)>pImg->width)||((pHandRect.y+pHandRect.height)>pImg->height))) { // Create a histogram representation for the hand cvSetImageROI( pHueImg, pHandRect ); cvSetImageROI( pMask, pHandRect ); cvCalcHist( &pHueImg, pHist, 0, pMask ); cvGetMinMaxHistValue( pHist, 0, &maxVal, 0, 0 ); cvConvertScale( pHist->bins, pHist->bins, maxVal? 255.0/maxVal : 0, 0 ); cvResetImageROI( pHueImg ); cvResetImageROI( pMask ); } // Store the previous hand location prevHandRect =pHandRect; prevHandRect2 =pHandRect; //Pass the hand location to kalman initializer kfilter.predictionBegin(prevHandRect); }
////////////////////////////////// // initAll() // int initAll() { // Create the display window cvNamedWindow( DISPLAY_WINDOW, 1 ); // Initialize tracker pframe=cvQueryFrame(capture); if( !createTracker(pframe) ) return 0; initHandDet("/home/vignesh/Downloads/hand.xml"); //initHandDet1("v.xml"); // Set Camshift parameters setVmin(60); setSmin(50); initface(); return 1; }
////////////////////////////////// // startTracking() // void startTracking(IplImage * pImg, CvRect * pFaceRect) { float maxVal = 0.f; // Make sure internal data structures have been allocated if( !pHist ) createTracker(pImg); // Create a new hue image updateHueImage(pImg); // Create a histogram representation for the face cvSetImageROI( pHueImg, *pFaceRect ); cvSetImageROI( pMask, *pFaceRect ); cvCalcHist( &pHueImg, pHist, 0, pMask ); cvGetMinMaxHistValue( pHist, 0, &maxVal, 0, 0 ); cvConvertScale( pHist->bins, pHist->bins, maxVal? 255.0/maxVal : 0, 0 ); cvResetImageROI( pHueImg ); cvResetImageROI( pMask ); // Store the previous face location prevFaceRect = *pFaceRect; }
int initAll() { initConfiguration(); // cout << "Use webcam? (Y/N)" <<endl; // // char cc = fgetc(stdin); if( !initCapture(true,cam_id)) //!initCapture(cc == 'Y' || cc == 'y',cam_id) ) return 0; if( !initFaceDet((OPENCV_ROOT + "/data/haarcascades/haarcascade_frontalface_default.xml").c_str())) { cerr << "failed initFaceDet with" << OPENCV_ROOT << "/data/haarcascades/haarcascade_frontalface_default.xml" << endl; return 0; } // Startup message tells user how to begin and how to exit printf( "\n********************************************\n" "To exit, click inside the video display,\n" "then press the ESC key\n\n" "Press <ENTER> to begin" "\n********************************************\n" ); fgetc(stdin); // Create the display window cvNamedWindow( DISPLAY_WINDOW, 1 ); // Initialize tracker captureVideoFrame(); if( !createTracker(pfd_pVideoFrameCopy) ) return 0; // Set Camshift parameters setVmin(60); setSmin(50); FdInit(); return 1; }
int main(int argc, char** argv){ int i; unsigned int test_http_buffer = 0; /* Toggle repetitive requests to confirm queuing behavior */ unsigned int test_http_total_requests = 25; /* To run over the request maximum a few times... */ // This value will show with the word "nët" encoded as "n%c3%abt" on the query string char unicode_value[] = "Ech kan Glas iessen, daat deet mir nët wei"; /* Static definition of a group of options (in stack space) */ UASettings settings = {{ {UA_DOCUMENT_PATH, 0, "/virtual/test/C"}, {UA_DOCUMENT_TITLE, 0, "This is a test in C"}, {UA_CUSTOM_DIMENSION, 5, "C library (5)"}, {UA_CUSTOM_DIMENSION, 7, "Custom Dimension 7"}, {UA_CUSTOM_METRIC, 5, "2451"}, /* A numeric string, custom metric index 5 */ {UA_USER_AGENT, 0, "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14"}, {UA_ANONYMIZE_IP, 0, "1"} /* IP anonymization for privacy-aware contexts (e.g. apps in EU) */ }}; /* createTracker() calls malloc for the entire size required by * the tracker; all memory it requires (except for CURL) is * allocated within this call. */ UATracker tracker = createTracker("UA-XXXXX-Y", "abc1234", NULL); /* Override the User Agent HTTP header */ tracker->user_agent = "user_agent_test"; /* Enable queing * This causes all requests to be queued until the "cleanup" phase * of the tracker's life (i.e. at removeTracker() below) */ setTrackerOption(tracker, UA_OPTION_QUEUE, 1); /* Store these options permanently (for the lifetime of the tracker) */ setParameters(tracker, & settings); /* Send a pageview, with no additional options. * Processes only the parameters that are set permanently in the * tracker. */ printf("Sending core pageview\n"); sendTracking(tracker, UA_PAGEVIEW, NULL); UAOptions mobileOptions = {{ {UA_APP_ID, 0, "org.example.application"}, {UA_APP_INSTALLER_ID, 0, "test-kit"}, {UA_APP_NAME, 0, "My Application"}, {UA_SCREEN_NAME, 0, "My Mobile Home Screen"}, {UA_EVENT_CATEGORY, 0, "Mobile"}, {UA_EVENT_ACTION, 0, "App Start"}, {UA_EVENT_LABEL, 0, unicode_value} // This value will leverage the UTF-8 encoding }}; printf("Sending mobile screenview\n"); sendTracking(tracker, UA_SCREENVIEW, & mobileOptions); /* Static definition of a group of options (in stack space) */ UAOptions opts = {{ {UA_EVENT_CATEGORY, 0, "Event Category"}, {UA_EVENT_ACTION, 0, "Event Action (C)"}, {UA_EVENT_LABEL, 0, "Event Label"}, {UA_CUSTOM_DIMENSION, 3, "Three"} }}; /* Send a bunch of events with additional ephemeral options. * We're sending such a large batch to test the HTTP library's * non-blocking (queuing) behavior. */ if(test_http_buffer){ printf("Sending %d events\n", test_http_total_requests); for(i = 0; i < test_http_total_requests; i++){ sendTracking(tracker, UA_EVENT, & opts); } } /* Process the queued tracking, then clear the tracker's memory * and deallocate */ removeTracker(tracker); return 0; }
int main( int argc, char** argv ) { // Store the first detected face CvRect *pFaceRect = NULL; // Store the tracked face CvRect nextFaceRect; //CvBox2D faceBox; // Points to draw the face rectangle CvPoint pt1 = cvPoint(0,0); CvPoint pt2 = cvPoint(0,0); char c = 0; // Object faceDetection of the class "FaceDetection" FaceDetection faceDetection; // Object captureFrame of the class "CaptureFrame" CaptureFrame captureFrame; // Create a new window cvNamedWindow("tracked face", 1); printf("\nPress r to re-initialise tracking"); // Capture from the camera captureFrame.StartCapture(); bool finished = captureFrame.CaptureNextFrame(); // capture into frameCopy if (finished) // if video is finished { captureFrame.DeallocateFrames(); releaseTracker(); cvDestroyWindow("tracked face"); return 0; } // Create the tracker if(!createTracker(captureFrame.getFrameCopy())) fprintf( stderr, "ERROR: tracking initialisation\n" ); // Set Camshift parameters setVmin(30); setSmin(20); // Capture video until a face is detected pFaceRect = waitForFaceDetect(&faceDetection, &captureFrame); // Start tracking if (pFaceRect == NULL) { captureFrame.DeallocateFrames(); releaseTracker(); // Destroy the window previously created cvDestroyWindow("tracked face"); return 0; } // Start tracking startTracking(captureFrame.getFrameCopy(), pFaceRect); // Track the detected face using CamShift while(1) { finished = captureFrame.CaptureNextFrame(); //capture to frameCopy if (finished) { captureFrame.DeallocateFrames(); releaseTracker(); cvDestroyWindow("tracked face"); return 0; } // Track the face in the new video frame nextFaceRect = track(captureFrame.getFrameCopy()); //faceBox = track(captureFrame.getFrameCopy()); pt1.x = nextFaceRect.x; pt1.y = nextFaceRect.y; pt2.x = pt1.x + nextFaceRect.width; pt2.y = pt1.y + nextFaceRect.height; // Draw face rectangle cvRectangle(captureFrame.getFrameCopy(), pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 ); // Draw face ellipse //cvEllipseBox(captureFrame.getFrameCopy(), faceBox, //CV_RGB(255,0,0), 3, CV_AA, 0 ); cvShowImage("tracked face", captureFrame.getFrameCopy()); c = cvWaitKey(100); switch(c) { case 27: break; break; case 'r': printf("\nKey pressed for re-initialisation"); // Capture video until a face is detected pFaceRect = waitForFaceDetect(&faceDetection, &captureFrame); if (pFaceRect == NULL) { captureFrame.DeallocateFrames(); releaseTracker(); // Destroy the window previously created cvDestroyWindow("tracked face"); return 0; } releaseTracker(); // Start tracking startTracking(captureFrame.getFrameCopy(), pFaceRect); break; } } // Release the image and tracker captureFrame.DeallocateFrames(); releaseTracker(); // Destroy the window previously created cvDestroyWindow("tracked face"); return 0; }
int main( int argc, const char** argv ) { cv::CommandLineParser parser( argc, argv, keys ); // Parse and validate input parameters std::string tracker_algorithm = parser.get<std::string>("1"); std::string video_name = parser.get<std::string>("2"); std::cout << "Tracker algorithm: " << tracker_algorithm << std::endl; std::cout << "Video name: " << video_name << std::endl; if( tracker_algorithm.empty() || video_name.empty() ) { std::cout << "Error: can't recognize tracking algorithm or open video" << std::endl; help(argv[0]); return 1; } // Open the video file cv::VideoCapture cap; cap.open( video_name ); if( !cap.isOpened() ) { std::cout << "Error: could not initialize video capturing...\n"; help(argv[0]); return 1; } // Get the first frame cv::Mat frame; cap >> frame; // Initialize GTReader and PrecisionRecallEvaluator std::string argv3 = parser.get<std::string>("3"); GTReader gt_reader(argv3); PrecisionRecallEvaluator pr_evaluator; // Initialize GUI GUI gui; cv::Rect bounding_box = gui.initBoundingBox(gt_reader.get(), frame); // Create Tracker cv::Ptr<Tracker> tracker = createTracker(tracker_algorithm); if (tracker == NULL) { std::cout << "Error: can't create tracker \"" << tracker_algorithm << "\"" << std::endl; return 1; } if (!tracker->init(frame, bounding_box)) { std::cout << "Error: can't initialize tracker..." << std::endl; return 1; } // Run tracking while (true) { // Fetch next frame cap >> frame; if(frame.empty()) break; // Track object cv::Rect position; bool found = tracker->track(frame, position); // Compare the predicted position with ground truth, if known cv::Rect gt = gt_reader.next(); cv::Scalar rect_color = cv::Scalar(0, 255, 0); if (gt_reader.isOpen() && !pr_evaluator.updateMetrics(position, gt)) { // Make rect red, if the prediction is incorrect rect_color = cv::Scalar(0, 0, 255); } // Display frame with predicted and ground truth rectangles, if known if (!gui.displayImage(frame, found ? position : cv::Rect(), rect_color, gt)) break; } if (gt_reader.isOpen()) { std::pair<float, float> metrics = pr_evaluator.getMetrics(); std::cout << "Precision:\t" << metrics.first << std::endl; std::cout << "Recall :\t" << metrics.second << std::endl; } return 0; }