2016-07-08 Perlbrew With Threads

I want to run fgallery on my laptop running OSX instead of uploading the images and running fgallery on the server in order to generate the album. Perhaps that’s stupid. Anyway, the first order of business is to compile a version of Perl that has threads.

fgallery

perlbrew install-multiple --both thread perl-5.22.0

Let’s see...

alex@Megabombus:~/src/fgallery-1.8.2$ perlbrew exec --with perl-5.22.0-thread-multi ./fgallery
perl-5.22.0-thread-multi
==========
Can't locate Image/ExifTool.pm in @INC (you may need to install the Image::ExifTool module) (@INC contains: /Users/alex/perl5/perlbrew/perls/perl-5.22.0-thread-multi/lib/site_perl/5.22.0/darwin-thread-multi-2level /Users/alex/perl5/perlbrew/perls/perl-5.22.0-thread-multi/lib/site_perl/5.22.0 /Users/alex/perl5/perlbrew/perls/perl-5.22.0-thread-multi/lib/5.22.0/darwin-thread-multi-2level /Users/alex/perl5/perlbrew/perls/perl-5.22.0-thread-multi/lib/5.22.0 .) at ./fgallery line 27.
...

OK, so now for dependencies, which have to be reinstalled.

alex@Megabombus:~/src/fgallery-1.8.2$ perlbrew use perl-5.22.0-thread-multi
alex@Megabombus:~/src/fgallery-1.8.2$ cpanm Image::ExifTool
--> Working on Image::ExifTool
Fetching http://www.cpan.org/authors/id/E/EX/EXIFTOOL/Image-ExifTool-10.20.tar.gz ... OK
Configuring Image-ExifTool-10.20 ... OK
Building and testing Image-ExifTool-10.20 ... OK
Successfully installed Image-ExifTool-10.20
1 distribution installed

I also got myself a copy of the facedetect. When I tried it:

facedetect

alex@Megabombus:~/src/facedetect-master$ ./facedetect
Traceback (most recent call last):
  File "./facedetect", line 8, in <module>
    import numpy as np
ImportError: No module named numpy

OK, the page mentions opencv and apparently Homebrew offers something like it.

opencv

alex@Megabombus:~/src/fgallery-1.8.2$ brew install homebrew/science/opencv
...
alex@Megabombus:~/src/fgallery-1.8.2$ ../facedetect-master/facedetect
usage: facedetect [-h] [--biggest] [--best] [-c] [--data-dir DIRECTORY] [-q]
                  [-s FILE] [--search-threshold PERCENT] [-o OUTPUT] [-d]
                  file
facedetect: error: too few arguments

I guess it works!

OK, so back to my “default” Perl and let’s check that command line.

alex@Megabombus:/Users/Shared/Fotos 2016$ perlbrew exec --with perl-5.22.0-thread-multi ~/src/fgallery-1.8.2/fgallery -f Saas\ Fee/Album/ 2016-saas-fee
perl-5.22.0-thread-multi
==========
error: cannot execute exiftran or exifautotran for lossless JPEG autorotation

OK, so more problems. Let’s install fbida.

fbida

alex@Megabombus:/Users/Shared/Fotos 2016$ brew install fbida
...
alex@Megabombus:/Users/Shared/Fotos 2016$ perlbrew exec --with perl-5.22.0-thread-multi ~/src/fgallery-1.8.2/fgallery -f Saas\ Fee/Album/ 2016-saas-fee
perl-5.22.0-thread-multi
==========
reading completed
facedetect: error: cannot load HAAR_FRONTALFACE_ALT2 from /usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml
error: command "facedetect --best --center 2016-saas-fee/imgs/P7020100.jpg" failed

OK, some data is missing. I downloaded a recent copy of the version 2 zip file and extracted just the data:

alex@Megabombus:~/src$ unzip /Users/alex/Downloads/opencv-2.4.13.zip "opencv-2.4.13/data*"
...

And then I tried again:

alex@Megabombus:/Users/Shared/Fotos 2016$ facedetect --data-dir /Users/alex/src/opencv-2.4.13/data/ --best --center 2016-saas-fee/imgs/P7020100.jpg

And it worked! (No output because it contains no face, I presume.)

So how can we pass this option from `fgallery` to `facedetect`? I think the simplest solution is to just change the `DATA_DIR` setting in `facedetect`:

alex@Megabombus:~$ diff ~/src/facedetect-master/facedetect bin/facedetect
21c21
< DATA_DIR = '/usr/share/opencv/'
---
> DATA_DIR = '/Users/alex/src/opencv-2.4.13/data/'

Oh, and I dedided to install the optional stuff as well.

alex@Megabombus:/Users/Shared/Fotos 2016$ brew install jpegoptim
...
alex@Megabombus:/Users/Shared/Fotos 2016$ brew install pngcrush
...
alex@Megabombus:/Users/Shared/Fotos 2016$ brew install p7zip
...
alex@Megabombus:/Users/Shared/Fotos 2016$ perlbrew exec --with perl-5.22.0-thread-multi cpanm Cpanel::JSON::XS
...

And now, finally, the test:

alex@Megabombus:/Users/Shared/Fotos 2016$ perlbrew exec --with perl-5.22.0-thread-multi ~/src/fgallery-1.8.2/fgallery -f Saas\ Fee/Album/ 2016-saas-fee
perl-5.22.0-thread-multi
==========
reading completed
processing completed
generating archive...
completed

Yay! Hours wasted but mission accomplished! 😄

Copy it over:

alex@Megabombus:/Users/Shared/Fotos 2016$ scp -r 2016-saas-fee/ alexschroeder.ch:alexschroeder.ch/gallery/
...

As it turns out, I dislike the stupid exif comments my camera leaves and sometimes I create little text files with alternate captions. Thus, I need the `-c txt` option. And then to copy it all over to the gallery.

gallery

alex@Megabombus:/Users/Shared/Fotos 2016$ perlbrew exec --with perl-5.22.0-thread-multi ~/src/fgallery-1.8.2/fgallery -c txt -f Saas\ Fee/Album/ 2016-saas-fee
...
alex@Megabombus:/Users/Shared/Fotos 2016$ rsync --progress --recursive 2016-saas-fee alexschroeder.ch:alexschroeder.ch/gallery/
...

​#Perl

Comments

(Please contact me if you want to remove your comment.)

New laptop, new problems...

Check dependencies:

sudo apt install imagemagick exiftran zip liblcms2-utils \
  jpegoptim pngcrush p7zip

Build new Perl with thread support and install the modules we need:

perlbrew install --thread perl-5.30.0
perlbrew use perl-5.30.0
cpan install App::cpanminus
cpanm Image::ExifTool
cpanm Cpanel::JSON::XS

– Alex Schroeder 2019-06-13 11:20 UTC