Kaynağa Gözat

PageNormalizer: Added option to rotate image

Thomas Chef 7 yıl önce
ebeveyn
işleme
5c07417ac2

+ 0 - 4
PageNormalizer/build-Debug/.gitignore

@@ -1,4 +0,0 @@
-# Ignore everything in this directory
-*
-# Except this file
-!.gitignore

+ 2 - 1
PageNormalizer/build-Mac/makefile

@@ -10,6 +10,7 @@ EXECUTABLE := PageNormalizer
 TARGET := ./$(EXECUTABLE)
 
 # Code Lists
+DEPS = ../pagenormalizer.h ../CImg.h
 SRCEXT := cpp
 SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
 OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
@@ -29,6 +30,6 @@ $(TARGET): $(OBJECTS)
 	@echo "Linking..."
 	@echo "  Linking $(TARGET)"; $(CC) $^ -o $(TARGET) $(LIB)
 
-$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
+$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) $(DEPS)
 	@echo "Compiling $<..."; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
 

+ 1 - 0
PageNormalizer/build-Mac/test.sh

@@ -0,0 +1 @@
+./PageNormalizer -r 90 -i ../example/IMG_0164.JPG -wref ../example/ref_white.jpg -bref ../example/ref_black.jpg -s ../example/settings.txt -o ./test.bmp

+ 0 - 4
PageNormalizer/build-Release/.gitignore

@@ -1,4 +0,0 @@
-# Ignore everything in this directory
-*
-# Except this file
-!.gitignore

BIN
PageNormalizer/example/IMG_0164.JPG


BIN
PageNormalizer/example/input_example.jpg


BIN
PageNormalizer/example/input_example2.jpg


BIN
PageNormalizer/example/ref_black.jpg


BIN
PageNormalizer/example/ref_white.jpg


+ 5 - 15
PageNormalizer/example/settings.txt

@@ -1,16 +1,6 @@
-This file contains settings for the PageNormalizer software
-Row 1 starts the line under "START:"
-Row and setting:
-1: x0 of Crop settings
-2: y0
-3: x1
-4: y1
-
+# Autogenerated file.
 START:
-291
-60
-3685
-2711
-
-
-
+374
+127
+3613
+2359

BIN
PageNormalizer/example/test1.JPG


BIN
PageNormalizer/example/test2.JPG


+ 5 - 1
PageNormalizer/main.cpp

@@ -25,8 +25,12 @@ int main(int argc, char *argv[])
     std::string file_o( cimg_option("-o","./output.jpg","Output file") );
     
     const bool quiet = cimg_option("-q",false,0);      // This is a hidden option
+
+    const int rotate = cimg_option("-r",0,0);
+
+    printf("Rot: %d\n ",rotate);
         
-    PageNormalizer pn = PageNormalizer(file_i, file_o, file_white_ref, file_black_ref, file_settings, quiet);
+    PageNormalizer pn = PageNormalizer(file_i, file_o, file_white_ref, file_black_ref, file_settings, quiet, rotate);
 
 
 

+ 12 - 1
PageNormalizer/pagenormalizer.cpp

@@ -7,7 +7,7 @@ PageNormalizer::PageNormalizer() {
     m_quiet = false;
 }
 
-PageNormalizer::PageNormalizer(const std::string inFile,const std::string outFile,const std::string whiteRef,const std::string blackRef,const std::string settingsFile, const bool quiet ) {
+PageNormalizer::PageNormalizer(const std::string inFile,const std::string outFile,const std::string whiteRef,const std::string blackRef,const std::string settingsFile, const bool quiet, const int rotate ) {
 
     m_quiet = quiet;
     
@@ -30,9 +30,20 @@ PageNormalizer::PageNormalizer(const std::string inFile,const std::string outFil
 
     NormalizeImage();
 
+    RotateImage(rotate);
+
     outImage.save_bmp( outFile.c_str() );
 }
 
+void PageNormalizer::RotateImage(const int rotAngle) {
+
+    if( rotAngle != 0 ) {
+        printf("Rotating %d degrees\n",rotAngle);
+        outImage.rotate(rotAngle);
+    }
+
+}
+
 void PageNormalizer::NormalizeImage()
 {
 

+ 2 - 1
PageNormalizer/pagenormalizer.h

@@ -10,7 +10,7 @@ class PageNormalizer
 {
 public:
     PageNormalizer();
-    PageNormalizer(const std::string inFile,const std::string outFile,const std::string whiteRef,const std::string blackRef,const std::string settingsFile, const bool quiet );
+    PageNormalizer(const std::string inFile,const std::string outFile,const std::string whiteRef,const std::string blackRef,const std::string settingsFile, const bool quiet, const int rotate );
 
 
 
@@ -18,6 +18,7 @@ public:
 private:
     void ReadSettings(const std::string inFile);
     void NormalizeImage();
+    void RotateImage(const int rotAngle);
 
     int GetWhiteness(unsigned int x,unsigned int y);
     int GetBlackness(unsigned int x,unsigned int y);