0

I am a frustrated newbie of C++ who would like to do the simple task of extracting a pixel matrix from an image file, do some transformation, and then output the modified matrix to an image format of my choosing.

I've given libpng a try and it's API is a mess and hardly readable. Interestingly, some people said it's the best available for C++. I gave my software developer cousin a call and he told me to use OpenGL. So, I did some Googling and I still haven't found a straight answer.

It appears getting a simple "int* readPNG(char* path)" is too much to ask for when the likes of Java, Matlab, and python have these things included in their standard libraries. This is just ridiculous! How do you pros come by and what libraries do you use?

Also a few trivial C++ questions: - Is there any way to organize classes in a hierarchy like how packages are used in Java? I tried filters in Visual C++ but they don't seem to be the same thing. - Is there any way to get easily comprehensible stack traces for runtime failures?

Some Newbie
  • 1,059
  • 3
  • 14
  • 33

7 Answers7

1

Try OpenCV. It is an image processing library with very simple features for editing and saving the images. It will serve your purpose. It also comes with very elegant documentation.

daerty0153
  • 524
  • 1
  • 6
  • 11
1

I've found ImageMagick's Magick++ library to be the most useful tool for handling image formatted data programmatically.

C++ has namespaces like Java but they are much more difficult to use and may only make things less readable. As for stack traces, I recommend combing the existing stackoverflow answers for that. In short, it's not simple.

zdv
  • 423
  • 3
  • 13
  • C++'s namespaces should be avoided? That's news to me. – Niklas B. Feb 07 '12 at 00:39
  • How are C++ namespaces "more difficult to use" than Java packages? Just write `namespace foo { ... }` instead of `package foo;` and `using namespace foo;` instead of `import foo.*;`. – André Caron Feb 07 '12 at 00:40
  • I'm not interested in arguing this here (it should really be a separate question), but my belief is simply that namespaces in C++ are not as simple as Java packages. Note that I did not use the word "avoid" anywhere. Given the more verbose syntax, differences in use between declaration and definition, the dangers of the "using namespace" syntax (especially in header files), and interactions with advanced features of C++ (e.g. templates, operator overloading), I consider them way more complicated than Java packages and not necessarily newbie friendly. – zdv Feb 07 '12 at 01:16
  • 1
    Huh? How does template and operator overloading factor into that? It appears to me that templates are just generics (in Java) and operator overloads are simply functions that are given a short-hand through symbol usage. – Some Newbie Feb 09 '12 at 09:42
0

I suggest you improve your Google-fu. There are lots of image processing libraries for C++, including the Boost Generic Image Library, which is as close to standard as you'll get. If you don't have Boost installed and minimal fuss installing libraries, you can always try The CImg Library.

As for your other questions (e.g. stack traces), you'll need to ask separate questions.

André Caron
  • 44,541
  • 12
  • 67
  • 125
0

I'd suggest Magick++, the C++ API to ImageMagick.

As for packages: you can use namespaces, but that's not nearly comparable to Java's packages (no package-level access etc). They're mostly what they're called: a means to organize names.

Stack traces are not trivial in C++. And there's no platform-independent way of implementing them that I'm aware of.

If you need these features, I just wonder why you don't stick with Java or Python or the likes ? ...

MartinStettner
  • 28,719
  • 15
  • 79
  • 106
0

1) Try freeImage - very easy to use and the documentation is readable. freeimage site

2) for stack traces: which environment are you working with? In Visual Studio there is Stack window (Debug/Windows/Call Stack - Alt 7), You can also use DebugView and OutputDebugString - not really traces the stack, but can be very usable in debugging. .

Flot2011
  • 4,601
  • 3
  • 44
  • 61
0

I recommend DevIL (formerly known as OpenIL). It has read and write support for 17 formats, and supports many more for just reading.

kevintodisco
  • 5,061
  • 1
  • 22
  • 28
  • I am using Visual C++ 2010 on VISTA. I tried to install Devil but it doesn't work. I double-clicked protects/msvc9/ImageLib.sln - no luck. I then tried the .vcxproj files in sub folders but they don't compile. I also tried FreeImage and it does install. But when I opened the solution, it's empty. I tried to use the Makefile and Makefile.cygwin using Cygwin and they threw a bunch of errors. I would greatly appreciate advice on how to install and use one of them. Thanks. I've never had to waste this much time on using Java and Python libraries. I feel like my head's going to blow with rage. – Some Newbie Feb 09 '12 at 23:55
  • It seems like I didn't make properly on the FreeImage library so I will give it another try. Still no luck with Devil. Instructions seem extremely outdated. – Some Newbie Feb 10 '12 at 00:11
  • Ok. I am giving up on installing them on Visual Studio C++ and will simply include all the .h and .cpp in classpath. – Some Newbie Feb 10 '12 at 00:30
0

This is my answer to my very own question here:

Some of the suggested libraries up there have issues with installation with Visual Studio 2010, offer practically no instructions for installation with Visual Studio (i.e. FreeImage), or simply have ridiculously messy API's (i.e. libpng).

If you are new to C/C++, please be careful about what library to choose. Even if there are technical forums roaming with gurus who knows all the answers, you are most likely on your own spending days experimenting and piecing up clues that experienced volunteers could've easily answered in 2 sentences (if they bothered).

Now, what works for me is the OpenCV image library (http://opencv.willowgarage.com/), which is introduced by Mister daerty0153 up there. When you go on the website, don't download the superpack from sourceforge. Instead, read the installation instructions (http://opencv.willowgarage.com/wiki/InstallGuide) and choose what platform you are using.

In my case, I use Visual Studio 2010 as my IDE and so this is the actual subpage that is relevant: http://opencv.willowgarage.com/wiki/VisualC%2B%2B

One problem I encountered is letting VS2010 recognize the .dll files and is not remedied by following those instructions. My solution was to copy all of them to my project folder and that solves all the problem. Some suggested it is a VS 2010 bug.

Hope it helps others suffering from the same situation.

Some Newbie
  • 1,059
  • 3
  • 14
  • 33
  • This should be a comment, not an answer. If a specific answer (e.g. [daerty0153's](http://stackoverflow.com/a/9169476/313063)) solved your problem, you should [accept it](http://meta.stackexchange.com/questions/5234). Also, you did not check all 2 sentence answers by experienced volunteers. I suggested the use of [CImg](http://cimg.sourceforge.net/) which holds in a single header file and there's nothing to install (no DLLs or anything). Just trying it out takes about 5 minutes and would have avoided you wasting 2 days trying to compile half a dozen libraries. – André Caron Feb 13 '12 at 05:37