Even then Odd pages, can scan tailor combine?

Scan Tailor specific announcements, releases, workflows, tips, etc. NO FEATURE REQUESTS IN THIS FORUM, please.

Moderator: peterZ

Post Reply
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Even then Odd pages, can scan tailor combine?

Post by rwreed »

I have a single camera setup, so I scan all even pages then odd pages. I usually use rotateall.exe to put them together but I get strange results if I have an odd number of pages. Is there a way to have scan tailor help me with this?

Thanks in advance
Randy
atarkri
Posts: 14
Joined: 08 Jan 2011, 13:29

Re: Even then Odd pages, can scan tailor combine?

Post by atarkri »

rwreed wrote:I have a single camera setup, so I scan all even pages then odd pages. I usually use rotateall.exe to put them together but I get strange results if I have an odd number of pages.
Hello, I'm the author of "rotateall.exe". What do you mean by "strange results?"

I cannot infer from your post what the problem is; so I will solve all problems:

1) Having an odd number of pages causes the first half to rotate correctly, but one is missed and rotated the wrong way.

Solution: Copy the first image (alphabetically) and rename the copy so that it comes before the first image (alphabetically). For instance, if you have the image set {DCM_1066.jpg, DCM_1067.jpg, DCM_1068.jpg ...} you would copy "DCM_1066.jpg" and then rename the copy "DCM_1065.jpg"

2) Having an odd number of pages causes the program to crash.

Solution: See 1)

3) Solution to 1) did not work.

Solution: Instead try copying the last image (alphabetically) and renaming the copy so that it comes after all other images
(alphabetically).

----
To answer your original question:
Yes, you could fix problems 1,3 in scantailor. Chances are your problem is something I haven't thought of. Would you mind posting more detail?

To be clear, scantailor will rotate images, crop them, produce high-contrast (black and white) output, etc. It is a full-featured post-processing program. "rotateall.exe" is just a little "script-as-an-exe" to help do lots of image rotations, quickly. There are other (interactive) programs that will allow you to do many rotations (batch rotate), such as Infranview, imagemagick, and scantailor.
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Re: Even then Odd pages, can scan tailor combine?

Post by rwreed »

Atarki,

Thank you so much for your program and your response. Since I was asking about scantailor, I was not descriptive about my rotateall problem, but you are correct the problem was #1, with an odd number of pages I ended up with pages out of sequence.
So I appreciate your answer there. :D

But I'm intrigued, I'm running rotateall in wine, but you seem to indicate its a shell script, is that right? Do you have the code posted somewhere. I looked for it when I started all this and did not find it. Can you direct me to it?

Thank so much.
Randy
atarkri
Posts: 14
Joined: 08 Jan 2011, 13:29

Re: Even then Odd pages, can scan tailor combine?

Post by atarkri »

Yeah man, my bad. I was even reviewing the code to make sure I hadn't put some bad logic in. ("Script" isn't entirely correct, it is a c program, it's just intended to mimic a simple script in imagemagick; which I don't have handy anymore, way of the dinosaurs and all that.) You didn't indicate whether you were running Linux, FreeBSD or Mac. I'll assume Linux; the following instructions are different for FreeBSD and Mac (but I'm not going to write this all out 3x)

The source code:
http://www.mattikariluoma.com/files/rotateNrightNleft.c

Dependencies are libjpeg-dev and gcc. On a Debian-based (Debian, Ubuntu, ...) system, they can be installed via:

Code: Select all

sudo apt-get install libjpeg-dev gcc
The code can be compiled on Linux via:

Code: Select all

gcc -ljpeg rotateNrightNleft.c -o rotateall
----
On a side note; the libjpeg version is for cross-compatibility reasons. If you want better performance, I'd use OpenCV instead of libjpeg. (Not that OpenCV isn't cross-compatible, I just needed to hammer out something quickly, and libjpeg was very easy to use. I've since been using OpenCV everywhere, but it's still easier to distribute to Windows with libjpeg, due to filesize)

The (equivalent) source code:
http://www.mattikariluoma.com/files/ope ... ateall.cpp

Dependencies are libopencv-dev and g++. On a Debian-based (Debian, Ubuntu, ...) system, they can be installed via:

Code: Select all

sudo apt-get install libcv-dev libhighgui-dev g++
The code can be compiled on Linux via:

Code: Select all

g++ opencv_rotateall.cpp -I /usr/include/opencv -lcv -lhighgui -o rotateall
On my machine, I see an improvement from 1.2s per image (libjpeg) to .7s per image (OpenCV).
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Re: Even then Odd pages, can scan tailor combine?

Post by rwreed »

Atarki,

I compiled the opencv version but when I ran it I got this error.
*** glibc detected *** rotateall: malloc(): memory corruption: 0x09592ff0 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x1c0591]
/lib/tls/i686/cmov/libc.so.6(+0x6e395)[0x1c3395]
/lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x5c)[0x1c4f9c]
rotateall[0x8049257]
rotateall[0x80498ca]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x16bbd6]
rotateall[0x8048e81]

