Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include<armadillo>
- using namespace std;
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb_image.h"
- /* https://raw.githubusercontent.com/nothings/stb/master/stb_image.h */
- int LoadImage(const char* fileName, int *width, int *height, int *channels, arma::Mat<unsigned char>&& output, size_t offset = 0)
- {
- unsigned char *image;
- stbi_set_flip_vertically_on_load(true);
- if (*channels == 3)
- {
- image = stbi_load(fileName,
- width,
- height,
- channels,
- STBI_rgb);
- }
- if(*channels == 1)
- {
- image = stbi_load(fileName,
- width,
- height,
- channels,
- STBI_grey);
- }
- int size = (*width)*(*height)*(*channels);
- cout<< width <<" "<< height <<" "<< channels <<endl;
- output = arma::Mat<unsigned char>( image, 1, size, false, true );
- return 0;
- }
- int main(int argc, char const *argv[])
- {
- int width, height, channels = 3;
- arma::Mat<unsigned char> img;
- LoadImage(argv[1], & width, &height, &channels, std::move(img));
- img.print("Image");
- return 0;
- }
Add Comment
Please, Sign In to add comment