How can I convert PDF Files to TIFF files with compression (Group 4 compression) - python-imaging-library

I am trying to complete a task to convert PDF's to TIFF files with CCITT t.4 compression. I am using the PymuPDF library/Pillow. From the code below, I am can generate the TIFF files fine, but I can't seem to add the compression to them no matter what I try. Anyone have any idea how I can accomplish this?
import fitz
import os
mat = fitz.Matrix(300 / 72, 300 / 72) # sets zoom factor for 300 dpi
doc = fitz.open(r"C:\testtiff4\test.pdf")
page_count = doc.pageCount
for page in range(0, page_count):
page_load = doc.loadPage(page)
pix = page_load.get_pixmap(matrix=mat)
img_filename = os.path.join(r"C\testtiff4", "page-%04i.tiff" % page_load.number)
pix.pil_save(img_filename, format="TIFF", dpi=(300,300), compression="group4")
When running the above code, I get the error:
OSError: encoder error -2 when writing image file

You need to have libtiff installed in order to write Group4 compressed files. Check like this:
python -m PIL
Sample Output
--------------------------------------------------------------------
Pillow 8.0.1
Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:10:52)
[Clang 6.0 (clang-600.0.57)]
--------------------------------------------------------------------
Python modules loaded from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL
Binary modules loaded from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 8.0.1
--- TKINTER support ok
--- FREETYPE2 support ok, loaded 2.10.4
--- LITTLECMS2 support ok, loaded 2.10
--- WEBP support ok, loaded 1.1.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for 9.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.3.1
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.11
--- LIBTIFF support ok, loaded 4.1.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok

Related

Tessarect implementation JAVA

