-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadImage.cpp
67 lines (53 loc) · 1.17 KB
/
ReadImage.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
59
60
61
62
63
64
65
66
67
#include "ReadImage.h"
CReadImage::CReadImage()
{
}
CReadImage::CReadImage(string path)
{
image = imread(path.c_str(), IMREAD_COLOR);
}
CReadImage::CReadImage(Mat img)
{
image = img;
}
Mat CReadImage::GetImage()
{
return image;
}
Mat CReadImage::GetImageGray()
{
Mat img_gray;
cvtColor(image, img_gray, CV_BGR2GRAY);
return img_gray;
}
bool CReadImage::SetImage(Mat img)
{
image = img;
if (image.empty())
{
cout << "Could not assign the image by a given image" << endl;
return false;
}
return true;
}
bool CReadImage::SetImage(string path)
{
image = imread(path.c_str(), IMREAD_COLOR); // c_string: convert string to char* to read image
// Can't read the image from the path
if (image.empty())
{
cout << "Could not open or find the image" << endl;
return false;
}
return true;
}
int CReadImage::DisplayImage()
{
namedWindow("Display window", WINDOW_NORMAL|WINDOW_KEEPRATIO); // WINDOW_AUTOSIZE or WINDOW_NORMAL|KEEP RATIO : resize to fit the normal windows but keep ration
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
CReadImage::~CReadImage()
{
}