mirror of
https://github.com/debnarpavol/spajanie_snimkov_uprava_jasu.git
synced 2025-08-08 05:07:20 +02:00
creation of cumulative dump function; edited test
cumdump() - puts all images into a single one with no stiching yet test.cpp - use of cumdump(), added img locations for quicker use
This commit is contained in:
@ -41,6 +41,9 @@ class PointBase {
|
|||||||
vector <Point2d> toDoVector; //points yet to be searched for adjacent points
|
vector <Point2d> toDoVector; //points yet to be searched for adjacent points
|
||||||
std::map<Point2d, string, ComparePoints> pathMap; //map for file paths - get the path of a file via pathMap[Point2d(x,y)]
|
std::map<Point2d, string, ComparePoints> pathMap; //map for file paths - get the path of a file via pathMap[Point2d(x,y)]
|
||||||
|
|
||||||
|
double imgWidthDeg;
|
||||||
|
double imgHeightDeg;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//loaded points in pointbase are sorted according to X value
|
//loaded points in pointbase are sorted according to X value
|
||||||
@ -63,6 +66,9 @@ class PointBase {
|
|||||||
Point2d newPoint = Point2d(coords["depthPos"]["x"].asDouble() , coords["depthPos"]["y"].asDouble());
|
Point2d newPoint = Point2d(coords["depthPos"]["x"].asDouble() , coords["depthPos"]["y"].asDouble());
|
||||||
pathMap[newPoint] = filePath;
|
pathMap[newPoint] = filePath;
|
||||||
points.push_back(newPoint);
|
points.push_back(newPoint);
|
||||||
|
|
||||||
|
imgWidthDeg = coords["rectangle"]["w"].asDouble();
|
||||||
|
imgHeightDeg = coords["rectangle"]["h"].asDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -342,4 +348,158 @@ class PointBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cumdump(int imgWidth,int imgHeight)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int imgIdx = 0;
|
||||||
|
//main loop
|
||||||
|
while (!points.empty())
|
||||||
|
{
|
||||||
|
//take the first point from the left and find adjts. to it
|
||||||
|
Point2d p = points[0];
|
||||||
|
vector<Point2d> stitchQueue;
|
||||||
|
stitchQueue.push_back(p);
|
||||||
|
points.erase(points.begin());
|
||||||
|
|
||||||
|
vector<Point2d> temp = getAdjacents(p); //find adj. of first point - inits toDo vector
|
||||||
|
|
||||||
|
|
||||||
|
if (toDoVector.empty()) //if first point has no adjts. - log him as singleton
|
||||||
|
{
|
||||||
|
ofstream singletonsFile("singletons.log", ios_base::app);
|
||||||
|
if(!singletonsFile)
|
||||||
|
{
|
||||||
|
singletonsFile << "x: " << p.x << std::endl;
|
||||||
|
singletonsFile << "y: " << p.y << std::endl;
|
||||||
|
singletonsFile << pathMap[Point2d(p.x,p.y) ] << std::endl;
|
||||||
|
singletonsFile.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ofstream sing;
|
||||||
|
sing.open("singletons.log",ios_base::app);
|
||||||
|
sing << "x: " << p.x << std::endl;
|
||||||
|
sing << "y: " << p.y << std::endl;
|
||||||
|
sing << pathMap[Point2d(p.x,p.y) ] << std::endl;
|
||||||
|
sing.close();
|
||||||
|
}
|
||||||
|
stitchQueue.pop_back();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//finds adjacencies to every point
|
||||||
|
while(!toDoVector.empty())
|
||||||
|
{
|
||||||
|
Point2d p2 = toDoVector[0];
|
||||||
|
stitchQueue.push_back(p2);
|
||||||
|
temp = getAdjacents(p2);
|
||||||
|
toDoVector.erase(toDoVector.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
//stitching
|
||||||
|
// Define object to store the stitched image
|
||||||
|
|
||||||
|
double minX=999;
|
||||||
|
double maxX=0;
|
||||||
|
double minY=900000;
|
||||||
|
double maxY=0;
|
||||||
|
|
||||||
|
for (Point2d coords: stitchQueue)
|
||||||
|
{
|
||||||
|
if (coords.x < minX) minX=coords.x;
|
||||||
|
if (coords.x > maxX) maxX=coords.x;
|
||||||
|
if (coords.y < minY) minY=coords.y;
|
||||||
|
if (coords.y > maxY) maxY=coords.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int xDiff = (int)round(maxX)-(int)round(minX);
|
||||||
|
int yDiff = (int)round(maxY)-(int)round(minY);
|
||||||
|
cout <<xDiff <<"\n";
|
||||||
|
cout <<yDiff <<"\n";
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
for (Point2d coords: stitchQueue)
|
||||||
|
{
|
||||||
|
//log which images are in which result file
|
||||||
|
logFile << "x: " << coords.x << std::endl;
|
||||||
|
logFile << "y: " << coords.y << std::endl;
|
||||||
|
logFile << pathMap[Point2d(coords.x,coords.y) ] << std::endl;
|
||||||
|
|
||||||
|
//log to stdout
|
||||||
|
cout << "x: " << coords.x << std::endl;
|
||||||
|
cout << "y: " << coords.y << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
string jsonPath = pathMap[coords];
|
||||||
|
string pngPath = jsonPath.erase(jsonPath.length()-4);
|
||||||
|
pngPath = pngPath + "png";
|
||||||
|
cout << "file: " << pngPath << std::endl;
|
||||||
|
|
||||||
|
Mat imgSmall = imread(pngPath,IMREAD_COLOR);
|
||||||
|
cout<< cv::typeToString( imgSmall.type() );
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
logFile.close();
|
||||||
|
string resultName = "result" + to_string(imgIdx) +".png";
|
||||||
|
imwrite(resultName, img);
|
||||||
|
imgIdx++;
|
||||||
|
|
||||||
|
//stitching
|
||||||
|
/*
|
||||||
|
cout << "Stitching" << std::endl;
|
||||||
|
Stitcher::Status status = stitcher->stitch(imgs, pano);
|
||||||
|
if (status != Stitcher::OK)
|
||||||
|
{
|
||||||
|
// Check if images could not be stitched
|
||||||
|
// status is OK if images are stitched successfully
|
||||||
|
cout << "Can't stitch images\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
string resultName = "result" + to_string(imgIdx) +".jpg";
|
||||||
|
|
||||||
|
// Store a new image stitched from the given
|
||||||
|
//set of images as "result.jpg"
|
||||||
|
imwrite(resultName, pano);
|
||||||
|
|
||||||
|
// Show the result
|
||||||
|
imshow(resultName, pano);
|
||||||
|
|
||||||
|
|
||||||
|
waitKey(0);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
22
src/test.cpp
22
src/test.cpp
@ -39,10 +39,16 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
//test pointbase load
|
//test pointbase load
|
||||||
PointBase pb;
|
PointBase pb;
|
||||||
|
//pb.load("../data/");
|
||||||
|
//120/2022-11-15_09-35-09
|
||||||
|
//155/2022-11-15_07-18-56
|
||||||
|
//2/2022-10-13_13-33-22
|
||||||
|
//1/2022-10-13_11-50-12
|
||||||
|
//pb.load("../1/2022-10-13_11-50-12/snapshots/");
|
||||||
pb.load("../data/");
|
pb.load("../data/");
|
||||||
|
|
||||||
//test print all point info
|
//test print all point info
|
||||||
pb.printPoints(1);
|
pb.printPoints(0);
|
||||||
|
|
||||||
/* test get path
|
/* test get path
|
||||||
path: ../data/0000044.json;
|
path: ../data/0000044.json;
|
||||||
@ -53,4 +59,18 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
pb.showPointImg();
|
pb.showPointImg();
|
||||||
|
|
||||||
|
/*
|
||||||
|
vector<Point2d> res = pb.getAdjacents(Point2d(75.1,3220.80));
|
||||||
|
for (Point2d p :res)
|
||||||
|
{
|
||||||
|
cout << "x: " << p.x << std::endl;
|
||||||
|
cout << "y: " << p.y << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//pb.stitchImgs();
|
||||||
|
cout <<"IMG HEIGHT:" << pb.imgHeightDeg <<"\n";
|
||||||
|
cout <<"IMG WIDTH DEG:" << pb.imgWidthDeg <<"\n";
|
||||||
|
pb.cumdump(650,525);
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user