-2

I am new to using C++. I am trying to convert an image to a string (I need to convert an image to a buffer).

So I use the "opencv" library. I try it but it doesn't work. When I execute my program this way:

g++ testpng.cpp -o testpng

This is the error in the terminal:

/usr/local/include/opencv4/opencv2/opencv.hpp:48:10: fatal error: opencv2/opencv_modules.hpp: No such file or directory
   48 | #include "opencv2/opencv_modules.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I need help to solve this error, or a working example to convert an image (.png) to a string, please!!

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Safa
  • 1
  • 1
  • This sounds like a linking problem. Do you use Make or CMake files or do you use an IDE with linking options? – Raavgo May 14 '22 at 21:14
  • Please check if your issue is related to https://stackoverflow.com/a/63456129/18667225 – Markus May 14 '22 at 21:19
  • what kinda string? just the bytes in the file (image is compressed), or do you want pixels? – Christoph Rackwitz May 14 '22 at 21:28
  • so I don´t know how i use make file with programm .cpp . – Safa May 14 '22 at 21:58
  • I want the image to a string types not a pixel – Safa May 14 '22 at 21:58
  • "below you will find my program" I believe you forgot to add it to your question. Also, calling g++ does not execute your program, it merely tries to compile the file you passed as argument. – SirDarius May 14 '22 at 22:03
  • Perhaps you’d like to use an image converter program to convert your image from PNG format to XPM format. One of the interesting qualities of an XPM image file is that it is also a valid C file that can be directly compiled into your program, and the image data can be accessed by other parts of the program, as a char array. https://en.m.wikipedia.org/wiki/X_PixMap – Jeremy Friesner May 14 '22 at 23:31
  • You can use cv::imencode to generate a byte array from an image. If you want a displayable string you might want to use hexcode instead. – Micka May 14 '22 at 23:48
  • 1
    @Raavgo "*This sounds like a linking problem*" - no, it is clearly a compiler error, not a linker error. The compiler is not able to find the `opencv2/opencv_modules.hpp` header file. This is a configuration problem, the compiler is not being told where to look for the `opencv2` folder. – Remy Lebeau May 15 '22 at 00:33

1 Answers1

0

If all you want is to load an image and then retrieve data from it, use the stb header library. It's simple to use, no binary libraries, only header files required. Simply download it from github and then include the stb_image.h file in your project.

GameWin221
  • 44
  • 1
  • 3