forked from niconielsen32/ComputerVision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
introductionOpenCV.cpp
58 lines (41 loc) · 1.54 KB
/
introductionOpenCV.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace std;
int main()
{
string image_path1 = "/home/nicolai/ComputerVision/images_1/images/Astronaut1.jpg";
string image_path2 = "/home/nicolai/ComputerVision/images_1/images/Astronaut2.jpg";
cv::Mat astro1 = cv::imread(image_path1, cv::IMREAD_COLOR);
cv::Mat astro2 = cv::imread(image_path2, cv::IMREAD_COLOR);
if(astro2.empty())
{
cout << "Could not read the image: " << endl;
return 1;
}
cv::rotate(astro2, astro2, cv::ROTATE_90_COUNTERCLOCKWISE);
cv::resize(astro2, astro2, cv::Size(300,300));
// cv::Vec3b colorModification = {231, 54, 154};
for(int i = 0; i < astro2.rows; i++)
{
for(int j = 0; j < astro2.cols; j++)
{
//astro2.at<cv::Vec3b>(i, j) = colorModification;
cv::Vec3b bgrPixel = astro2.at<cv::Vec3b>(i, j);
cout << "bgr: " << bgrPixel << endl;
//Grayscale = (R + G + B / 3)
unsigned char grayScale = (bgrPixel[2] + bgrPixel[1] + bgrPixel[0]) / 3;
astro2.at<cv::Vec3b>(i, j) = {grayScale, grayScale, grayScale};
cv::Vec3b grayPixel = astro2.at<cv::Vec3b>(i, j);
cout << "gray: " << grayPixel << endl;
}
}
cv::imshow("Display window", astro2);
int k = cv::waitKey(0); // Wait for a keystroke in the window
if(k == 's'){
cv::imwrite("starry_night.png", astro2);
}
return 0;
}