On Fr, 2015-10-02 at 15:45 +0000, Terrence Kovacs wrote: > Attached is an sdaps_recognize.py that I believe works correctly but > still uses the add_image from sdaps.add. > A diff is attached also.
Hm, the idea is fine in general, but it is not quite the way that I envisioned how the script works. What you are doing now is basically the same as an add + recognize + cs v export command would do if it does not save the survey afterwards[1]. The script however works differently, it takes one page of the input image, throws it into SDAPS, analyses it and then prints the result. With this approach nothing weird will happen if you have e.g. a multipage survey and the scan includes two first pages at the start. The script would simply print that data. SDAPS core however does not properly handle the case and will overwrite the data from the first page. Benjamin [1] Hm, that could be fun to implement. Just allow chaining multiple SDAPS command, leave out the implicit save in this case, or just have a --no-save option or so. So one could do: sdaps PROJECT add --no-copy input.tif ! recognize ! csv export -o out.csv or if you want to add the file normally: sdaps PROJECT add input.tif ! recognize ! csv export -o out.csv ! save which would just save some overhead for opening/saving the survey. > Terry > > Terrence Kovacs > Research Systems Engineer > Physics and Astronomy Department > Dartmouth College > Wilder 341, 603-646-9303 > > ________________________________________ > From: Terrence Kovacs <[email protected]> > Sent: Friday, October 2, 2015 7:56 AM > To: Benjamin Berg; [email protected] > Subject: Re: custom script sdap-recognize.py > > Yes - I realised this too after I sent that last note. Thanks very > much for the follow up. > Terry > > Terrence Kovacs > Research Systems Engineer > Physics and Astronomy Department > Dartmouth College > Wilder 341, 603-646-9303 > > ________________________________________ > From: Benjamin Berg <[email protected]> > Sent: Thursday, October 1, 2015 4:55 PM > To: Terrence Kovacs; [email protected] > Subject: Re: custom script sdap-recognize.py > > Ah, now I remember why the script does not use the routines from the > "add" package. Right now the add package unconditionally adds all > pages > of a tiff, while the script handles the input image on a page by page > basis. > > This will not make a difference for you if you are simply using > single > page tiffs, but does mean that your code is not quite correct either > unfortunately :) > > I'll need to properly fix this somehow so that the script works with > simplex projects with both simplex and duplex scans. > > /me opens a ticket to not forget. > > Issue #83. > > Benjamin > > On Do, 2015-10-01 at 18:03 +0000, Terrence Kovacs wrote: > > Thanks for the quick response. > > Yes it is a simplex document. > > Unfortunately the patch you sent threw this: > > [tkovacs@sunspot new]$ ./sdaps-recognize.py tenq tenq_scan.tif > > TIFFOpen: tenq/../DUMMY: No such file or directory. > > Traceback (most recent call last): > > File "./sdaps-recognize.py", line 74, in <module> > > survey.questionnaire.recognize.recognize() > > File "/usr/lib64/python2.7/site > > -packages/sdaps/recognize/buddies.py", line 479, in recognize > > res = self.identify(clean=False) > > File "/usr/lib64/python2.7/site > > -packages/sdaps/recognize/buddies.py", line 465, in identify > > self.obj.sheet.recognize.recognize() > > File "/usr/lib64/python2.7/site > > -packages/sdaps/recognize/buddies.py", line 55, in recognize > > image.surface.load() > > File "/usr/lib64/python2.7/site-packages/sdaps/surface.py", line > > 51, in load > > True if self.obj.rotated else False > > AssertionError: The image surface could not be created! Broken or > > non > > 1bit tiff file? > > > > after some tinkering I resorted to importing add_image from > > sdaps.add > > which does the correct magic. > > > > $ diff ../sdaps-1.1.10/custom-scripts/sdaps-recognize.py sdaps > > -recognize.py > > 31a32 > > > from sdaps.add import add_image > > 54,62d54 > > < > > < def add_image(survey, tiff, page): > > < img = model.sheet.Image() > > < survey.sheet.add_image(img) > > < # SDAPS assumes a relative path from the survey directory > > < img.filename = os.path.relpath(os.path.abspath(tiff), > > survey.survey_dir) > > < img.orig_name = tiff > > < img.tiff_page = page > > < > > 67,70c59 > > < add_image(survey, *images.pop(0)) > > < > > < if survey.defs.duplex: > > < add_image(survey, *images.pop(0)) > > --- > > > add_image(survey, images.pop(0)[0], survey.defs.duplex) > > > > > > Terrence Kovacs > > Research Systems Engineer > > Physics and Astronomy Department > > Dartmouth College > > Wilder 341, 603-646-9303 > > > > ________________________________________ > > From: Benjamin Berg <[email protected]> > > Sent: Wednesday, September 30, 2015 5:04 PM > > To: Terrence Kovacs; [email protected] > > Subject: Re: custom script sdap-recognize.py > > > > Hi, > > > > hm, interesting. My guess would be that you have a simplex > > document? > > Probably never tested the script in that case. > > > > Short explanation. SDAPS basically assumes internally that all > > surveys > > are printed and scanned in duplex mode. To handle simplex mode the > > "sdaps add" command inserts a special dummy page so that exactly > > this > > failure does not happen. > > > > If you scanned in simplex mode then apply the attached patch. If > > you > > scanned in duplex mode, then just run the second add_image there > > unconditionally instead. > > > > Benjamin > > > > > > On Mi, 2015-09-30 at 20:47 +0000, Terrence Kovacs wrote: > > > I have a sdaps tenq survey which I can run: > > > [tkovacs@sunspot new]$ sdaps tenq recognize > > > ----------------------------------------------------------------- > > > -- > > > -- > > > --------- > > > - SDAPS -- recognize > > > ----------------------------------------------------------------- > > > -- > > > -- > > > --------- > > > 6 sheets > > > > ############################################################### > > > > #| > > > 100% 00:00:01 > > > 0.219686 seconds per sheet > > > > > > without issue but the custom script throws an error. Am I doing > > > something wrong? > > > > > > [tkovacs@sunspot new]$ ./sdaps-recognize.py tenq tenq_scan.tif > > > Traceback (most recent call last): > > > File "./sdaps-recognize.py", line 73, in <module> > > > survey.questionnaire.recognize.recognize() > > > File "/usr/lib64/python2.7/site > > > -packages/sdaps/recognize/buddies.py", line 479, in recognize > > > res = self.identify(clean=False) > > > File "/usr/lib64/python2.7/site > > > -packages/sdaps/recognize/buddies.py", line 465, in identify > > > self.obj.sheet.recognize.recognize() > > > File "/usr/lib64/python2.7/site > > > -packages/sdaps/recognize/buddies.py", line 85, in recognize > > > self.duplex_copy_image_attr(failed_pages, 'rotated', > > > _("Neither > > > %s, %i or %s, %i has a known rotation!")) > > > File "/usr/lib64/python2.7/site > > > -packages/sdaps/recognize/buddies.py", line 292, in > > > duplex_copy_image_attr > > > second = self.obj.images[i + 1] > > > IndexError: list index out of range > > > > > > Terrence Kovacs > > > Research Systems Engineer > > > Physics and Astronomy Department > > > Dartmouth College > > > Wilder 341, 603-646-9303 > > > > > > > -- > To unsubscribe, send mail to [email protected].
signature.asc
Description: This is a digitally signed message part
