-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
77 lines (57 loc) · 2.46 KB
/
main.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
#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <detection/detection.hpp>
#include <filters/filters.hpp>
#include <noise_borders/noise_borders.hpp>
#include <preprocessing/preprocessing.hpp>
#include <utils/utils.hpp>
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Please, specify the path to the image you want to check;" << std::endl;
return 1;
}
cv::Mat mask = cv::imread("../mask/mask_computed.jpg", cv::IMREAD_GRAYSCALE);
cv::Mat startImage = cv::imread("../data/train/image_07.jpg", cv::IMREAD_COLOR);
cv::Mat startImagePrepared = prepareImage(startImage, mask, false, startImage.size());
std::string pathToImage = argv[1];
cv::Mat image = cv::imread(pathToImage, cv::IMREAD_COLOR);
if (image.empty()) {
std::cerr << "Please, chack the path to your image: it's incorrect;" << std::endl;
return 2;
}
cv::Mat imageToDraw = image.clone();
cv::Mat imagePrepared = prepareImage(image, mask, false, startImage.size());
cv::Mat difference = getDifference(startImagePrepared, imagePrepared);
cv::Mat ImageThresholded = thresholdImage(difference, -390.875, 308.125);
for (int indexI = 0; indexI < 4; ++indexI) {
ImageThresholded = maxNeighbourFilter(ImageThresholded, 3);
}
for (int indexI = 0; indexI < 4; ++indexI) {
cv::dilate(ImageThresholded, ImageThresholded, getStructuringElement(cv::MORPH_RECT, cv::Size(7, 7)));
}
std::vector<std::vector<int>> objects = detectObjects(ImageThresholded);
cv::Mat ObjectsDetected = makeRectangles(imageToDraw, objects);
cv::Mat ObjectsDetectedResized;
cv::resize(ObjectsDetected, ObjectsDetectedResized, cv::Size(), 0.7, 0.7);
cv::imshow("Detected objects", ObjectsDetectedResized);
cv::waitKey(0);
if (argc >= 3) {
std::string saveFlag = argv[2];
if (saveFlag == "-s") {
if (argc < 4) {
std::cerr << "Please, specify the path to directory where you want to save the result;" << std::endl;
return 3;
}
std::string pathToSave = argv[3];
int length = pathToSave.size();
if (pathToSave[length - 1] == '/') {
cv::imwrite(pathToSave + "result.jpg", ObjectsDetected);
return 0;
}
cv::imwrite(pathToSave + "/result.jpg", ObjectsDetected);
return 0;
}
}
return 0;
}