-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.cpp
106 lines (97 loc) · 2.16 KB
/
common.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "stdafx.h"
#include "common.h"
#include <CommDlg.h>
#include <ShlObj.h>
FileGetter::FileGetter(char* folderin,char* ext){
strcpy(folder,folderin);
char folderstar[MAX_PATH];
if( !ext ) strcpy(ext,"*");
sprintf(folderstar,"%s\\*.%s",folder,ext);
hfind = FindFirstFileA(folderstar,&found);
hasFiles= !(hfind == INVALID_HANDLE_VALUE);
first = 1;
//skip .
//FindNextFileA(hfind,&found);
}
int FileGetter::getNextFile(char* fname){
if (!hasFiles)
return 0;
//skips .. when called for the first time
if( first )
{
strcpy(fname, found.cFileName);
first = 0;
return 1;
}
else{
chk=FindNextFileA(hfind,&found);
if (chk)
strcpy(fname, found.cFileName);
return chk;
}
}
int FileGetter::getNextAbsFile(char* fname){
if (!hasFiles)
return 0;
//skips .. when called for the first time
if( first )
{
sprintf(fname, "%s\\%s", folder, found.cFileName);
first = 0;
return 1;
}
else{
chk=FindNextFileA(hfind,&found);
if (chk)
sprintf(fname, "%s\\%s", folder, found.cFileName);
return chk;
}
}
char* FileGetter::getFoundFileName(){
if (!hasFiles)
return 0;
return found.cFileName;
}
int openFileDlg(char* fname)
{
char *filter = "All Files (*.*)\0*.*\0";
HWND owner = NULL;
OPENFILENAME ofn;
char fileName[MAX_PATH];
strcpy(fileName,"");
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "";
GetOpenFileName(&ofn);
strcpy(fname,ofn.lpstrFile);
return strcmp(fname,"");
}
int openFolderDlg(char *folderName)
{
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(bi));
SHGetPathFromIDList(SHBrowseForFolder(&bi),folderName);
return strcmp(folderName,"");
}
void resizeImg(Mat src, Mat &dst, int maxSize, bool interpolate)
{
double ratio = 1;
double w = src.cols;
double h = src.rows;
if (w>h)
ratio = w/(double)maxSize;
else
ratio = h/(double)maxSize;
int nw = (int) (w / ratio);
int nh = (int) (h / ratio);
Size sz(nw,nh);
if (interpolate)
resize(src,dst,sz);
else
resize(src,dst,sz,0,0,INTER_NEAREST);
}