Using c++ to decode qr code from a png to a link - c++

I am currently in the process of learn c++ and I have decided to make a simple program that takes a .png file and exports the link inside it. I have looked it up and discovered ZXing but I still can't figure out how to implement it easily.
The ones I've found consists of scanning using webcam etc instead of a very simple version.

First, you need a library to read the images. CImg is good, it is a header only library build on top of the base libraries for the different images format: https://cimg.eu/
Assuming the image is a clean QR code you can skip the complex computer vision recognition part.
For the decoding part I am not sure, I don't know ZXing but it looks like the c++ port is no longer maintained anyway. Still, once you have the clean image it should not be a problem to use it.

You might want to have a look at the most recent c++ port of ZXing: https://github.com/nu-book/zxing-cpp
The project includes a trivial example application that does exactly what you want.

Related

C++: Writing images to video file independent of installed codecs

I'm trying to save a series of images (16 bit grayscale pgm) as video. The video has to be compressed. My program has to be independent of the codecs installed in the system.
My initial idea was to use OpenCV for this, unfortunately it depends on codecs installed in the system (unless I'm missing something).
I feel like there should be a way to compile an encoder (H264 or similar would be perfect) into the program or redistribute it as a dll with my program. I just can't find any good up to date guidance/examples.
I've been swimming in the deep vast ocean of AV encoding for a couple of days and would really appreciate it if someone could point me to a right direction.
Thanks.
As Ben suggests, it would be a good idea to use an established library in your code.
FFMPEG is probably the most used at the moment - it can be used on the command line, with a 'wrapper' program or the libraries it is built with can be used directly.
I think the last case sounds like the one you want - you can find documentation here:
https://trac.ffmpeg.org/wiki/Using%20libav*
Note the comment about disambiguation at the start - this is important to understand as the project lib and the library (which is what you want) are different things.
and there is some notes in this answer on how to build it into a program:
FFMpeg sample program

Allegro 5 ALLEGRO_BITMAP to text file

I'm currently working on a video game project in C++ using Allegro 5 as my graphics library. I store my graphic and font assets in subfolders within the root folder of the .exe. To use them in the program, I have an initGraphics() function that loads all the required assets through al_load_bitmap(), and then later free up the memory with al_destroy_bitmap(). This means however that when I eventually distribute my game, it'll be super easy for anyone to go into the install folder and just edit the graphics to be whatever, and I'm having trouble finding any kind of help regarding how to prevent this.
What I was thinking maybe is some kind of program that I'd run on my own computer before distribution that loads the appropriate graphical assets, and somehow converts them into a .txt file, then changing the main game executable's 'initGraphics()' function to load and use those instead of just the raw .png files, but I'm not sure if this is possible. Any information about this type of conversion would be hugely appreciated, or alternatively a more reliable tested method that achieves the same effect. Thank you very much in advance!
While researching the internet I've found interesting solution:
Allegro5 uses PhysicsFS library to handle file archives. It does not support password protected archives, but you can calculate md5 for your assets archive and hardcode it into your program and then compare it on runtime (source - see more here).
See this part of documentation of Allegro5.
Example explanation of md5 implementation is here

Raw Images, and DCRaw in C++

I want to be able to work with RAW images in C++ so I downloaded an already compiled DCRaw executable. I tried compiling it myself but I kept getting errors. So I want to be able to read in raw images to C++ and work with them. What would be the best way to do this? Should I find a way to include dcraw.c in my projects and call functions in that, or should I access the EXE file using the system(...) function?
If you don't want to manipulate the raw data directly in your application then yes you should use an already existing implementation of a raw image decoder (such as dcraw, like you said).
Here is what I would do in order of preference:
I would first try to find another raw image decoder that is available as a static or dynamic library version and link to that (dcraw only has an executable).
If #1 is not possible, I would extract the relevant parts of dcraw into a static library and link to that.
If not possible, I would include the .c file in my code like you have proposed.
I would only execute the EXE from within my program as a last resort.
That being said, if your application is for experimentation purposes only I don't see anything wrong in using the dcraw EXE from within your program. Otherwise I would not do this in a professional application.

Absolute beginners guide to working with audio in C/C++?

I've always been curious about audio conversion software, but I have never seen a proper explanation from a beginners point of view as to how to write a simple program that converts for example, a mp3 file to a wav. I'm not asking about any of the complex algorithms involved, just a small example using a simple library. Searching on SO, I came up with several names including:
Lame
The Synthesis Toolkit
OpenAL
DirectSound
But I'm unable to find a straightforward example of any of these libraries. Usually I don't mind wading through tons of code, but here I have absolutely no knowledge about the subject and so I always feel like I'm shooting in the dark.
Anyone here have a simple example / tutorial on converting a sound file using any of these libraries? My question is specifically directed towards C/C++ because those are the two languages I'm currently learning and so I'd like to continue to focus on them.
Edit: One thing I forgot to mention: I'm on a *NIX system.
Thanks everyone for the responses! I sort of cobbled them together to successfully make a small utility that converts a AIFF/WAV/etc file to an mp3 file. There seems to be some interest in this question, so here it what I did, step by step:
Step 1:
Download and install the libsndfile library as suggested by James Morris. This library is very easy to use – its only shortcoming is it won't work with mp3 files.
Step 2:
Look inside the 'examples' folder that comes with libsndfile and find generate.c. This gives a nice working example of converting any non-mp3 file to various file formats. It also gives a glimpse of the power behind libsndfile.
Step 3:
Borrowing code from generate.c, I created a c file that just converts an audio file to a .wav file. Here is my code: http://pastie.org/719546
Step 4:
Download and install the LAME encoder. This will install both the libmp3lame library and the lame command-line utility.
Step 5:
Now you can peruse LAME's API or just fork & exec a process to lame to convert your wav file to an mp3 file.
Step 6: Bring out the champagne and caviar!
If there is a better way (I'm sure there is) to do this, please let me know. I personally have never seen a step-by-step roadmap like this so I thought I'd put it out there.
For converting between various formats (except MP3) check libsndfile http://mega-nerd.com/libsndfile/
Libsndfile is a library designed to
allow the reading and writing of many
different sampled sound file formats
(such as MS Windows WAV and the
Apple/SGI AIFF format) through one
standard library interface.
During read and write operations,
formats are seamlessly converted
between the format the application
program has requested or supplied and
the file's data format. The
application programmer can remain
blissfully unaware of issues such as
file endian-ness and data format
It is also simple to use, with the API following the style of the Standard C library function names:
http://mega-nerd.com/libsndfile/api.html
And examples are included in the source distribution.
For actual audio output, another library will be needed, SDL as already mentioned might be a good place to start. While SDL can also read/write audio files, libsndfile is far superior.
If your curious about DSP and computers, take a look at the Synthesis Toolkit. It's sweet. It's designed for learning. The examples and tutorials they have on their website are straightforward and thorough. Keep in mind, the guys who wrote it, wrote it so they could create acoustic models of real instruments. As a result, they've included some instruments that are just plain wacky, but fun. It will give you a core understanding of processing PCM sound. And you'll probably be able to hack together some fun little noisemakers while your at it.
https://ccrma.stanford.edu/software/stk/
Check libmad http://mad.sourceforge.net " "M"peg "A"udio "D"ecoder library", should provide a good example.
Also for an easy cross-platform audio handling, check SDL http://www.libsdl.org/.
Hope that helps.

Decode JPEG to obtain uncompressed data

I want to decode JPEG files and obtain uncompressed decoded output in BMP/RGB format.I am using GNU/Linux, and C/C++.
I had a look at libjpeg, but there seemed not to be any good documentation available.
So my questions are:
Where is documentation on libjpeg?
Can you suggest other C-based jpeg-decompression libraries?
The documentation for libjpeg comes with the source-code. Since you haven't found it yet:
Download the source-code archive and open the file libjpeg.doc. It's a plain ASCII file, not a word document, so better open it in notepad or another ASCII editor.
There are some other .doc files as well. Most of them aren't that interesting though.
Unfortunately I cannot recommend any other library besides libjpeg. I tried a couple of alternatives, but Libjpeg always won. Is pretty easy to work with once you have the basics done. Also it's the most complete and most stable jpeg library out there.
MagickWand is the C API for ImageMagick:
http://imagemagick.org/script/magick-wand.php
I have not used it, but the documentation looks quite extensive.
You should check out Qt's QImage. It has a pretty easy interface that makes this task really easy. Setup is pretty simple for every platform.
If Qt is overkill, you can try Magick++ http://www.imagemagick.org/Magick++/. It supports similar operations and is also well suited for that sort of task. The last time I used it, I struggled a bit with dependencies for it on Windows, but don't recall much trouble on Linux.
For Magick++'s Image class, the function you probably want is getConstPixels.
I have code that you can copy ( or just use as a reference ) for loading a jpeg image using the libjpeg library.
You can browse the code here: http://code.google.com/p/kgui/source/browse/trunk/kguiimage.cpp
Just look for the function LoadJPGImage.
The code is setup to handle c++ binding of my DataHandle class to it for loading the image, that way the image can be a file or data already in memory or whatever.
A slightly out of the box solution is to acquire a copy of the netpbm tools, which transform images from pretty much any format to any other format via one of several very simple intermediate formats. They work well from the shell, and are most often used in pipes to read some arbitrary image, perform an operation on it, and write it out to some other format.
The pbm formats can be as simple as a plain ASCII header followed by the RGB data in ASCII or binary. They are intended to be simple enough to use without required a library to implement.
JPEG is supported in netpbm by read and write filters that are implemented on top of libjpeg.