I'm trying to implement OCR recognition through Tessarect.
But at the moment I'm stuck with this error.
This is what I've done so far:
Homebrew tessarect
Download the API
Link the Jar with my project (build path > Configure build path > Add external Jar's
But when I compile my code this is the error
Error opening data file D:/Tess4J/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Warning: Invalid resolution 0 dpi. Using 70 instead.
I've downloaded the eng trained data and I've tried different stuff but I can't figure out how to solve this.
I'm running eclipse in macOS Catalina.
Thanks!
My situation
Set your datapath correctly.
Your location D:/Tess4J/tessdata/eng.traineddata is wrong

Deploy Shiny application with older version of particular package

This may be a stupid question, but I'm unable to solve the following issue:
I'm working on a Shiny-app and need an older version of lavaan to obtain the same results as a few weeks ago. I used the following code to install the older version locally: install_version("lavaan",version = "0.5-23.1097"), and I loaded this old version using library(lavaan) into my server.R file. I also added all possible dependencies to my list in the server.R file so that everything works fine locally.
However, when I try to deploy my application, I obtain the following at the end of my task log:
[2018-08-16T17:00:24.569989191+0000] Installing R package: quadprog (1.5-5)
* installing to library �/opt/R/3.4.0/lib/R/library�
* installing *binary* package �quadprog� ...
* DONE (quadprog)
[2018-08-16T17:00:24.749745586+0000] Building R package: lavaan (0.5-23.1097)
/mnt/packages/build /mnt
* installing to library �/opt/R/3.4.0/lib/R/library�
* installing *source* package �lavaan� ...
** package �lavaan� successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/opt/R/3.4.0/lib/R/library/quadprog/libs/quadprog.so':
libRblas.so: cannot open shared object file: No such file or directory
ERROR: lazy loading failed for package �lavaan�
* removing �/opt/R/3.4.0/lib/R/library/lavaan�
Apparently, it is able to find the old lavaan version and unpack it, but as soon as it performs this lazy loading action, it breaks down.
Does anybody know where I could eliminate this lazy loading or perhaps where to find this quadprog.so or libRblas.so file? I assume that something more essential is going on, but I can't figure it out. Below, you can find my sessionInfo() output.
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252 LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Belgium.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lavaan_0.5-23.1097 quadprog_1.5-5 MASS_7.3-47 numDeriv_2016.8-1 htmlwidgets_1.0 jsonlite_1.5 htmltools_0.3.6
[8] yaml_2.2.0 tibble_1.4.2 DT_0.2 ggplot2_2.2.1 rmarkdown_1.8 stringi_1.1.7 foreign_0.8-67
[15] magrittr_1.5 rsconnect_0.8.5 shinyjs_0.9.1 shinythemes_1.1.1 shiny_1.1.0 devtools_1.13.6
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 git2r_0.18.0 pillar_1.3.0 compiler_3.4.0 later_0.7.3 plyr_1.8.4 bitops_1.0-6 tools_3.4.0
[9] digest_0.6.12 memoise_1.1.0 evaluate_0.10.1 gtable_0.2.0 rlang_0.2.1 rstudioapi_0.6 curl_3.1 pbivnorm_0.6.0
[17] httr_1.2.1 withr_1.0.2 stringr_1.2.0 knitr_1.17 stats4_3.4.0 rprojroot_1.2 grid_3.4.0 R6_2.2.2
[25] RJSONIO_1.3-0 backports_1.1.0 scales_0.4.1 promises_1.0.1 mnormt_1.5-5 mime_0.5 xtable_1.8-2 colorspace_1.3-2
[33] httpuv_1.4.5 miniUI_0.1.1 RCurl_1.95-4.8 lazyeval_0.2.0 munsell_0.4.3 crayon_1.3.4
Many thanks in advance!!
Kind regards
Apparently, my issue had nothing to do with managing package versions.
The solution can be found on this link, thanks to Joshua Spiewak.
The gist is that the package quadprog was improperly compiled, although it was successfully installed. Flushing the package from the cache for R 3.4.0 solved the issue.
Thank you all for helping out!
Try using packrat to manage you package versions. This is how I run shiny apps with different versions of packages and it makes them deployable to connect servers in a way that maintains the correct package.

Codec Not Found

I'm trying to read a AVI file into MATLAB using VideoReader.
video = VideoReader('test.avi');
But get this error:
The file requires the following codec(s) to be installed on your system:
cvid
Error in VideoReader (line 147)
obj.init(fileName);
Error in video (line 1)
video = VideoReader('test.avi');
The cvid codec is installed on my win7 64bit box. Any help? I am required to use VideoReader.
EDIT: MATLAB version is 2013a
From here, here and also the document on aviwriter which specifies that you can use "'Cinepak' on 32-bit systems.", I think the issue is with the combination of that specific codec and your 64 bit version of MATLAB. You probably have software on your computer which can handle 32 bit codecs so will be able to view it with some video player software, but MATLAB will be looking for the 64 bit codec (which for Cinepak is non-existent).
Your options would seem to be:
Convert the file to another codec or to an uncompressed version.
Install or get access to a 32-bit version of MATLAB

Modelsim .WLF file version error

I am using Modelsim ALTERA STARTER EDITION 10.1d and am importing a waveform file but am getting the following error.
The WLF file version is 132.Modelsim 10.1d can read up to and including WLF file version 121.
I have tried importing the same file into Modelsim 13.1 and am still receiving similar problems. If anybody knows what version of Modelsim I need to open this file version your help would be most appreciated. Thanks!
It looks like the version number is the fourth byte in the WLF header (121 = 0x79). I manually edited a version 121 file to bump up this field and got the same version warning you are seeing. Your version 132 file should have 0x84 in its fourth byte. You could manually edit the file to reduce its version and hope the format is otherwise compatible with the older version of Modelsim but there are no guarantees.

How to produce lighter mongodb c++ driver

I'm compiling mongoclient with MSVC 2012 and boost 1.54 and the generated lib size is about 117 mb !
I am doing something wrong ?
I'm using this command:
scons --extrapath=c:\dev\boost_1_54_0 --release --32 mongoclient
Self response: The huge size is due to 2 things : static library and debugging symbols non stripped from it. Version 2.5 will produce dynamic lib (dll) and separate debugging symbol (pdb).