Skip to content

Commit

Permalink
Style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alefedor committed May 31, 2018
1 parent 80a0d10 commit c346005
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ find_package(Threads REQUIRED)

set(CMAKE_BUILD_TYPE Release)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -DVISUALISATION")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
Expand Down Expand Up @@ -55,9 +55,9 @@ target_link_libraries(variants ${OpenCV_LIBRARIES})

set(PAN_DIJKSTRA_SOURCE_FILES ${SOURCE_FILES} src/orthomosaic_pan_dijkstra.cpp src/solutions/pan_dijkstra.cpp src/energy/pan_pixel_energy.cpp src/energy/pan_energy.cpp src/energy/pan_differential_energy.cpp)
set(PAN_DIJKSTRA_SOURCE_FILES ${PAN_DIJKSTRA_SOURCE_FILES})
add_executable(orthomosaic_pan_dijkstra ${PAN_DIJKSTRA_SOURCE_FILES})
target_link_libraries(orthomosaic_pan_dijkstra ${EDISON_LIBRARIES})
target_link_libraries(orthomosaic_pan_dijkstra ${OpenCV_LIBRARIES})
add_executable(orthomosaic ${PAN_DIJKSTRA_SOURCE_FILES})
target_link_libraries(orthomosaic ${EDISON_LIBRARIES})
target_link_libraries(orthomosaic ${OpenCV_LIBRARIES})

set(MC_DIJKSTRA_SOURCE_FILES ${SOURCE_FILES} src/orthomosaic_mincut_dijkstra.cpp src/solutions/mincut_dijkstra.cpp)
add_executable(orthomosaic_mincut_dijkstra ${MC_DIJKSTRA_SOURCE_FILES})
Expand Down
37 changes: 24 additions & 13 deletions src/energy/pan_pixel_energy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "energy/pan_pixel_energy.h"

//#define EDGE_DETECTION

static const int frameSize = 5;
static const int delta = 1600;

Expand Down Expand Up @@ -83,22 +85,27 @@ PanPixelEnergy::PanPixelEnergy(Image &a, Image &b, bool segmentation) : a(a), b(
isPR[i] = true;


/*#pragma omp parallel for
#ifdef VISUALIZATION

#pragma omp parallel for
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
if (a.inside(x + intersectionLeft, y + intersectionTop) && isPR[labels[y * width + x]])
for (int j = 0; j < 3; j++)
(im.data + 3 * (y * width + x))[j] = magic[j];

cv::imwrite(std::to_string(rand()) + "pan_dijkstra_segmentation_result.jpg", im);*/

#endif
}

#ifdef EDGE_DETECTION



