-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowImage.cpp
executable file
·75 lines (65 loc) · 1.8 KB
/
showImage.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
68
69
70
71
72
73
74
75
#include "showImage.h"
using namespace cv;
using namespace std;
std::string dirnameOf(const std::string& fname)
{
size_t pos = fname.find_last_of("\\/");
return (std::string::npos == pos)
? ""
: fname.substr(0, pos);
}
struct MatchPathSeparator{
bool operator()( char ch ) const{
return ch == '/';
}
};
// struct MatchPathSeparator{
// bool operator()( char ch ) const{
// return ch == '\\' || ch == '/';
// }
// }; //for windows path
Mat Grayscaler(Mat img){
int gr_w = img.cols;
int gr_h = img.rows;
//cout<<hist_h<<" "<<modus<<" "<<bin_h;
Mat grImage(gr_h, gr_w, CV_8UC1, Scalar(255, 255, 255));
for(int y = 0; y < gr_h; y++){
for(int x = 0; x < gr_w; x++){
Point3_<uchar>* p = img.ptr<Point3_<uchar> >(y,x);
grImage.at<uchar>(y,x)=.2126 * p->z +.7152 * p->y+.0722 * p->x;
}
}
return grImage;
}
Mat loadImage(string imageDirName){
string imageName("../data/HappyFish.jpg"); // by default
if( imageDirName.length() > 1)
{
imageName = imageDirName;
}
Mat image;//(800, 800, CV_8UC1, Scalar(255, 255, 255));
image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return image;
}
else return image;
}
void showImage(Mat image, string name){
namedWindow( name, WINDOW_AUTOSIZE ); // Create a window for display.
imshow( name, image );
}
string basename(string const& pathname ){
return string(
find_if(
pathname.rbegin(), pathname.rend(),MatchPathSeparator() ).base(),
pathname.end() );
}
String convertIntString(int x){
stringstream convert;
string hasil;
convert<<x;
hasil=convert.str();
return hasil;
}