(I can post the memory map as well if you'd like but I figure this would get us started).
Any ideas?

I'll try the other one next.
Randy
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Re: Even then Odd pages, can scan tailor combine?

Post by rwreed »

I tried the other libjpeg one as well, and it seg faults about 3/4 the way through.

btw I'm using ubuntu 10.04

Thanks again
Randy
atarkri
Posts: 14
Joined: 08 Jan 2011, 13:29

Re: Even then Odd pages, can scan tailor combine?

Post by atarkri »

Oh my.

First up is enabling debugging symbols. This is done at compile time with the "-g" switch:

Code: Select all

gcc -ljpeg rotateNrightNleft.c -o rotateall -g 

Code: Select all

g++ opencv_rotateall.cpp -I /usr/include/opencv -lcv -lhighgui -o rotateall -g
Then we install gdb, the GNU Debugger. For Debian/Ubuntu:

Code: Select all

sudo apt-get install gdb
We now run the misbehaving programs inside gdb. gdb will drop you down to a shell, the commands we'll use once inside the shell will be "run <args>" and "bt" (backtrace).

Say you'd normally run:

Code: Select all

./rotateall some/folder/
...and you experience a crash/segfault. Instead we run:

Code: Select all

gdb rotateall
(gdb) run some/folder/
# Wait for it to crash...
(gdb) bt
# Investigate/post results on the forum
(gdb) quit
# when done, just quit, saying 'y' to killing the program
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Re: Even then Odd pages, can scan tailor combine?

Post by rwreed »

Ok so for opencv version I get this

Code: Select all

#0  0x0012d422 in __kernel_vsyscall ()
#1  0x0050e651 in raise () from /lib/tls/i686/cmov/libc.so.6
#2  0x00511a82 in abort () from /lib/tls/i686/cmov/libc.so.6
#3  0x0054549d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4  0x0054f591 in ?? () from /lib/tls/i686/cmov/libc.so.6
#5  0x00552395 in ?? () from /lib/tls/i686/cmov/libc.so.6
#6  0x00553f9c in malloc () from /lib/tls/i686/cmov/libc.so.6
#7  0x08049257 in rotateAllInDirectory (
    dir_name=0xbffff47d "/home/randy/MyDocuments/ebooks/Boer_Manifesto/")
    at opencv_rotateall.cpp:101
#8  0x080498ca in main (argc=2, argv=0xbffff2a4) at opencv_rotateall.cpp:171
for the libjpeg version I get this

Code: Select all

#0  0x001bbc1c in ?? () from /lib/tls/i686/cmov/libc.so.6
#1  0x001beecd in free () from /lib/tls/i686/cmov/libc.so.6
#2  0x080497e6 in loadDirectory (
    myDir=0xbffff46d "/home/randy/MyDocuments/ebooks/Boer_Manifesto/")
    at rotateNrightNleft.c:220
#3  0x0804995b in main (argc=2, argv=0xbffff294) at rotateNrightNleft.c:252
I'm not a C programmer so I'm afraid I can't be much help in debugging this. But I'm happy to try anything you like.
Thanks
Randy
atarkri
Posts: 14
Joined: 08 Jan 2011, 13:29

Re: Even then Odd pages, can scan tailor combine?

Post by atarkri »

For the OpenCV version, the problem is in allocating more memory for filenames.
In the libjpeg version, the problem is in freeing some memory for filenames.

These both imply malloc() isn't able to get enough memory, are you running on a resource-constrained system?

I'll freely admit I have no experience reading in directories and managing string memory for such a task. Perhaps I'm doing something horrible in the code.

----
My first concern, however, isn't that my code runs well, it's that the user (i.e. you) can perform the action you've set out to do. Since you're using a Linux system, I can reach for the easy solution, which is to let the OS and shell handle directory and filename recursion. Following is a bash script (and supporting files) to do so:

http://www.mattikariluoma.com/files/rot ... ipt.tar.gz

Inside that archive are three files (in a directory): rotateall.sh, jpeg_rotate.c, and opencv_rotate.cpp

Either jpeg_rotate.c or opencv_rotate.cpp file can be compiled to make the executable "rotate"

Code: Select all

gcc -lm -ljpeg jpeg_rotate.c -o rotate
# OR
g++ opencv_rotate.cpp -I /usr/include/opencv -lcv -lhighgui -o rotate
The usage:

Code: Select all

./rotate
Usage: ./rotate <input-filename> <degrees-clockwise> <output-filename>
Now then, when we run the "rotateall.sh" command, it will look for this "rotate" executable (it looks in the same directory where "rotateall.sh" is located) and apply it in an equivalent way as my earlier "rotateall" executables.

Code: Select all

./rotateall.sh some/folder
As a bonus, the execution is even faster, down to .02 sec per image (43X faster!?), although I think my "time" utility might be lying to me.

If this still fails, I'll just re-write that damn imagemagick script.
rwreed
Posts: 21
Joined: 23 Jan 2011, 16:15

Re: Even then Odd pages, can scan tailor combine?

Post by rwreed »

Ah, that works wonderfully! I took off the & at the end of the processing lines cause it caused x to restart. And I added a echo line so I could see what it was doing. But I do think its much faster.

Thanks so much! You Rock!

Randy
Post Reply