tuning; better tracking; began on distance calc;
This commit is contained in:
@@ -10,18 +10,7 @@ ContourAnalyzer::ContourAnalyzer(UI *ui, int *lastKey) {
|
||||
}
|
||||
|
||||
void ContourAnalyzer::analyze() {
|
||||
prunedContours.clear();
|
||||
if (*lastKey == 99) {
|
||||
cannyRec = !cannyRec;
|
||||
} else if (*lastKey == 118) {
|
||||
drawContours = !drawContours;
|
||||
}
|
||||
minSize = ui->getWidth()*ui->getHeight()*(minSizeScale/(float)10000);
|
||||
|
||||
if (cannyRec) {
|
||||
cannyUpper = std::min(3*cannyLower, 255);
|
||||
cv::setTrackbarPos("Can. Upper", UI::DEBUG_WINDOW, cannyUpper);
|
||||
}
|
||||
preAnalyze();
|
||||
|
||||
cv::cvtColor(*(ui->currentFrame(-1)), *(ui->nextFrame()), cv::COLOR_BGR2GRAY);
|
||||
cv::GaussianBlur(*(ui->currentFrame(-1)), *(ui->nextFrame()), cv::Size(5, 5), 0);
|
||||
@@ -29,7 +18,30 @@ void ContourAnalyzer::analyze() {
|
||||
cv::Canny(*(ui->currentFrame(-1)), *(ui->nextFrame()), cannyLower, cannyUpper);
|
||||
cv::findContours(*(ui->currentFrame()), contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
|
||||
|
||||
removeRedundancy();
|
||||
|
||||
if (drawContours) {
|
||||
drawContoursOntoMat(*(ui->drawnFrame()));
|
||||
cv::putText(*(ui->drawnFrame()), "Showing possible triangles rectangles.",
|
||||
cv::Point{5, 30}, cv::FONT_HERSHEY_PLAIN, 0.8, selectColor);
|
||||
}
|
||||
}
|
||||
|
||||
void ContourAnalyzer::analyze(cv::Rect rect) {
|
||||
preAnalyze();
|
||||
cv::Mat frame;
|
||||
ui->getOriginalFrame().copyTo(frame);
|
||||
|
||||
cv::Mat cropped = frame(rect);
|
||||
cv::cvtColor(cropped, cropped, cv::COLOR_BGR2GRAY);
|
||||
cv::GaussianBlur(cropped, cropped, cv::Size(5, 5), 0);
|
||||
cv::threshold(cropped, cropped, binLower, 255, cv::THRESH_BINARY);
|
||||
cv::Canny(cropped, cropped, cannyLower, cannyUpper);
|
||||
cv::findContours(cropped, contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
|
||||
removeRedundancy();
|
||||
}
|
||||
|
||||
void ContourAnalyzer::removeRedundancy() {
|
||||
for (unsigned i = 0; i < contours.size(); i++) {
|
||||
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);
|
||||
@@ -62,9 +74,20 @@ void ContourAnalyzer::analyze() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drawContours) {
|
||||
drawContoursOntoMat(*(ui->drawnFrame()));
|
||||
void ContourAnalyzer::preAnalyze() {
|
||||
prunedContours.clear();
|
||||
if (*lastKey == 99) {
|
||||
cannyRec = !cannyRec;
|
||||
} else if (*lastKey == 118) {
|
||||
drawContours = !drawContours;
|
||||
}
|
||||
minSize = ui->getWidth()*ui->getHeight()*(minSizeScale/(float)10000);
|
||||
|
||||
if (cannyRec) {
|
||||
cannyUpper = std::min(3*cannyLower, 255);
|
||||
cv::setTrackbarPos("Can. Upper", UI::DEBUG_WINDOW, cannyUpper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user