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!!
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.
Related
I was trying to run a simple testing C++ file in my R package development directory with Rcpp located at say the directory "my_R_package_dir/src/my_file_location.cpp":
#include <Rcpp.h>
// [[Rcpp::export]]
int plusone() {
return 1 + 1;
}
But when running Rcpp::sourceCpp("src/my_file_location.cpp") the R console gives the following warning:
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/myself/my_R_package_dir/src/../inst/include": file not found
The function exported plusone() did work, but I can see clearly that its for some reason trying to access a non-existent file named "include" in the "inst" directory which I do have. I'm guessing it wants to access the Rcpp.h file but I probably need to somehow indicate it the path to point at? How do I do that?
P.S. This also causes the package build to fail and part of the message also indicates that theres no such file or directory Rcpp.h.
I thought I needed a Makevars.win and Makevars file, and I put them both into src and they look like this:
PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'`
PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'`
CC=C:\msys64\mingw64\bin\g++.exe
CXX=C:\msys64\mingw64\bin\gcc.exe
But with no avail. I am on a windows device with Rtools 4.3, gcc, and g++.
We need to store some data as c++ header file, so that we can then include it in the build bundle and shipped with any applications that use it.
To do that we use
xxd -i data.png > data.h
This works well, but the data.h files is now as 6X large as the data.png file. That means, if the data.png is 4MB, the data.h would be 24MB.
May I ask if there is a way to compress the data.h file to a smaller size?
Thanks!
--- update ---
Thank you all for the suggestions! I think I could clarify the need here to provide more context!
the ideal way for us to consume the file is we can open it as input stream like
std::ifstream is;
infile.open("data.png");
somefunc(is) // a api function that takes std::istream as input
p.s. the file is not png file but a scripted model, I use png as example because I find it as a more generic problem of "xxd -i"
we didn't find a way to make it available as a file to be read, as the file system the codes actually searching would be in Android/iOS. (only files on the mobile system are available and the source codes would be zipped in the .so file)
with the header file we can do something like
std::stringstream is;
is.write((char*)data_byte_array, data_byte_array_len)
somefunc(is)
The source codes would end up built as a lib.so. In our tests, A 70KB data.h would end up adding 45KB to the lib.so.
May I ask if there is a way to compress the data.h file to a smaller size?
You can use any lossless compression algorithm. The gzip program is a common default choice on POSIX systems.
You can compile any binary file into an object file using objcopy -I binary. See C/C++ with GCC: Statically add resource files to executable/library for more details
I have wrote this code to which is a simple utility to separate RG/GB Bayer color channels to individual files. It takes in input a RAW12 file and outputs png files corresponding to different Bayer Channels.I tried to compile it using DevC++ and it shows
[Error] lodepng.h: No such file or directory
I'm kinda new to these kind of things, and I don't know how to include lodepng.h and lodepng.cpp in DevC++ I tried a lot to find how. Any help would be appreciated.
#include "lodepng.h" statement is enough to add the file, if it is present in the same path as the current file in which you are working.
Once you have added the file, you can directly call all the methods in that file or refer to any objects or variables in that file.
I'm following the instructions on github.com/jcjohnson/torch-rnn and have it working until the training section. When I use th train.lua -input_h5 my_data.h5 -input_json my_data.jsonI get the error Error: unable to locate HDF5 header file at /usr/local/Cellar/hdf5/1.10.0-patch1/include;/usr/include;/usr/local/opt/szip/include/hdf5.h
I'm new to luarocks and torch, so I'm not sure what's wrong. I installed torch-hd5f. Any advice would be very much appreciated.
Check that the header file exists and that you have the correct path.
If the header file is missing you skipped the preprocess step. If the header file exists it's likely in your data directory and not in the same directory as the sample.lua code:
th train.lua -input_h5 data/my_data.h5 -input_json data/my_data.json
I would like to compile a c++ file as a mex file in MATLAB namely: "mexLasso.cpp".
These are the steps I take and I get the following error. What is the problem?
1. Put the files "mexLasso.cpp" and "mexutils.h" in a folder.
2. Set the compiler:
mex -setup C++
I recieve:
MEX configured to use 'Microsoft Visual C++ 2013 Professional' for C++ language compilation.
3. Run the command:
mex C:\...\mexLasso.cpp
I recieve the following error:
Error using mex
mexLasso.cpp
C:\...\mexLasso.cpp(33) : fatal error C1083: Cannot
open include file: 'mexutils.h': No such file or directory
Can somebody help us what we are missing?
From the mex command line tool reference, there is an argument for adding include paths:
-Ipathname Adds pathname to the list of folders to search for #include files.
Do not add a space between I and pathname.
Like this:
mex -v -IC:\path\to\mexutils_h\ mexLasso.cpp
Note that with -I you are not specifying the header, you are specifying a path containing one or more header files.
Thanks for your comments. I think the besy way to solve my problem is to install SPAMS in my machine and successfully compile it. I have posted the steps I take in this post :
How to install SPAMS toolbox in Matlab 2014b under windows 8.1
Can I have your opinion there. Sorry for duplicated message, only for relevancy and importance of the discussed topic.
Many thanks.