-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSobel.cpp
More file actions
105 lines (88 loc) · 2.43 KB
/
Sobel.cpp
File metadata and controls
105 lines (88 loc) · 2.43 KB
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
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#ifdef __linux__
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#endif
#ifdef __WIN32
#include <io.h>
#include <windows.h>
#endif
void GetImgNames(string root_path, std::vector<std::string>& names) {
#ifdef __linux__
struct dirent* filename;
DIR* dir;
dir = opendir(root_path.c_str());
if(NULL == dir) {
return;
}
int iName=0;
while((filename = readdir(dir)) != NULL) {
if( strcmp( filename->d_name , "." ) == 0 ||
strcmp( filename->d_name , "..") == 0)
continue;
string t_s(filename->d_name);
names.push_back(t_s);
}
#endif
#ifdef __WIN32
intptr_t hFile = 0;
struct _finddata_t fileinfo;
string p;
hFile = _findfirst(p.assign(root_path).append("/*.jpg").c_str(), &fileinfo);
if (hFile != -1) {
do {
if (strcmp(fileinfo.name, ".") == 0 || strcmp(fileinfo.name, "..") == 0) {
continue;
}
names.push_back(fileinfo.name);
} while (_findnext(hFile, &fileinfo) == 0);
}
#endif
}
int main() {
// string root_path = "../../BackUpSource/Ball/Train/Raw";
string root_path = "D:/baseRelate/pic_data";
std::vector<string> image_names;
GetImgNames(root_path, image_names);
for (auto i = image_names.begin(); i != image_names.end(); i++) {
cv::Mat frame = cv::imread(root_path+"/"+*i);
cout<<*i<<endl;
if (frame.empty()) {
continue;
}
cv::Mat t;
cv::Mat t_cs[3];
cv::cvtColor(frame, t, CV_BGR2HSV);
cv::split(t, t_cs);
// cv::split(frame, t_cs);
cv::Mat dst;
cv::Sobel(t_cs[2], dst, CV_8U, 0, 1);
cv::convertScaleAbs(dst, dst);
// cv::threshold(dst, dst, 0, 255, CV_THRESH_OTSU);
cv::imshow("211", dst);
cv::imshow("233", frame);
char key = cv::waitKey(0);
if (key == 'q') {
break;
}
else if (key == 'n') {
continue;
}
else if (key == 'p') {
i--;
i--;
}
}
return 0;
}