diff --git a/CompleteVision_MAIN/CompleteVision_MAIN.depend b/CompleteVision_MAIN/CompleteVision_MAIN.depend index 9cdb621..2e00309 100644 --- a/CompleteVision_MAIN/CompleteVision_MAIN.depend +++ b/CompleteVision_MAIN/CompleteVision_MAIN.depend @@ -152,7 +152,7 @@ -1386715088 source:/home/mdarling/Desktop/CompleteVision_MAIN/PnPObj.cpp +1386967819 source:/home/mdarling/Desktop/CompleteVision_MAIN/PnPObj.cpp "PnPObj.hpp" 1381786430 source:/home/mdarling/Desktop/CompleteVision_MAIN/serialCommBeagle.cpp @@ -263,17 +263,17 @@ -1386805576 source:/home/mdarling/Desktop/CompleteVision_MAIN/LED_Detector.cpp +1386968734 source:/home/mdarling/Desktop/CompleteVision_MAIN/LED_Detector.cpp "LED_Detector.hpp" -1386818986 /home/mdarling/Desktop/CompleteVision_MAIN/LED_Detector.hpp +1386830602 /home/mdarling/Desktop/CompleteVision_MAIN/LED_Detector.hpp "Global.hpp" -1386738559 source:/home/mdarling/Desktop/CompleteVision_MAIN/FeatureDetector_Test.cpp +1386967558 source:/home/mdarling/Desktop/CompleteVision_MAIN/FeatureDetector_Test.cpp "Global.hpp" "Config.hpp" "v4l2_c.h" diff --git a/CompleteVision_MAIN/TestImages/frame_0.jpg b/CompleteVision_MAIN/TestImages/frame_0.jpg index 4690929..48660d9 100644 Binary files a/CompleteVision_MAIN/TestImages/frame_0.jpg and b/CompleteVision_MAIN/TestImages/frame_0.jpg differ diff --git a/CompleteVision_MAIN/TestImages/frame_0001.jpg b/CompleteVision_MAIN/TestImages/frame_0001.jpg index 67e3b97..55fcfc9 100644 Binary files a/CompleteVision_MAIN/TestImages/frame_0001.jpg and b/CompleteVision_MAIN/TestImages/frame_0001.jpg differ diff --git a/CompleteVision_MAIN/TestImages/frame_0002.jpg b/CompleteVision_MAIN/TestImages/frame_0002.jpg index 2116e69..9e50809 100644 Binary files a/CompleteVision_MAIN/TestImages/frame_0002.jpg and b/CompleteVision_MAIN/TestImages/frame_0002.jpg differ diff --git a/CompleteVision_MAIN/bin/Debug/CompleteVision_MAIN b/CompleteVision_MAIN/bin/Debug/CompleteVision_MAIN index 3a730ff..f1e272f 100755 Binary files a/CompleteVision_MAIN/bin/Debug/CompleteVision_MAIN and b/CompleteVision_MAIN/bin/Debug/CompleteVision_MAIN differ diff --git a/CompleteVision_MAIN/obj/Debug/PnPObj.o b/CompleteVision_MAIN/obj/Debug/PnPObj.o index aac0c2f..55e1e57 100644 Binary files a/CompleteVision_MAIN/obj/Debug/PnPObj.o and b/CompleteVision_MAIN/obj/Debug/PnPObj.o differ diff --git a/FeatureDetector_Test.cpp b/FeatureDetector_Test.cpp index a78a8d5..0e56ed0 100644 --- a/FeatureDetector_Test.cpp +++ b/FeatureDetector_Test.cpp @@ -214,7 +214,7 @@ while(1) Detector.findLEDs(frame,gray,binary,imagePoints,DetectorParams,PnP.is_current,PnP.projImagePoints); // Compute pose estimate - int poseIters = PnP.localizeUAV(imagePoints, poseState, poseErr, 9, POSE_ERR_TOL, SECONDARY_POSE_ERR_TOL); //, preCorrelated); + int poseIters = PnP.localizeUAV(imagePoints, poseState, poseErr, 9, POSE_ERR_TOL, SECONDARY_POSE_ERR_TOL,preCorrelated); if ( poseIters > 0 && checkSanity(poseState) > 0 ) { PnP.is_current = true; @@ -238,7 +238,7 @@ while(1) /// Print fps and pose estimate to console in real-time #ifdef POSE_TO_CONSOLE double fps_cnt=fps.fps(); - printf("\e[J FPS: %6.2f # of detected features: %4d\n",fps_cnt,imagePoints.size()); + printf("\e[J FPS: %6.2f # of detected features: %4d # iters: %3d\n",fps_cnt,imagePoints.size(),poseIters); printf(" Pose Estimate:%7s %7s %7s %7s %7s %7s [in/deg]\n","x","y","z","roll","pitch","yaw"); printf(" %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", reportState[0], reportState[1], reportState[2], diff --git a/LED_Detector.cpp b/LED_Detector.cpp index 4097aa9..2e4da3d 100644 --- a/LED_Detector.cpp +++ b/LED_Detector.cpp @@ -30,7 +30,8 @@ bool LED_Detector::findLEDs(const cv::Mat& RGBImage, cv::Mat &grayImage, cv::Mat vector > contours; findContours(binaryImage,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE); - + /// Jump back to here if we can't use previous state + not_detected_stop: /// We now have a vectorized contours object: vector > contours @@ -44,21 +45,18 @@ bool LED_Detector::findLEDs(const cv::Mat& RGBImage, cv::Mat &grayImage, cv::Mat if (havePreviousState) // Need to initialize proximities { proximityVec.resize(NO_LEDS); // This will resize 1st dimension to proximityVec[5][] + for (int i=0; i params.maxColor ) continue; } + if (havePreviousState) { // check each blob if in local raidus of previous image point @@ -191,20 +189,13 @@ bool LED_Detector::findLEDs(const cv::Mat& RGBImage, cv::Mat &grayImage, cv::Mat // check if within local radius if (radius < (params.localRadius * span / 100)) { -// n_detected++; -// if (radius < (proximityVec[i].radius)) // replace if better than current value -// { -// proximityVec[i].center = contourStruct.center; -// proximityVec[i].radius = radius; -// } - - n_detected++; proximity tmpProx; tmpProx.center = contourStruct.center; tmpProx.radius = radius; proximityVec[i].push_back(tmpProx); } } + } } @@ -212,14 +203,25 @@ bool LED_Detector::findLEDs(const cv::Mat& RGBImage, cv::Mat &grayImage, cv::Mat contourStructVec.push_back(contourStruct); } - // If we don't detect at least 2 of the LEDs in current frame, don't use previous information - // (prevents us from holding onto a past state that may not be true) - //if (n_detected < 3) - // havePreviousState = false; + if (!havePreviousState && params.sortByColor) + { + sort(contourStructVec.begin(), contourStructVec.end(), LED_Detector::sortByColor); + + // populate the vector of image points from the contourStructVec + int stopHere = (contourStructVec.size() > params.maxBlobs) ? params.maxBlobs : contourStructVec.size(); + for (int i=0; i flat; // "flattened" vector (points to elements of proximityVec) for (int i=0; i LEDs; // Pass the first LEDs for (int i=0; i layer; int layer_no = 0; - while (LEDs.size() < LEDs_max) + while (leds.size() < LEDs_max) { // Populate the next layer if we have extracted all elements from previous one @@ -329,49 +334,11 @@ bool LED_Detector::findLEDs(const cv::Mat& RGBImage, cv::Mat &grayImage, cv::Mat break; int randomPick = rand() % layer.size(); - LEDs.push_back(*layer[randomPick]); + leds.push_back(*layer[randomPick]); layer.erase(layer.begin() + randomPick); } } - else if (params.sortByColor) - { - sort(contourStructVec.begin(), contourStructVec.end(), LED_Detector::sortByColor); - - // populate the vector of image points from the contourStructVec - int stopHere = (contourStructVec.size() > params.maxBlobs) ? params.maxBlobs : contourStructVec.size(); - for (int i=0; i &imagePoints_IN, std::vec PnPObj::solve(); // WARNING: Modifies private member function values of PnPObj! - if (scaledReprojErr < perrTol){ + // Relax the tolerance if we have a previous frame to help us out + if (scaledReprojErr < perrTol || (scaledReprojErr < serrTol && skipCorrelation)){ poseErr = scaledReprojErr; poseState = PnPObj::getState(); @@ -378,8 +379,8 @@ int PnPObj::localizeUAV(const std::vector &imagePoints_IN, std::vec error_buff.push_back(scaledReprojErr); PnPObj_buff.push_back(*this); // append this instance of PnPObj to buffer } - if (skipCorrelation) //only go through one iteration if we are providing image pts in order - break; +// if (skipCorrelation) //only go through one iteration if we are providing image pts in order +// break; } }