From 73224b10ec9283e4e07fc956cc7ce1959fa8ac6b Mon Sep 17 00:00:00 2001 From: Pavol Debnar Date: Thu, 16 Feb 2023 23:09:33 +0100 Subject: [PATCH] WIP SIFT descriptors --- src/pointbase.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/src/pointbase.cpp b/src/pointbase.cpp index c488e79..b9e90f9 100644 --- a/src/pointbase.cpp +++ b/src/pointbase.cpp @@ -3,6 +3,8 @@ #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/stitching.hpp" +#include +#include #include #include #include @@ -380,7 +382,7 @@ class PointBase { void cumdump(int imgWidth,int imgHeight) { - + std::vector edges; @@ -390,7 +392,10 @@ class PointBase { double minY=edges[2]; double maxY=edges[3]; - Mat img = Mat::zeros((int)(maxY*(imgHeight/imgHeightDeg))+imgHeight,(int)((360/imgWidthDeg)*imgWidth) + imgWidth,CV_8UC3); + int windowHeight = (int)(maxY*(imgHeight/imgHeightDeg))+imgHeight; + int windowWidth = (int)((360/imgWidthDeg)*imgWidth) + imgWidth; + + Mat img = Mat::zeros(windowHeight,windowWidth,CV_8UC3); rectangle(img,Point(3,3),Point(15,15),Scalar(128,128, 0),2,2,0); int imgIdx = 0; @@ -465,11 +470,12 @@ class PointBase { Mat img = Mat::zeros((int)(maxY*(imgHeight/imgHeightDeg))+imgHeight,(int)((360/imgWidthDeg)*imgWidth) + imgWidth,CV_8UC3); rectangle(img,Point(3,3),Point(15,15),Scalar(128,128, 0),2,2,0); */ - + //open stream for logging string logFileName = to_string(imgIdx) + ".log"; ofstream logFile(logFileName); + int qIdx = 0; for (Point2d coords: stitchQueue) { //log which images are in which result file @@ -492,13 +498,76 @@ class PointBase { cout < windowWidth) xWitdth = windowWidth - xLoc; + if (yLoc + yHeight > windowHeight) yHeight = windowHeight - yLoc; + + Mat roi; + roi = img(Rect(xLoc, yLoc, xWitdth, yHeight)); + /*imshow("roi",roi); + imwrite("temp.jpg", roi); + waitKey(0);*/ + + + cv::Ptr siftPtr = SIFT::create(); + std::vector keypointsROI, keypointsImg; + cv::Ptr siftExtrPtr; + cv::Mat descriptorsROI, descriptorsImg; + siftPtr->detect(roi, keypointsROI); + siftPtr->detect(imgSmall, keypointsImg); + + + + // Add results to image and save. + /* + cv::Mat output; + cv::drawKeypoints(imgSmall, keypointsImg, output); + imshow("sift_result.jpg", output); + waitKey(0);*/ + + cout<<" SIZE \n"<compute(roi, + keypointsROI, + descriptorsROI); + /*siftExtrPtr->compute(imgSmall, + keypointsImg, + descriptorsImg);*/ + + + cv::BFMatcher matcher(cv::NORM_L2,true); + std::vector matches; + + matcher.match(descriptorsROI,descriptorsImg,matches); + cv::Mat imageMatches; + + drawMatches(roi,keypointsROI,imgSmall,keypointsImg,matches,imageMatches); + cv::namedWindow("matches"); + cv::imshow("matches",imageMatches); + cv::waitKey(0); + + + //cout<