diff --git a/CoinPictureManager/ChromaKey.cpp b/CoinPictureManager/ChromaKey.cpp index 8bc3de0..ef9a6e8 100644 --- a/CoinPictureManager/ChromaKey.cpp +++ b/CoinPictureManager/ChromaKey.cpp @@ -83,7 +83,13 @@ void chromaKey(Mat *img) { */ void updateDisplay() { Mat img_show; - Size newsize(900 * bgra.cols / bgra.rows, 900); //Resize image to a reasonable size +#ifdef _WIN32 + Size newsize(GetSystemMetrics(SM_CYSCREEN) - 200, (GetSystemMetrics(SM_CYSCREEN) - 200) * img_show.rows / img_show.cols); //Resize image to a reasonable size for display +#elif __linux__ + Display* d = XOpenDisplay(NULL); + Screen* s = DefaultScreenOfDisplay(d); + Size newsize(s->width - 200, (s->height - 200) * img_show.rows / img_show.cols); //Resize image to a reasonable size for display +#endif resize(bgra, img_show, newsize); //std::chrono::time_point start_time = std::chrono::system_clock::now(); diff --git a/CoinPictureManager/CoinPictureManager.cpp b/CoinPictureManager/CoinPictureManager.cpp index 3bfab8c..4be7d4d 100644 --- a/CoinPictureManager/CoinPictureManager.cpp +++ b/CoinPictureManager/CoinPictureManager.cpp @@ -76,13 +76,13 @@ std::string verify_str = "Files MUST be organized as follows : \n\ * @param root_dir Top directory (to search below) * @param verbose Verbose */ -int renameFiles(fs::path root_dir, boolean verbose) { +int renameFiles(fs::path root_dir, bool verbose) { std::cout << "Renaming files in subdirectories" << std::endl; - for (auto &d : fs::directory_iterator(root_dir)) { //Each sub-directory + for (auto &d: fs::directory_iterator(root_dir)) { //Each sub-directory if (fs::is_directory(d)) { int f_no = 0; if (verbose) std::cout << "\tDirectory: " << d.path().filename() << std::endl; - for (auto &f : fs::directory_iterator(d)) { //Each image file + for (auto &f: fs::directory_iterator(d)) { //Each image file if (isImage(f.path().extension().string())) { std::string name = std::to_string(f_no); name.insert(name.begin(), 4 - name.length(), '0'); @@ -105,13 +105,13 @@ int renameFiles(fs::path root_dir, boolean verbose) { * @param max_imgs Maximum number of images to use (-1 for all) * @param verbose Verbose */ -int createThumbnail(fs::path root_dir, int max_imgs, boolean verbose) { +int createThumbnail(fs::path root_dir, int max_imgs, bool verbose) { if (max_imgs > 0) { std::cout << "Creating thumbnail files in subdirectories with a maximum number of pictures " << max_imgs << "..." << std::endl; } else { std::cout << "Creating thumbnail files in subdirectories..." << std::endl; } - for (auto &d : fs::directory_iterator(root_dir)) { //Each sub-directory + for (auto &d: fs::directory_iterator(root_dir)) { //Each sub-directory if (fs::is_directory(d)) { if (verbose) std::cout << "\tDirectory: " << d.path().filename() << std::endl; createThumbnail(d.path(), 250, max_imgs); @@ -126,7 +126,7 @@ int createThumbnail(fs::path root_dir, int max_imgs, boolean verbose) { * @param root_dir Top directory (to search below) * @param verbose Verbose */ -int createWebp(fs::path root_dir, boolean verbose) { +int createWebp(fs::path root_dir, bool verbose) { std::cout << "Creating WebP images..." << std::endl; for (auto &d : fs::directory_iterator(root_dir)) { //Each sub-directory if (fs::is_directory(d)) { @@ -143,9 +143,9 @@ int createWebp(fs::path root_dir, boolean verbose) { * @param root_dir Top directory (to search below) * @param verbose Verbose */ -int chromaKey(fs::path root_dir, boolean verbose) { +int chromaKey(fs::path root_dir, bool verbose) { std::cout << "Running chroma keying..." << std::endl; - for (auto &d : fs::directory_iterator(root_dir)) { //Each sub-directory + for (auto &d: fs::directory_iterator(root_dir)) { //Each sub-directory if (fs::is_directory(d)) { if (verbose) std::cout << "\tDirectory: " << d.path().filename() << std::endl; for (auto &f : fs::directory_iterator(d)) { //Each image file @@ -165,9 +165,9 @@ int chromaKey(fs::path root_dir, boolean verbose) { * @param root_dir Top directory (to search below) * @param verbose Verbose */ -int cropImages(fs::path root_dir, boolean verbose) { +int cropImages(fs::path root_dir, bool verbose) { std::cout << "Cropping images..." << std::endl; - for (auto &d : fs::directory_iterator(root_dir)) { //Each sub-directory + for (auto &d: fs::directory_iterator(root_dir)) { //Each sub-directory if (fs::is_directory(d)) { if (verbose) std::cout << "\tDirectory: " << d.path().filename() << std::endl; for (auto &f : fs::directory_iterator(d)) { //Each image file @@ -187,7 +187,7 @@ int cropImages(fs::path root_dir, boolean verbose) { * @param command Integer command as defined in getSelection * @return success code */ -int runCommand(char command, boolean verbose, boolean interactive_mode, fs::path root_dir) { +int runCommand(char command, bool verbose, bool interactive_mode, fs::path root_dir) { switch (command) { case '1': return renameFiles(root_dir, verbose); @@ -226,7 +226,7 @@ int runCommand(char command, boolean verbose, boolean interactive_mode, fs::path * * @return status code */ -int runUI(fs::path root_dir, boolean verbose) { +int runUI(fs::path root_dir, bool verbose) { std::cout << help_str; while (1) { char sel; @@ -241,7 +241,7 @@ int runUI(fs::path root_dir, boolean verbose) { } int main(int argc, char **argv) { //Main loop - parse any command line options and run either command or interactive mode - boolean run_ui = false, verbose = false; + bool run_ui = false, verbose = false; std::vector commands; fs::path root_dir = fs::path(DEFAULT_PATH); @@ -257,7 +257,7 @@ int main(int argc, char **argv) { //Main loop - parse any command line options a verbose = true; } else if (argv[i][1] == 'c') { //Run command if (strlen(argv[i]) > 3 && argv[i][2] == '=') { - for (int c=3; c 0) { - for (int i = 0; i < commands.size(); i++) { + for (unsigned int i = 0; i < commands.size(); i++) { char comm = commands.at(i); int status = runCommand(comm, verbose, false, root_dir); if (status > 0) return 1; //Exit upon error diff --git a/CoinPictureManager/CropImages.cpp b/CoinPictureManager/CropImages.cpp index cd87eb2..f51b825 100644 --- a/CoinPictureManager/CropImages.cpp +++ b/CoinPictureManager/CropImages.cpp @@ -46,7 +46,7 @@ void getBounds(Mat img, Rect *bounding_rect) { vector> cnts; findContours(canny, cnts, RETR_TREE, CHAIN_APPROX_SIMPLE); - for (int i = 0; i < cnts.size(); i++) { + for (unsigned int i = 0; i < cnts.size(); i++) { float peri = arcLength(cnts[i], true); vector cnts_poly(1); approxPolyDP(cnts[i], cnts_poly, 0.0015 * peri, true); @@ -112,7 +112,13 @@ void onCropTrackbar(int sp, void *val) {//Update the current shown image plotBounds(&img_show, &bounding_rect); cropImage(&img_show, &bounding_rect); - Size newsize(GetSystemMetrics(SM_CYSCREEN)-200, (GetSystemMetrics(SM_CYSCREEN)-200) * img_show.rows / img_show.cols); //Resize image to a reasonable size for display +#ifdef _WIN32 + Size newsize(GetSystemMetrics(SM_CYSCREEN)-200, (GetSystemMetrics(SM_CYSCREEN)-200) * img_show.rows / img_show.cols); //Resize image to a reasonable size for display +#elif __linux__ + Display* d = XOpenDisplay(NULL); + Screen* s = DefaultScreenOfDisplay(d); + Size newsize(s->width - 200, (s->height - 200) * img_show.rows / img_show.cols); //Resize image to a reasonable size for display +#endif resize(img_show, img_show, newsize); imshow(crop_window_name, img_show); //Show final image } diff --git a/CoinPictureManager/Dependencies.h b/CoinPictureManager/Dependencies.h index cee9c1d..b27c399 100644 --- a/CoinPictureManager/Dependencies.h +++ b/CoinPictureManager/Dependencies.h @@ -1,20 +1,28 @@ #ifndef DEPENDENCIES_H -#define DEPENDENCIES_H + #define DEPENDENCIES_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace fs = std::experimental::filesystem; + #include + #include + #include + #include + #include + #include + #include + #include + #include + -using namespace std; -using namespace cv; + #ifdef _WIN32 + #include + #include + #elif __linux__ + #include + #include + #endif + + namespace fs = std::experimental::filesystem; + + using namespace std; + using namespace cv; #endif \ No newline at end of file diff --git a/CoinPictureManager/ImageFunctions.cpp b/CoinPictureManager/ImageFunctions.cpp index e2ddbfd..6f19fa4 100644 --- a/CoinPictureManager/ImageFunctions.cpp +++ b/CoinPictureManager/ImageFunctions.cpp @@ -24,9 +24,9 @@ * Determine if file is an acceptable image format based on extension * * @param ext String of the file extension (case-insensitive) - * @return boolean if file is an image + * @return bool if file is an image */ -boolean isImage(std::string ext) { +bool isImage(std::string ext) { std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); return ext==".jpg" || ext==".jpeg" || ext==".jpe" || ext==".jp2" || ext==".png"; } @@ -95,7 +95,7 @@ int createThumbnail(fs::path image_dir, int thumbnail_height, int max_pics) { * @param quality WebP image quality (0-100) * @param verbose Verbose */ -int createWebp(fs::path image_dir, int quality, boolean verbose) { +int createWebp(fs::path image_dir, int quality, bool verbose) { vector params; params.push_back(IMWRITE_WEBP_QUALITY); params.push_back(quality); diff --git a/CoinPictureManager/ImageFunctions.h b/CoinPictureManager/ImageFunctions.h index b195b93..607f235 100644 --- a/CoinPictureManager/ImageFunctions.h +++ b/CoinPictureManager/ImageFunctions.h @@ -3,10 +3,10 @@ #include "Dependencies.h" -boolean isImage(std::string ext); //Determine if the file is an image +bool isImage(std::string ext); //Determine if the file is an image int createThumbnail(fs::path image_dir, int thumbnail_height, int max_pics); //Create a thumbnail image given the images in the directory at path with a maximum number of pictures max_pics -int createWebp(fs::path image_dir, int quality, boolean verbose); //Create WebP versions of each JPEG image file in image_dir +int createWebp(fs::path image_dir, int quality, bool verbose); //Create WebP versions of each JPEG image file in image_dir #endif \ No newline at end of file diff --git a/CoinPictureManager/Makefile b/CoinPictureManager/Makefile new file mode 100644 index 0000000..f2cc390 --- /dev/null +++ b/CoinPictureManager/Makefile @@ -0,0 +1,27 @@ +CC := g++ +CFLAGS := -g -Wall -pedantic + +SRCS := $(wildcard *.cpp) +OBJS := $(patsubst %.cpp,%.o,$(SRCS)) + +LIBS := -lopencv_core -lopencv_photo -lopencv_highgui -lopencv_calib3d -lopencv_dnn -lopencv_features2d -lopencv_flann -lopencv_gapi -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lstdc++fs -lX11 +INCLD := -I/usr/local/include/opencv4 + +PROG := coinpicturemanager + +all: $(PROG) + +coinpicturemanager: $(OBJS) + ${CC} $(CFLAGS) -o $@ $^ $(LIBS) $(INCLD) + +%.o: %.cpp + ${CC} $(CFLAGS) -c $< $(INCLD) + +clean: + rm -rf $(OBJS) + +install: + mv $(PROG) /usr/local/bin/$(PROG) + +remove: + rm -rf /usr/local/bin/$(PROG) diff --git a/CoinPictureManager/Thumbnail.cpp b/CoinPictureManager/Thumbnail.cpp deleted file mode 100644 index 4a41835..0000000 --- a/CoinPictureManager/Thumbnail.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Thumbnail.cpp - Creates thumbnail images - * This file is part of CoinPictureManager. - * - * Copyright (C) 2020 PolarPiBerry - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include - -#include "Thumbnail.h" - -using namespace cv; - -int createThumbnail(const char *path, int max_no) { - Mat img = imread(path); - -} \ No newline at end of file diff --git a/CoinPictureManager/Thumbnail.h b/CoinPictureManager/Thumbnail.h deleted file mode 100644 index 5f8c3fb..0000000 --- a/CoinPictureManager/Thumbnail.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef THUMBNAIL_H -#define THUMBNAIL_H - -int createThumbnail(const char *path, int max_no); - -#endif \ No newline at end of file diff --git a/README.md b/README.md index a771046..6944b5d 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,22 @@ - For the latest stable version, please see the releases tab and download the EXE file. - Next, either place this file in the directory where you want to manage pictures or place it in a safe directory and add the variable to the path as above so it can be run globally (run the command `SET PATH=%PATH%;c:\PATH\TO\YOUR\EXE`) - *To download the latest code, clone this repository and open the project in Visual Studio* + ### Linux -*To be added* -## Usage +- A Makefile is provided for easy code compilation. Install make with `sudo apt-get install make` if you do not have it already. +- Run `make` in the CoinPictureManager directory to compile the code. The finished program will be in a file called coinpicturemanager. +- Use `make clean` to remove the build files +- To install the command system-wide, run `make install` (`make remove` to remove it). +## Usage `coinpicturemanager [DIRECTORY] [OPTIONS]` *Without a specified directory, the app uses the current directory. Without any options or when run as a desktop app on Windows, it will run in verbose interactive mode.* ### Options - -h Print this help - -i Interactive mode (default unless other option specified) - -v Verbose mode + -h Print this help + -i Interactive mode (default unless other option specified) + -v Verbose mode -c=COMMANDS Run command(s) (commands run in order listed; see available commands below) ### Commands