|
|
|
@ -3,6 +3,8 @@
|
|
|
|
|
#include "opencv2/imgproc.hpp"
|
|
|
|
|
#include "opencv2/imgcodecs.hpp"
|
|
|
|
|
#include "opencv2/stitching.hpp"
|
|
|
|
|
#include <opencv2/xfeatures2d.hpp>
|
|
|
|
|
#include <opencv2/features2d.hpp>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <json/json.h>
|
|
|
|
@ -380,7 +382,7 @@ class PointBase {
|
|
|
|
|
|
|
|
|
|
void cumdump(int imgWidth,int imgHeight)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector <double> 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 <<minX <<"\n";
|
|
|
|
|
cout <<minY <<"\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//cout << (int)round(coords.x)-(int)round(minX)<< "\n";
|
|
|
|
|
//cout << (int)round(coords.y)-(int)round(minY)<< "\n";
|
|
|
|
|
cout << (int)round(coords.y)*(int)(imgHeight/imgHeightDeg)<< "\n";
|
|
|
|
|
imgSmall.copyTo(img(cv::Rect((int)round(coords.x)*(int)(imgWidth/imgWidthDeg),(int)round(coords.y)*(int)(imgHeight/imgHeightDeg),imgSmall.cols, imgSmall.rows)));
|
|
|
|
|
|
|
|
|
|
//first image is added to result img, others will be stitched
|
|
|
|
|
if (qIdx==0) imgSmall.copyTo(img(cv::Rect((int)round(coords.x)*(int)(imgWidth/imgWidthDeg),(int)round(coords.y)*(int)(imgHeight/imgHeightDeg),imgSmall.cols, imgSmall.rows)));
|
|
|
|
|
else {
|
|
|
|
|
//default ROI location and size
|
|
|
|
|
int xLoc=(int)round(coords.x)*(int)(imgWidth/imgWidthDeg) - imgWidth; //=normalized x-coord. minus 1 width of image
|
|
|
|
|
int yLoc=(int)round(coords.y)*(int)(imgHeight/imgHeightDeg) - imgHeight;
|
|
|
|
|
int xWitdth=3*imgWidth;
|
|
|
|
|
int yHeight=3*imgHeight;
|
|
|
|
|
|
|
|
|
|
//edge cases
|
|
|
|
|
if ((int)round(coords.x)*(int)(imgWidth/imgWidthDeg) - imgWidth < 0) xLoc=0;
|
|
|
|
|
if ((int)round(coords.y)*(int)(imgHeight/imgHeightDeg) - imgHeight < 0) yLoc = 0;
|
|
|
|
|
if (xLoc + xWitdth > 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<SIFT> siftPtr = SIFT::create();
|
|
|
|
|
std::vector<cv::KeyPoint> keypointsROI, keypointsImg;
|
|
|
|
|
cv::Ptr<SiftDescriptorExtractor> 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"<<roi.size() <<" \n";
|
|
|
|
|
siftPtr->compute(roi,
|
|
|
|
|
keypointsROI,
|
|
|
|
|
descriptorsROI);
|
|
|
|
|
/*siftExtrPtr->compute(imgSmall,
|
|
|
|
|
keypointsImg,
|
|
|
|
|
descriptorsImg);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::BFMatcher matcher(cv::NORM_L2,true);
|
|
|
|
|
std::vector<cv::DMatch> 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<<CV_VERSION;
|
|
|
|
|
}
|
|
|
|
|
//if(qIdx==2) break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qIdx++;
|
|
|
|
|
}
|
|
|
|
|
logFile.close();
|
|
|
|
|
string resultName = "result" + to_string(imgIdx) +".png";
|
|
|
|
|