minimum size slider

This commit is contained in:
Harrison Deng 2018-05-07 18:21:48 -05:00
parent c2b817d200
commit e1cbdbae7d
2 changed files with 5 additions and 2 deletions

View File

@ -11,12 +11,12 @@ ContourAnalyzer::ContourAnalyzer(UI *ui, int *lastKey) {
void ContourAnalyzer::analyze() { void ContourAnalyzer::analyze() {
prunedContours.clear(); prunedContours.clear();
if (*lastKey == 99) { if (*lastKey == 99) {
cannyRec = !cannyRec; cannyRec = !cannyRec;
} else if (*lastKey == 118) { } else if (*lastKey == 118) {
drawContours = !drawContours; drawContours = !drawContours;
} }
minSize = ((ui->originalFrame()->cols)*(ui->originalFrame()->rows))*(minSizeScale/(float)10000);
if (cannyRec) { if (cannyRec) {
cannyUpper = std::min(3*cannyLower, 255); cannyUpper = std::min(3*cannyLower, 255);
@ -31,7 +31,7 @@ void ContourAnalyzer::analyze() {
for (unsigned i = 0; i < contours.size(); i++) { for (unsigned i = 0; i < contours.size(); i++) {
if ((cv::contourArea(contours[i]) > 225) && (cv::contourArea(contours[i]) < (ui->currentFrame(0)->cols * ui->currentFrame(0)->rows) -25)) { if ((cv::contourArea(contours[i]) > minSize) && (cv::contourArea(contours[i]) < (ui->currentFrame(0)->cols * ui->currentFrame(0)->rows) -25)) {
double perimeter = cv::arcLength(contours[i], true); double perimeter = cv::arcLength(contours[i], true);
cv::approxPolyDP(contours[i], contours[i], (epsilon/(float)1000)*perimeter, true); cv::approxPolyDP(contours[i], contours[i], (epsilon/(float)1000)*perimeter, true);
@ -102,6 +102,7 @@ void ContourAnalyzer::componentSetup() {
cv::createTrackbar("Can. Lower", UI::DEBUG_WINDOW, &cannyLower , 255); cv::createTrackbar("Can. Lower", UI::DEBUG_WINDOW, &cannyLower , 255);
cv::createTrackbar("Can. Upper", UI::DEBUG_WINDOW, &cannyUpper , 255); cv::createTrackbar("Can. Upper", UI::DEBUG_WINDOW, &cannyUpper , 255);
cv::createTrackbar("Epsilon", UI::DEBUG_WINDOW, &epsilon , 1000); cv::createTrackbar("Epsilon", UI::DEBUG_WINDOW, &epsilon , 1000);
cv::createTrackbar("Min. Size", UI::DEBUG_WINDOW, &minSizeScale, 10000);
} }
ContourAnalyzer::~ContourAnalyzer() { ContourAnalyzer::~ContourAnalyzer() {
ui->UIListeners.erase(std::remove(ui->UIListeners.begin(), ui->UIListeners.end(), this)); ui->UIListeners.erase(std::remove(ui->UIListeners.begin(), ui->UIListeners.end(), this));

View File

@ -25,6 +25,8 @@ class ContourAnalyzer: public UIListener {
public: public:
int binLower = 52; int binLower = 52;
int minSize = 0;
int minSizeScale = 15;
int cannyLower = 57; int cannyLower = 57;
int cannyUpper = 3*cannyLower; int cannyUpper = 3*cannyLower;