Created
August 20, 2021 19:28
-
-
Save diogon01/4bf1f9942cee2eed60f3add9b61f19d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
// OpenCV includes | |
#include <opencv2/core.hpp> | |
#include <opencv2/highgui.hpp> | |
using namespace cv; | |
int main(int argc, char** argv) { | |
// Read images | |
Mat color = imread("lena.jpg"); | |
Mat gray = imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); | |
if (!color.data) { | |
cout << "Could not open or find the image" << std::endl; | |
return -1; | |
} | |
// Write images | |
imwrite("lenaGray.jpg", gray); | |
// Get same pixel with opencv function | |
int myRow = color.cols - 1; | |
int myCol = color.rows - 1; | |
Vec3b pixel = color.at<Vec3b>(myRow, myCol); | |
cout << "Pixel value (B,G,R): (" << (int)pixel[0] << "," << (int)pixel[1] << "," << (int)pixel[2] << ")" << endl; | |
// show images | |
imshow("Lena BGR", color); | |
imshow("Lena Gray", gray); | |
// wait for any key press | |
waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment