/* Sort blobs in descending order using selection sort. NOTE: if efficiency is an issue this sort can be improved */ void Blobs::sort() { for (int i = 0; i < number(); i++){ Blob temp = blobs[i]; int biggest = getBiggest(i); blobs[i] = blobs[biggest]; blobs[biggest] = temp; } }
void printAll(LinkedList list, int num, int noCols) { Node* walker = list.first; unsigned* maximums = getBiggest(list, noCols); while(walker!=NULL) { for(int i=0; i < noCols; i++) { printf("%s\t", walker->line[i]); for(unsigned i = strlen(walker->line[i]); i<maximums[i]; i++) { printf(" "); } } printf("\n"); walker = walker->next; } }
void Camera::showBiggest() { cuda::GpuMat frame_gpu, frame_hsv_gpu, descriptors_scene; cap >> frame; frame_gpu.upload(frame); cuda::cvtColor(frame_gpu, frame_hsv_gpu, CV_BGR2HSV, 4); frame_hsv_gpu.download(frame_hsv); inRange(frame_hsv, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgSave); #ifdef DEBUG imshow("Tresh", imgSave); #endif frame_hsv_gpu.upload(imgSave); // Mat cannyOutput; for(int i = 0; i < ErodeDilate; i++) { cuda::createMorphologyFilter(MORPH_ERODE, CV_8UC4, imgSave); cuda::createMorphologyFilter(MORPH_DILATE, CV_8UC4, imgSave); cuda::createMorphologyFilter(MORPH_DILATE, CV_8UC4, imgSave); cuda::createMorphologyFilter(MORPH_ERODE, CV_8UC4, imgSave); } /* erode(imgSave, imgSave, getStructuringElement(MORPH_ELLIPSE, Size(3, 3)) ); dilate( imgSave, imgSave, getStructuringElement(MORPH_ELLIPSE, Size(3, 3)) ); dilate(imgSave, imgSave, getStructuringElement(MORPH_ELLIPSE, Size(8, 8))); erode(imgSave, imgSave, getStructuringElement(MORPH_ELLIPSE, Size(8, 8))); */ //Mat dst; frame_hsv_gpu.download(imgSave); findContours(imgSave, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0,0)); Mat drawing = Mat::zeros(imgSave.size(), CV_8UC3); for(int i = 0; i < contours.size(); i++) { Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point()); } #ifdef DEBUG imshow("Drawing", drawing); imshow("Control", frame_hsv); #endif // if (good_matches.size() >= 4) { color = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); Mat biggest = Mat::zeros(imgSave.size(), CV_8UC3); drawContours(biggest, contours, getBiggest(), color, 2, 8, hierarchy, 0, Point()); #ifdef DEBUG imshow("Biggest", biggest); #endif waitKey(1); }
std::vector<cv::Rect> RealSenseDetector::detectImpl(const ImageGrayscale &img) { std::vector<cv::Rect> rects = OpenCVDetector::detect(img); if (rects.empty()) { consecutiveDetects = 0; consecutiveNonDetects++; // depth face tracker overlap test if (consecutiveNonDetects < 4 && rsDepthFaceTracker->hasLastRoi()) { cv::Rect croi = RealSenseDepthFaceTracker::convertScale(rsDepthFaceTracker->getLastCroi(), setup.scale, setup.detectRoi); cv::Rect intersection = lastRoi & croi; cv::Rect smallerRoi = croi.area() < lastRoi.area() ? croi : lastRoi; std::cout << std::dec << " *** RealSenseDetector::detectImpl, lastRoi: " << lastRoi << ", croi: " << croi << ", intersection: " << intersection << std::endl; std::cout << std::dec << " *** RealSenseDetector::detectImpl, intersection/smallerRoi/croi/lastRoi areas: " << intersection.area() << "/" << smallerRoi.area() << "/" << croi.area() << "/" << lastRoi.area() << std::endl; if (intersection.area() > smallerRoi.area() * 0.5) { cv::Point croiCenter(croi.x + croi.width / 2, croi.y + croi.height / 2); cv::Point lregCenter(lastRoi.x + lastRoi.width / 2, lastRoi.y + lastRoi.height / 2); cv::Point displ(croiCenter - lregCenter); std::cout << std::dec << " *** RealSenseDetector::detectImpl, displ vector: " << displ << std::endl; lastRoi.x += displ.x; lastRoi.y += displ.y; rects.push_back(lastRoi); } } else { std::cout << std::dec << " *** RealSenseDetector::detectImpl, NO FACE, consecutiveNonDetects: " << consecutiveNonDetects << std::endl; } } else { consecutiveDetects++; consecutiveNonDetects = 0; lastRoi = getBiggest(rects); } return rects; }