-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
186 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,71 @@ | ||
// | ||
// Created by Andy Mina on 3/7/23. | ||
// | ||
/** | ||
* Andy Mina | ||
* | ||
* File to test SeamCarver in C++ implementation. Given a path to an image, the target number of | ||
* rows, and the target number of cols, carves the image and displays the result. | ||
* | ||
* Args: | ||
* {path to img} | ||
* {target rows} | ||
* {target cols} | ||
*/ | ||
#include "timer.hpp" | ||
#include <seam_carving/carver.hpp> | ||
|
||
#include <opencv2/core.hpp> | ||
#include <opencv2/imgcodecs.hpp> | ||
#include <opencv2/highgui.hpp> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <chrono> | ||
|
||
namespace sc = seam_carving; | ||
|
||
template <class Duration = std::chrono::milliseconds, class Clock = std::chrono::steady_clock> | ||
class Timer { | ||
using time_pt = typename Clock::time_point; | ||
|
||
time_pt _start = Clock::now(); | ||
time_pt _end = {}; | ||
|
||
public: | ||
void tick() { _start = Clock::now(); } | ||
void tock() { _end = Clock::now(); } | ||
|
||
template <class T = Duration> | ||
auto duration() const { | ||
return std::chrono::duration_cast<T>(_end - _start).count(); | ||
} | ||
}; | ||
|
||
int main(int argc, char **argv) { | ||
if (argc != 4) { | ||
std::cout << "Usage: " << argv[0] << " {path to img} {target cols} {target rows}\n"; | ||
return -1; | ||
} | ||
|
||
const std::string input_path(argv[1]); | ||
const int target_cols(std::stoi(argv[2])); | ||
const int target_rows(std::stoi(argv[3])); | ||
|
||
cv::Mat img = cv::imread(input_path); | ||
std::cout << "Original size: " << img.cols << "x" << img.rows << "\n"; | ||
|
||
cv::Mat res = img; | ||
Timer carver_timer; | ||
|
||
std::cout << "Starting carving...\n"; | ||
|
||
carver_timer.tick(); | ||
sc::Carver::Carve(target_rows, target_cols, img, res); | ||
carver_timer.tock(); | ||
|
||
std::cout << "Carved size: " << res.cols << "x" << res.rows << "\n"; | ||
std::cout << "Carving took " << carver_timer.duration() << " ms\n"; | ||
|
||
int main() { | ||
std::cout << "hello world\n"; | ||
cv::imshow("Original", img); | ||
cv::imshow("Carved", res); | ||
int k = cv::waitKey(0); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.