void* Run(cv::VideoCapture& capture) { int size = ivWidth*ivHeight; int count = 1; DebugInfo dbgInfo; cv::CascadeClassifier cascade; std::vector<cv::Rect> detectedFaces; std::vector<ObjectBox> trackBoxes; ObjectBox detectBox; // Initialize MultiObjectTLD #if LOADCLASSIFIERATSTART MultiObjectTLD p = MultiObjectTLD::loadClassifier((char*)CLASSIFIERFILENAME); #else MOTLDSettings settings(COLOR_MODE_RGB); settings.useColor = false; MultiObjectTLD p(ivWidth, ivHeight, settings); #endif if(cascadePath != "") cascade.load( cascadePath ); Matrix maRed; Matrix maGreen; Matrix maBlue; unsigned char img[size*3]; while(!ivQuit) { /* if(reset){ p = *(new MultiObjectTLD(ivWidth, ivHeight, COLOR_MODE_RGB)); reset = false; } if(load){ p = MultiObjectTLD::loadClassifier(CLASSIFIERFILENAME); load = false; } */ #if TIMING c_end = std::clock(); std::cout << "Total: " << (c_end-c_start) << std::endl; c_start = std::clock(); #endif // Grab an image if(!capture.grab()){ std::cout << "error grabbing frame" << std::endl; break; } cv::Mat frame; capture.retrieve(frame); frame.copyTo(curImage); //BGR to RGB // for(int j = 0; j<size; j++){ // img[j] = frame.at<cv::Vec3b>(j).val[2]; // img[j+size] = frame.at<cv::Vec3b>(j).val[1]; // img[j+2*size] = frame.at<cv::Vec3b>(j).val[0]; // } #if TIMING c_start1 = std::clock(); #endif for(int i = 0; i < ivHeight; ++i){ for(int j = 0; j < ivWidth; ++j){ img[i*ivWidth+j] = curImage.at<cv::Vec3b>(i,j).val[2]; img[i*ivWidth+j+size] = curImage.at<cv::Vec3b>(i,j).val[1]; img[i*ivWidth+j+2*size] = curImage.at<cv::Vec3b>(i,j).val[0]; } } #if TIMING c_end1 = std::clock(); std::cout << "time1: " << (c_end1-c_start1) << std::endl; #endif // for(int i = 0; i < ivHeight; ++i){ // for(int j = 0; j < ivWidth; ++j){ // curImage.at<cv::Vec3b>(i,j).val[2] = 0; // curImage.at<cv::Vec3b>(i,j).val[1] = 0; // curImage.at<cv::Vec3b>(i,j).val[0] = 0; // } // } // cv::imshow("MOCTLD", curImage); #if TIMING c_start2 = std::clock(); #endif // Process it with motld p.processFrame(img); #if TIMING c_end2 = std::clock(); std::cout << "time2: " << (c_end2-c_start2) << std::endl; #endif // Add new box if(mouseMode == MOUSE_MODE_ADD_BOX){ p.addObject(mouseBox); mouseMode = MOUSE_MODE_IDLE; } if(mouseMode == MOUSE_MODE_ADD_GATE){ p.addGate(gate); mouseMode = MOUSE_MODE_IDLE; } if(((count%20)==0) && cascadeDetect) { cascade.detectMultiScale( frame, detectedFaces, 1.1, 2, 0 //|CASCADE_FIND_BIGGEST_OBJECT //|CASCADE_DO_ROUGH_SEARCH |cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30) ); Ndetections = detectedFaces.size(); for( std::vector<cv::Rect>::const_iterator r = detectedFaces.begin(); r != detectedFaces.end(); r++ ) { detectBox.x = r->x; detectBox.y = r->y; detectBox.width = r->width; detectBox.height = r->height; if(p.isNewObject(detectBox)) p.addObject(detectBox); } //printf("size detectedFaces: %i\n", detectedFaces.size()); } count++; // Display result HandleInput(); p.getDebugImage(img, maRed, maGreen, maBlue, drawMode); #if TIMING c_start3 = std::clock(); #endif BGR2RGB(maRed, maGreen, maBlue); #if TIMING c_end3 = std::clock(); std::cout << "time3: " << (c_end3-c_start3) << std::endl; #endif drawGate(); drawMouseBox(); dbgInfo.NObjects = p.getObjectTotal(); dbgInfo.side0Cnt = p.getSide0Cnt(); dbgInfo.side1Cnt = p.getSide1Cnt(); writeDebug(dbgInfo); cv::imshow("MOCTLD", curImage); p.enableLearning(learningEnabled); if(save){ p.saveClassifier((char*)CLASSIFIERFILENAME); save = false; } } //delete[] img; capture.release(); return 0; }
void* Run(void*) { int size = ivWidth*ivHeight; // Initialize MultiObjectTLD #if LOADCLASSIFIERATSTART MultiObjectTLD p = MultiObjectTLD::loadClassifier((char*)CLASSIFIERFILENAME); #else MOTLDSettings settings(COLOR_MODE_RGB); settings.useColor = false; MultiObjectTLD p(ivWidth, ivHeight, settings); #endif Matrix maRed; Matrix maGreen; Matrix maBlue; unsigned char img[size*3]; #ifdef FORCE_RESIZING CvSize wsize = {ivWidth, ivHeight}; IplImage* frame = cvCreateImage(wsize, IPL_DEPTH_8U, 3); #endif while(!ivQuit) { /* if(reset){ p = *(new MultiObjectTLD(ivWidth, ivHeight, COLOR_MODE_RGB)); reset = false; } if(load){ p = MultiObjectTLD::loadClassifier(CLASSIFIERFILENAME); load = false; } */ // Grab an image if(!cvGrabFrame(capture)){ std::cout << "error grabbing frame" << std::endl; break; } #ifdef FORCE_RESIZING IplImage* capframe = cvRetrieveFrame(capture); cvResize(capframe, frame); #else IplImage* frame = cvRetrieveFrame(capture); #endif for(int j = 0; j<size; j++){ img[j] = frame->imageData[j*3+2]; img[j+size] = frame->imageData[j*3+1]; img[j+2*size] = frame->imageData[j*3]; } // Process it with motld p.processFrame(img); // Add new box if(mouseMode == MOUSE_MODE_ADD_BOX){ p.addObject(mouseBox); mouseMode = MOUSE_MODE_IDLE; } // Display result HandleInput(); p.getDebugImage(img, maRed, maGreen, maBlue, drawMode); FromRGB(maRed, maGreen, maBlue); cvShowImage("MOCTLD", curImage); p.enableLearning(learningEnabled); if(save){ p.saveClassifier((char*)CLASSIFIERFILENAME); save = false; } } //delete[] img; cvReleaseCapture(&capture); return 0; }