Working with images in C++ or C

后端 未结 5 871
北荒
北荒 2021-02-06 12:24

The first thing is that I am a beginner. Okay?

I\'ve read related answers and questions, but please help me with this problem:

How can I open an JPEG image file

相关标签:
5条回答
  • 2021-02-06 12:35

    There are many good libraries for working with images in C and C++, none of which is clearly superior to all others. OpenCVwiki, project page has great support for some of these tasks, while ImageMagickwiki, project page is good at others. The JPEG group has its own implementation of JPEG processing functions as well. These are probably good resources to start from; the API documentation can guide you more specifically on how to use each of these.

    As for whether C or C++ libraries are bound to be faster, there's no clear winner between the two. After all, you can always compile a C library in C++. That said, C++ libraries tend to be a bit trickier to pick up because of the language complexity, but much easier to use once you've gotten a good feel for the language. (I am a bit biased toward C++, so be sure to consider the source). I'd recommend going with whatever language you find easier for the task; neither is a bad choice here, especially if performance is important.

    Best of luck with your project!

    0 讨论(0)
  • 2021-02-06 12:52

    If running time is really important thing then you must consider image processing library which offloads processing job to GPU chip, such as:

    • Core Image (Osx)
    • OpenVIDIA (Windows)
    • GpuCV (Windows, Linux)
    0 讨论(0)
  • 2021-02-06 12:55

    well for basic image manipulations you could also try Qt's QImage class (and other). This gives you basic functionality for opening, scaling, resizing, cropping, pixel manipulations and other tasks.

    Otherwise you could as already said use ImageMagick or OpenCV. OpenCV provides a lot of examples with it for many image manipulation/image recognition tasks...

    Hope it helps...

    0 讨论(0)
  • 2021-02-06 12:56

    here is an example using magick library.

    program which reads an image, crops it, and writes it to a new file (the exception handling is optional but strongly recommended):

    #include <Magick++.h>
    #include <iostream>
    using namespace std;
    using namespace Magick;
    int main(int argc,char **argv)
    {
      // Construct the image object. Seperating image construction from the
      // the read operation ensures that a failure to read the image file
      // doesn't render the image object useless.
      Image image;
    
      try {
        // Read a file into image object
        image.read( "girl.jpeg" );
    
        // Crop the image to specified size (width, height, xOffset, yOffset)
        image.crop( Geometry(100,100, 100, 100) );
    
        // Write the image to a file
        image.write( "x.jpeg" );
      }
      catch( Exception &error_ )
        {
          cout << "Caught exception: " << error_.what() << endl;
          return 1;
        }
      return 0;
    }
    

    check many more examples here

    0 讨论(0)
  • 2021-02-06 12:57

    libgd is about the easiest, lightest-weight solution.

    gdImageCreateFromJpeg
    gdImageCopyMergeGray
    gdImageCopyResized
    

    Oh, and it's all C.

    0 讨论(0)
提交回复
热议问题