int gx[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
int gy[3][3] = {{1, 2, 1}, {0, 0, 0}, {-1, -2, -1}};

/*
//EDGE DETECTING
std::vector<std::vector<int>> gradient;
gradient.resize(height, std::vector<int>());
#pragma omp parallel for
Expand Down Expand Up @@ -144,8 +151,8 @@ PanPixelEnergy::PanPixelEnergy(Image &a, Image &b, bool segmentation) : a(a), b(

cv::imwrite("edges_result.jpg", im);

//EDGE DETECTING
*/
#endif // EDGE_DETECTION

energy.resize(height, std::vector<double>());
#pragma omp parallel for
for (int i = 0; i < energy.size(); i++)
Expand All @@ -155,7 +162,9 @@ PanPixelEnergy::PanPixelEnergy(Image &a, Image &b, bool segmentation) : a(a), b(
for (int y = top; y < bottom; y++)
for (int x = left; x < right; x++)
if (a.inside(x, y) && b.inside(x, y)) {
//bool edge = false;
#ifdef EDGE_DETECTION
bool edge = false;
#endif
for (int dy = -frameSize; dy <= frameSize; dy++)
for (int dx = -frameSize; dx <= frameSize; dx++) {
int xx = x + dx;
Expand All @@ -166,14 +175,18 @@ PanPixelEnergy::PanPixelEnergy(Image &a, Image &b, bool segmentation) : a(a), b(
if (segmentation)
cost *= (isPR[labels[(yy - top) * width + xx - left]] ? 0.4 : 1);

/*if (gradient[yy - intersectionTop][xx - intersectionLeft] >= level)
edge = true;*/
#ifdef EDGE_DETECTION
if (gradient[yy - intersectionTop][xx - intersectionLeft] >= level)
edge = true;
#endif

energy[y - top][x - left] = std::max(energy[y - top][x - left], cost);
}
}
//if (edge)
// energy[y - top][x - left] *= 0.7;
#ifdef EDGE_DETECTION
if (edge)
energy[y - top][x - left] *= 0.7;
#endif
}

};
Expand All @@ -184,6 +197,4 @@ static inline int mhtDist(Pixel *a, Pixel *b) {

double PanPixelEnergy::calcEnergy(int x, int y) {
return energy[y - top][x - left];
//return abs(getI(a, x, y) - getI(b, x, y)) * (segmented && isPR[labels[(y - top) * width + x - left]] ? 0.4 : 1);
//return mhtDist(a.getPixel(x, y), b.getPixel(x, y)) * (segmented && isPR[labels[(y - top) * width + x - left]] ? 0.4 : 1);
}
12 changes: 11 additions & 1 deletion src/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void Runner::run(int argnum, char **args, SeamSolver &&solver, string prefix) {

// WHITE ELIMINATION

#ifdef VISUALIZATION

Mat preimage = Mat::zeros(cv::Size(width, height), CV_8UC3);
#pragma omp parallel for
for (int y = intersectionTop; y < intersectionBottom; y++)
Expand All @@ -155,6 +157,8 @@ void Runner::run(int argnum, char **args, SeamSolver &&solver, string prefix) {

imwrite("image" + to_string(num) + "_result.jpg", preimage);

#endif

Seam seam = solver.getSeam(image, im);

if (seam.edges.size() == 1) {
Expand All @@ -167,6 +171,8 @@ void Runner::run(int argnum, char **args, SeamSolver &&solver, string prefix) {
num++;

if (num != 1) {
#ifdef VISUALIZATION

Image copySeam = image.clone();
Image copyMark = image.clone();

Expand All @@ -175,9 +181,13 @@ void Runner::run(int argnum, char **args, SeamSolver &&solver, string prefix) {
Visualizer::markImage(im, 1);
copyMark.combine(im, seam);

imwrite((!filenames.empty() ? "" : to_string(num)) + prefix + "result" + ".jpg", image.image);
imwrite((!filenames.empty() ? "" : to_string(num)) + prefix + "seam_result" + ".jpg", copySeam.image);
imwrite((!filenames.empty() ? "" : to_string(num)) + prefix + "mark_result" +".jpg", copyMark.image);

#endif

imwrite((!filenames.empty() ? "" : to_string(num)) + prefix + "result" + ".jpg", image.image);

}

images.pop_back();
Expand Down
15 changes: 3 additions & 12 deletions src/solutions/pan_dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ Seam PanDijkstra::getSeam(Image& a, Image& b) {

if (intr.size() > 2) {
std::cout << "Diffucult area of intersection is ignored (photo " + b.filename + ")\n";
/*throw std::runtime_error("Difficult areas of intersection not supported yet (single component required). "
+ std::to_string(intr[0].first) + " "
+ std::to_string(intr[0].second) + "; "
+ std::to_string(intr[1].first) + " "
+ std::to_string(intr[1].second) + "; "
+ std::to_string(intr[2].first) + " "
+ std::to_string(intr[2].second) + "; ");*/
result.addEdge(getEdge(0, 0, 0, 1));
result.addEdge(getEdge(0, 0, 0, 1)); //crutch to show that ignored
return result;
}

Expand All @@ -91,8 +84,7 @@ Seam PanDijkstra::getSeam(Image& a, Image& b) {
l = m;
}


//VISUALISATION
#ifdef VISUALISATION

cv::Mat image = cv::Mat::zeros(cv::Size(intersectionWidth, intersectionHeight), CV_8UC4);
#pragma omp parallel for
Expand All @@ -109,10 +101,9 @@ Seam PanDijkstra::getSeam(Image& a, Image& b) {
to[i] = from[i];
}

//cv::imwrite(std::to_string(rand()) + "pan_dijkstra_bottleneck_area_result.jpg", image);
cv::imwrite("pan_dijkstra_bottleneck_area_result.jpg", image);

//VISUALISATION
#endif


std::vector<std::pair<int, int>> pixels = dijkstra(a, b, start, end, energy, pixelEnergy, r);
Expand Down

0 comments on commit c346005

Please sign in to comment.