-
Notifications
You must be signed in to change notification settings - Fork 5
/
OpenCVApplication.cpp
97 lines (86 loc) · 1.52 KB
/
OpenCVApplication.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
// OpenCVApplication.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "common.h"
void testOpenImage()
{
char fname[MAX_PATH];
while(openFileDlg(fname))
{
Mat src;
src = imread(fname);
imshow("opened image",src);
waitKey();
}
}
void testOpenImagesFld()
{
char folderName[MAX_PATH];
if (openFolderDlg(folderName)==0)
return;
char fname[MAX_PATH];
FileGetter fg(folderName,"bmp");
while(fg.getNextAbsFile(fname))
{
Mat src;
src = imread(fname);
imshow(fg.getFoundFileName(),src);
if (waitKey()==27) //ESC pressed
break;
}
}
void testColor2Gray()
{
char fname[MAX_PATH];
while(openFileDlg(fname))
{
Mat_<Vec3b> src = imread(fname, IMREAD_COLOR);
int height = src.rows;
int width = src.cols;
Mat_<uchar> dst(height, width);
for (int i=0; i<height; i++)
{
for (int j=0; j<width; j++)
{
Vec3b v3 = src(i,j);
uchar b = v3[0];
uchar g = v3[1];
uchar r = v3[2];
dst(i,j) = (r+g+b)/3;
}
}
imshow("original image",src);
imshow("gray image",dst);
waitKey();
}
}
int main()
{
int op;
do
{
system("cls");
destroyAllWindows();
printf("Menu:\n");
printf(" 1 - Basic image opening...\n");
printf(" 2 - Open BMP images from folder\n");
printf(" 3 - Color to Gray\n");
printf(" 0 - Exit\n\n");
printf("Option: ");
scanf("%d",&op);
switch (op)
{
case 1:
testOpenImage();
break;
case 2:
testOpenImagesFld();
break;
case 3:
testColor2Gray();
break;
}
}
while (op!=0);
return 0;
}