I now hope to convert image.jpg to image.ppm via c++ code implementation. What library can I implement in C++? By the way: my work platform is Raspberry Pi 3B+. I look forward to any help and reply from you.
Asked
Active
Viewed 2,209 times
1
-
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Thomas Sablik Oct 31 '19 at 11:45
-
Search for a library for image processing. Open the jpg file and write the image as ppm – Thomas Sablik Oct 31 '19 at 11:46
2 Answers
0
The established libjpeg-turbo library for fast JPEG image I/O can also read and write the simple PPM image format. You can use tjSaveImage()
method provided by libjpeg-turbo for that.
In your code, use tjDecompress2()
and tjSaveImage()
methods.
See example code in the libjpeg-turbo project.
You might also want to read this article for how to do an optimized build of OpenCV and libjpeg-turbo on the raspberry platform (do only the libjpeg-turbo
part).

ypnos
- 50,202
- 14
- 95
- 141
0
I would recommend CImg library for this. It is modern, lightweight and very, very simple to use because it is "header only" - just a single include file.
#define cimg_display 0 // if you dont have x11.and you can delete-Dcimg_display=0. https://github.com/GreycLab/CImg/issues/187
#include "CImg.h"
using namespace cimg_library;
int main() {
// Load JPEG image
CImg<unsigned char> im("image.jpg");
// Save as PPM
im.save("result.ppm");
// show ppm: ffplay -i a.ppm / ffmpeg -i a.ppm a.bmp
}
Compile like this:
g++ -std=c++11 -O3 -march=native -Dcimg_jpeg=1 -Dcimg_display=0 main.cpp -o main

rurouni
- 3
- 2

Mark Setchell
- 191,897
- 31
- 273
- 432
-
Thank you very much for your suggestion When I downloaded the .zip file on the Raspberry Pi, I don't know where to put the unzipped files? I used the c++ unofficial library for the first time, so I am not very familiar. – samuel_zong Oct 31 '19 at 14:00
-
The only file you need is *"Cimg.h"* which you can put in the same directory as your other C++ source files or in `/usr/local/include` if you plan to use it for many projects. You may need to add `-I .` for the first and `-I /usr/local/include` to your compiler command. – Mark Setchell Oct 31 '19 at 14:05