Reading PDF file using OpenCV - c++

Is it possible to convert a PDF file to cv::Mat?
I know that PDF file is generally vector of objects, but given a required resolution. Is there any tool that can do such a conversion?

OpenCV doesn't support pdf format at all, so you should convert pdf page to image using another library. Read this discussion: Open source PDF library for C/C++ application?
Also this question is similar to yours: What C++ library can I use to convert a PDF to an image on windows?

Related

How to convert a PDF to image format (jpeg, png,...) using my C program?

I'm working with Visual Studio and OpenCV for image processing, but all my documents are PDF so I need to convert them to image format so I can compatibilize them with OpenCV
This is my code to open a image:
enter image description here
Is there any way to modify it to open and read PDF's as an image?
Many thanks!
You may want to take a look at ImageMagick. The CLI tool is able to convert PDF to images and I believe they provide C libraries too.

Compress Pdf using c++

I have a c++ application in Qt where I create a pdf file. How can I compress the pdf file so it is smaller. Is there a free c++ lib that is available and easy to use?
Two usual methods:
qCompress \ qUncompress from the QByteArray class let you do that. Just read the content of a QFile with readAll or as you please, and then use these methods: qCompress. This is clearly the easiest solution, but are somehow tied to Qt, and cannot easily export to a specific format
7zip which is licenced under LGPL, and which you can integrate as sources files, or as a library : 7zip, and the download page with sources. A bit more involving, but let you compress and uncompress in various formats, as long as you are fine with 7zip license (to put it in perspective, Qt OpenSource is at the time mostly LGPLv3)
However, as hinted by RyanP, don't expect a huge compression ratio, as PDF are already compressed. A quick test on a 920kB PDF with basic 7zip compression yielded a 860kB file, corresponding to a only 6.5% compression.

How would you read the data from a TIF image in OCaml?

I would like to process Landsat8 raw data with OCaml. The data is stored in TIF files. An example of such a file can be found here:
http://landsat-pds.s3.amazonaws.com/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF
How can I read a TIF file in OCaml? Is there a library that already does this?
If you're working with a Landsat or other GeoTIFF image you may want to use bindings to GDAL for more complete support: https://github.com/hcarty/ocaml-gdal and http://gdal.org/
GDAL allows you to access the raw values and their geospatial information - location, projection and whatever else is included in the underlying TIFF.
I have not used it in many years, but there is a library named camlimages that claims to support TIF files. You can install it with OPAM.

How can I pass TIFF image data to JUCE (which does not support TIFF)?

I am using learning gui programming using c++ JUCE library. That library have supports for image file format(png, jpg). But I wants to learn how can I use other file format for example tiff.
After google I got libtiff.
My question is what will be the accurate approach for displaying this. Should I need to convert .tiff file into jpeg/png from tiff for doing this.
But I think this will require double processing.
Can anyone explain the raw/native/basic image file format so that I need to convert all images into that type and use it directly.
As I find something in winAPI for dealing with images in which they use image data from file format.
It will be very helpful if someone can let me know the approach for handling images data and displaying it.
Can anyone explain the raw/native/basic image file format so that I need to convert all images into that type and use it directly.
There is no "native" image file format, but RGB comes close (especially if you strip the headers to give just a Width×Height×Channels array of pixel values). You probably wouldn't want to use this for storing everything though as your buffers will be very large. Let your libraries handle storage.
It will be very helpful if someone can let me know the approach for handling images data and displaying it.
There is no "the" approach. C++ itself doesn't say anything about images, and there are loads of ways you can go about working with them. Your design will depend on your functional requirements specification and on what libraries you have available.
I am using learning gui programming using c++ JUCE library. That
library have supports for image file format(png, jpg). But I wants to
learn how can I use other file format for example tiff.
After google I got libtiff.
My question is what will be the accurate approach for displaying this.
Should I need to convert .tiff file into jpeg/png from tiff for doing
this.
But I think this will require double processing.
If you mean using libtiff to convert TIFF-format images to formats that JUCE supports, you're right in saying that this introduces an extra initial processing step. However, as far as you've said, it sounds like any possible performance hit through this will be vastly, wildly and hugely outweighed by the benefit of simplicity and clarity. So I'd just do that.
In order to do something like read *.tiff images and using them in an application build with the JUCE framework, I would suggest to create a new class derived from the base interface ImageFileFormat.
class MyTiffFormat : public ImageFileFormat
{
private:
MyTiffFormat( const MyTiffFormat& );
MyTiffFormat& operator=( const MyTiffFormat& );
public:
MyTiffFormat();
~MyTiffformat();
const String getFormatName();
bool canUnderStand();
Image decodeImage( InputStream& input );
bool writeImageToStream( const Image& source, OuptputStream& dest );
};
Implementing the function "Image decodeImage( InputSTeram& input )" is the point were you need something like libtiff. In the JUCE source tree you will find the implementation for PNG and the other supported formats in the folder: \juce\src\gui\graphics\imaging
More information on extending JUCE features can be found in the JUCE user forum.
Juce works great with pngs, jpgs, and gifs (not animated), and they can be read from file, or even "compiled" with the BinaryBuilder.
For example to load it from compiled c++ with BinaryBuilder.
someImage = ImageFileFormat::loadFrom (AppResources::image_png, AppResources::image_pngSize);
Check out the doxygen docs, they are quite helpful. to compile your images with BinaryBuilder the syntax is:
./BinaryBuilder someFolder otherFolder ClassName

Is it possible to open PDF files in Turbo C++ and if so, how?

I am doing a project in C++ and I want to open PDF files. How can I do it in turbo c++? Do I have to switch to another IDE?
Edited:
I am doing an "E-book management" in c++. After managing the software i wanted to open pdf file through my program and do no access adobe reader or aome other. Sorry for incomplete question.
You can add PDF support to your application with TechSoft's PDF library. Which IDE you use shouldn't matter.
If your intention is to open the PDF for viewing (like you probably do with your PDF viewer, e.g. Acrobat Reader), and not to open the file programmically, you cannot do it in Turbo C++ IDE.
Try opening the IDE in non-full-screen window, and you will be able to see the IDE and the PDF (in the Acrobat Reader) at the same time.
The Poppler library is a C++ library for rendering PDFs to any arbitrary format, whether to screen or image. It's very easy to extend, and I wrote a program for rendering PDFs to a custom image format in about 150 lines, in a little under 5 hours - and most of that work was in exporting the custom image format. A simple renderer came in under 50 lines and took me less than an hour to write.